The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 5 of 5

Thread: Pulling information from DB store in array

  1. #1

    Afrostyle Pulling information from DB store in array

    I need some help. I am putting together a portfolio site. I have a database full of information include image paths, client id's, categories and sub categories. What I am trying to do is have a page that when you view a portfolio piece it will show (Client, Date, Status, Title) along with an Image and Pages to the other images in that piece. What I having a problem with is:
    I always learned to pull information from a database and store it in an array like this
    PHP Code:
    <?php
    $sqli 
    = ("SELECT ImageID FROM images WHERE Cid=$cat_id AND Sid=$sub_id AND clientID=$client_id ORDER BY ImageID ASC LIMIT 1");
    $ires mysql_query($sqli);
    while(
    $irow mysql_fetch_assoc($ires)) {
    ?>
    /*HTML code is here like displaying (client info, title, date, status, 1 image from the table, pages)*/
    <?php ?>
    This will pull all rows that pertain to the $sqli variable. I know I can use LIMIT to only grab one row but I want to grab all the info so I can set up how many PAGES will will be associated with $sqli.

    Is there another way instead of using WHILE?
    Cause if I use this it will repeat the HTML code for all the rows that pertain to the mysql_query.

    If you get lost in my description let me know where I lost you and I can help you understand it better. Thanks in advance!

  2. #2
    yea gonna have to revamp your question ... for me at least cause that makes no sense
    Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
    Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.

  3. #3
    Quote Originally Posted by waverider303 View Post
    This will pull all rows that pertain to the $sqli variable. I know I can use LIMIT to only grab one row but I want to grab all the info so I can set up how many PAGES will will be associated with $sqli.
    Hard to understand, but this may be what you need:

    PHP Code:
    $q 'SELECT COUNT(*) FROM images WHERE Cid=$cat_id AND Sid=$sub_id AND clientID=$client_id';
    $q mysql_fetch_array(mysql_query($q));
    $howManyPages $q['COUNT(*)']; 

  4. #4
    if all you want is the total number of results of a query just do
    PHP Code:
    $count mysql_num_rows($sqli); 
    not sure if Neo's up at the top works, never done it or seen it done that way, but i know the way I showed does
    Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
    Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.

  5. #5
    My way counts rows without actually retrieving any real data, which saves RAM and time. But if you needed both the number of rows and data, then Simplistik's way is better.
    Last edited by NeoDreamer; August 4th, 2009 at 02:44 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012