...

View Full Version : Trouble getting all results from array



sfraise
08-20-2011, 08:10 PM
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:


$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>"; }

Nightfire
08-20-2011, 08:44 PM
what's not working? the $tags not showing all results? Or none of the table showing with anything in?

sfraise
08-20-2011, 09:24 PM
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:


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.

sfraise
08-22-2011, 05:34 PM
Anyone have any advice at all?

Nightfire
08-22-2011, 05:48 PM
$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>"; }

webdev1958
08-22-2011, 05:50 PM
If fieldid or itemid is a primary or unique key then you will get only 0 or 1 row returned maximum.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum