SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2006
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Pulling just the first value from a while statement

    I have some code that pulls out some details from a database, then loads it into an array as follows:

    PHP Code:
    //Load artwork information into the gallery array
                    
    $artworkset = @mysql_query(
                    
    "SELECT *, DATE_FORMAT(date, '%d/%m/%Y') AS ddmmyyyy FROM artwork limit $offset$limit");
                    if (!
    $artworkset) {
                        exit(
    'Unable to load artwork from the database' mysql_error());
                    }

    while (
    $artwork mysql_fetch_array($artworkset)) {
                    
                    
    $id $artwork['id']; 
    and so forth.

    That's all fine, but I need to get JUST the first $id value into another variable for use with another component. Any idea how? Been stumpted on this for a while now, nothing I've tried has worked...

    Thanks

  2. #2
    SitePoint Member
    Join Date
    Mar 2007
    Location
    Adelaide
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $id = null;

    while (...) {
    if (is_null($id)) { $id = 123; }
    }

    do you need the other rows at all, ie; do you need a while loop?

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2006
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahh awesome. Thanks man!

    Yeah it pulls out a whole buncha stuff and creates links and images too. But I just needed this first id variable for the default first page value thing


Bookmarks

Posting Permissions

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