Jump to content

Recommended Posts

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.

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.

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.