Web Analytics Made Easy -
StatCounter Trouble getting all results from array - CodingForum

Announcement

Collapse
No announcement yet.

Trouble getting all results from array

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    what's not working? the $tags not showing all results? Or none of the table showing with anything in?

    Comment


    • #3
      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.

      Comment


      • #4
        Anyone have any advice at all?

        Comment


        • #5
          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>"; } 

          Comment


          • #6
            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; Aug 22, 2011, 11:56 AM.

            Comment

            Working...
            X