sfraise Posted August 22, 2011 Share Posted August 22, 2011 I'm having trouble getting all of the results out of a query array, as it is I only get the first result and nothing else. Here's the basic code I'm working with: $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>"; } I've also tried using a foreach loop thinking that would pop all of the results but I end up not getting anything at all then. I'm guessing I'm setting the foreach loop up wrong. Here's how I'm trying to do it: foreach($listtags as $value) { $tags = $value; } Does it have something to do with sticking the $tags variable in the $title variable? I wouldn't think that would matter, but the strange thing is I use this exact same query in a different part of this component and just echo it directly and it works fine. Quote Link to comment https://forums.phpfreaks.com/topic/245432-trouble-getting-all-results-from-query-array/ Share on other sites More sharing options...
Muddy_Funster Posted August 22, 2011 Share Posted August 22, 2011 how certain are you that there should be multiple rows returned? what do you get if you use echo mysql_num_rows($result) ? Quote Link to comment https://forums.phpfreaks.com/topic/245432-trouble-getting-all-results-from-query-array/#findComment-1260552 Share on other sites More sharing options...
sfraise Posted August 22, 2011 Author Share Posted August 22, 2011 110% positive, I can look at the item listing and see if there are multiple values selected, plus I'm using this same query in the item details page and when I view that it will display all of the results there instead of just the first one like it does in the list view. Quote Link to comment https://forums.phpfreaks.com/topic/245432-trouble-getting-all-results-from-query-array/#findComment-1260568 Share on other sites More sharing options...
PFMaBiSmAd Posted August 22, 2011 Share Posted August 22, 2011 If you post all the code inside the while(){...} loop, someone can probably help with what it is doing wrong. Best guess is you are reusing and overwriting the $result variable. Quote Link to comment https://forums.phpfreaks.com/topic/245432-trouble-getting-all-results-from-query-array/#findComment-1260572 Share on other sites More sharing options...
sfraise Posted August 22, 2011 Author Share Posted August 22, 2011 Thanks, I'll change the $result to something else and see if that helps. Quote Link to comment https://forums.phpfreaks.com/topic/245432-trouble-getting-all-results-from-query-array/#findComment-1260581 Share on other sites More sharing options...
sfraise Posted August 22, 2011 Author Share Posted August 22, 2011 No joy, still just pops the first result. If you want to get a better idea of what I'm talking about you can go to the dev site at http://www.erecoverydev.com, log in with user test and password test123. Click the resource center link in the top menu, then click on the service directory link on the left menu. We just have test data in there right now so just do a search for within 500 miles of 90210, this should pop some results. You'll see what I'm talking about with the tags only showing one result in the list, but if you click on it to view the details you'll see all of the tags output. Quote Link to comment https://forums.phpfreaks.com/topic/245432-trouble-getting-all-results-from-query-array/#findComment-1260598 Share on other sites More sharing options...
jcbones Posted August 22, 2011 Share Posted August 22, 2011 The best way to get help is to post all of the relevant code. Being that you are using PHP (PRE-HYPERTEXT PROGRAMMING), looking at the end product doesn't help with a coding problem. I would start with echo'ing out the $query, and pasting that into my database program (ie. phpMyAdmin) or typing it straight into the console. This would remove the doubts as to what rows are returned. Quote Link to comment https://forums.phpfreaks.com/topic/245432-trouble-getting-all-results-from-query-array/#findComment-1260709 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.