SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2003
    Location
    NYC
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    loop array, more results?

    The below code is returning close to what I need, but not all of it. I'm trying to attain this:
    Code:
    stgAst=|ASSET0:portfolio:Some kind of intro.|ASSET1:galleries:These are recent.|ASSET2:contact:I am here.|ASSET3:bio:Past to Present.&total=4
    but I'm only getting the last "|" deliminated values.
    Code:
    |ASSET3:bio:Past to Present.&total=4
    Current code;
    PHP Code:
    $select "SELECT type_id, type_name, type_desc, type_order FROM gallery_type ORDER BY type_order";
    $result mysql_query ($select);
    $rows mysql_num_rows($result);
    if (
    $rows) {
        
    $valuesForFlash '';
        
    $fileCount 0;
        if (
    $fileCount $rows) {
        while(
    $list mysql_fetch_array($result)) {
            
    $torder $list['type_order'];
            
    $tname $list['type_name'];
            
    $tdesc $list['type_desc'];
        }
        }
        
    $valuesForFlash .= '|ASSET'.$torder.':'.$tname.':'.$tdesc;
        
    $fileCount++;
    } else {
        echo 
    'there are no results!';
    }
    mysql_free_result($result);
    $valuesForFlash .= "&total=".$rows;
    print 
    $valuesForFlash

  2. #2
    SitePoint Evangelist Aska's Avatar
    Join Date
    Aug 2003
    Location
    Melbourne, Australia
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The concatenation needs to be done in the while loop like so:
    PHP Code:
     $select "SELECT type_id, type_name, type_desc, type_order FROM gallery_type ORDER BY type_order";
    $result mysql_query ($select);
    $rows mysql_num_rows($result);
    if (
    $rows 0) {
        
    $valuesForFlash '';
        
    /* $fileCount variable not really needed as the while loop will stop once there's no more rows in the result set */
        
    while($list mysql_fetch_array($result)) {
            
    $torder $list['type_order'];
            
    $tname $list['type_name'];
            
    $tdesc $list['type_desc'];
            
    $valuesForFlash .= '|ASSET'.$torder.':'.$tname.':'.$tdesc;
        }
    } else {
        echo 
    'there are no results!';
    }
    mysql_free_result($result);
    $valuesForFlash .= "&total=".$rows;
    print 
    $valuesForFlash

  3. #3
    SitePoint Zealot
    Join Date
    Aug 2003
    Location
    NYC
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, yeah that is what I asked for Aska, thanks. I'm trying to edit this a little more. Where the "|" deliminator is part of the "ASSET" string, I need it to be an actual deliminator. I thought I could cheat it as a string but my end results suffer.
    Would a for loop be in order? I've tried adding it as a value to $valuesForFlash var but it's not correct. I needs to be added during a cycle process in order to avoid having the "|" show add either the beginning or end of the total printed array.
    PHP Code:
    if ($rows 0) {
        
    $valuesForFlash '';
        while(
    $list mysql_fetch_array($result)) {
            
    $torder $list['type_order'];
            
    $tname $list['type_name'];
            
    $tdesc $list['type_desc'];
            
    $tmov $list['type_movie'];
            
    $valuesForFlash .= 'ASSET'.$torder.':'.$tname.':'.$tdesc.':'.$tmov;
            
    $valuesForFlash .= '|'.$valuesForFlash;
        } 
    Thanks for anyone's input on this.

  4. #4
    SitePoint Evangelist Aska's Avatar
    Join Date
    Aug 2003
    Location
    Melbourne, Australia
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see... want to give this a try?
    PHP Code:
    if ($rows 0) {
        
    /* create an empty array to store records */
        
    $valuesForFlashArr = array();
        while(
    $list mysql_fetch_array($result)) {
            
    $torder $list['type_order'];
            
    $tname $list['type_name'];
            
    $tdesc $list['type_desc'];
            
    $tmov $list['type_movie'];
            
    $valuesForFlashArr[]= 'ASSET'.$torder.':'.$tname.':'.$tdesc.':'.$tmov;
        } 
        
    /* merge array into one string with '|' as the delimiter */
        
    $valuesForFlash implode'|'$valuesForFlashArr); 

  5. #5
    SitePoint Zealot
    Join Date
    Aug 2003
    Location
    NYC
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, I see how this should work and looked up a lot on implode ...I think the "while" part is not getting the data AND putting into the array ...still working on this if you have another tip because I'm not getting any data returned.
    current code;
    PHP Code:
    $select "SELECT type_id, type_name, type_desc, type_order, type_movie FROM gallery_type ORDER BY type_order";
    $result mysql_query ($select);
    $rows mysql_num_rows($result);
    if (
    $rows 0) {
        
    /* create an empty array to store records */
        
    valuesForFlashArr = array();
        while(
    $list mysql_fetch_array($result)) {
            
    $torder $list['type_order'];
            
    $tname $list['type_name'];
            
    $tdesc $list['type_desc'];
            
    $tmov $list['type_movie'];
            
    $valuesForFlashArr[]= 'ASSET'.$torder.':'.$tname.':'.$tdesc.':'.$tmov;
        }
        
    /* merge array into one string with '|' as the delimiter */
        
    $valuesForFlash implode'|'$valuesForFlashArr);
    } else {
        echo 
    'there are no results!';
    }
    mysql_free_result($result);
    //$valuesForFlash = implode( '|', $valuesForFlashArr)
    $valuesForFlash .= "&total=".$rows;
    print 
    'stgAst='.$valuesForFlash;
    ?> 
    Thanks Aska

  6. #6
    SitePoint Zealot
    Join Date
    Aug 2003
    Location
    NYC
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've recoded the while loop and I get the results I wanted, except that the $row values are not in the array order I had originally desired ...so a few little touch ups and should be good to go. Also, I need the string "ASSET" added to type_order, but I might just do that in Flash ActionScript, not sure ...cause FYI no variables can begin with an integer in Flash (causes probs).
    PHP Code:
    $select "SELECT type_id, type_name, type_desc, type_order, type_movie FROM gallery_type ORDER BY type_order";
    $result mysql_query($select) or die(mysql_error());
    $rows mysql_num_rows($result);
    if (
    $rows 0) {
        
    //$valuesForFlash = '';
        
    $valuesForFlashArr = array();
        while (
    $row mysql_fetch_assoc($result)) {
            unset(
    $row['type_id']);
            
    $row array_values($row);
            
    $valuesForFlashArr[]= implode(':'$row);
        }
        
    $valuesForFlash implode'|'$valuesForFlashArr);
    } else {
        echo 
    'there are no results!';
    }
    mysql_free_result($result);
    print 
    'stgAst='.$valuesForFlash


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
  •