Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Mar 2009
    Posts
    175
    Thanks
    3
    Thanked 1 Time in 1 Post

    Trouble getting all results from array

    I'm having trouble getting all results out of a query array.
    I've tried using a foreach loop but for some reason I can't get it to work.
    Here's what I'm trying to do:
    Code:
    $query = "SELECT data_txt FROM jos_servicedirectory_fields_data WHERE fieldid = 19 AND itemid = $item->itemid";
    $result = mysql_query($query) or die(mysql_error());
    while($row = mysql_fetch_array($result)){
    $listtags = $row['data_txt'];
    $tags = "$listtags, ";
    
    $title = "<div class='servicedirectoryItemTitle'><table class=\"sdlistingitemtitle\" cellspacing=\"5\"><tbody><tr>$listingimage<td style=\"vertical-align:top;width:690px;\">$listingbasicicon<span class=\"$listingtitleclass\">$listinglogo<a href=\"{$href}\" {$onClick} title=\"{$item->title}\">{$item->title}</a></span><br /><span class=\"listingdescription\">$listingdescription</span></td><td style=\"vertical-align:top;\">$featuredribbon$moreinfobasic</td></tr></tbody></table><div class=\"listingbottom\">Tags:<span class=\"listingtags\">  $tags </span></div></div>"; }

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    what's not working? the $tags not showing all results? Or none of the table showing with anything in?

  • #3
    Regular Coder
    Join Date
    Mar 2009
    Posts
    175
    Thanks
    3
    Thanked 1 Time in 1 Post
    It's only outputting the first result of the array but I need all of them to display.
    I tried sticking the while } end tag after the $title = line to wrap it in it but didn't have any affect. I also tried setting up a foreach loop but couldn't get it to pop anything for some reason, I'm not really sure what I did wrong in it but I'm sure I probably didn't do it right. I used:
    Code:
    foreach($listtags as $value) {
    $tags = $value;
    }
    Again, tried closing the foreach } tag at the end of the $title = line but still no good, even doing a print_r($value) doesn't return anything so I'm sure I'm not setting up the foreach right.

  • #4
    Regular Coder
    Join Date
    Mar 2009
    Posts
    175
    Thanks
    3
    Thanked 1 Time in 1 Post
    Anyone have any advice at all?

  • #5
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    $query "SELECT data_txt FROM jos_servicedirectory_fields_data WHERE fieldid = 19 AND itemid = $item->itemid";
    $result mysql_query($query) or die(mysql_error());
    $tags "";
    while(
    $row mysql_fetch_array($result)){
    $listtags $row['data_txt'];
    $tags .= "$listtags,&nbsp;";
    }
    $title "<div class='servicedirectoryItemTitle'><table class=\"sdlistingitemtitle\" cellspacing=\"5\"><tbody><tr>$listingimage<td style=\"vertical-align:top;width:690px;\">$listingbasicicon<span class=\"$listingtitleclass\">$listinglogo<a href=\"{$href}\" {$onClick} title=\"{$item->title}\">{$item->title}</a></span><br /><span class=\"listingdescription\">$listingdescription</span></td><td style=\"vertical-align:top;\">$featuredribbon$moreinfobasic</td></tr></tbody></table><div class=\"listingbottom\">Tags:<span class=\"listingtags\">  $tags </span></div></div>"; } 

  • #6
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    If fieldid or itemid is a primary or unique key then you will get only 0 or 1 row returned maximum.
    Last edited by webdev1958; 08-22-2011 at 05:56 PM.


  •  

    Tags for this Thread

    Posting Permissions

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