Jump to content

[SOLVED] Sql result array help


monkeybidz

Recommended Posts

I have a query that I get results to one at a time depending on the last created item, but would like the results to display in a row separted by a comma. Is this possible?

 

Here is my current code:

$query = "SELECT title FROM XXXXX_XXXXX WHERE private='n' ORDER BY starts DESC LIMIT ".$SETTINGS['lastitemsnumber'];
$result = mysql_query($query);	  
if($result) {
 $num_auction = mysql_num_rows($result);
 $title = mysql_result($result,$i,"title");
    $i++;
}

 

Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/153406-solved-sql-result-array-help/
Share on other sites

Like this?

 

$query = "SELECT title FROM XXXXX_XXXXX WHERE private='n' ORDER BY starts DESC LIMIT ".$SETTINGS['lastitemsnumber'];
   $result = mysql_query($query) or die(mysql_error());    
if($result) {
   while($row = mysql_fetch_assoc($result)) {
      $string .= $row['title'] . " ,";
   }
}

echo $string;

Your on the right track, except I get the result with a , like I want, but not the first result. I will use the word "sample" as array for all result:

 

resulst: samplesample, sample, sample, sample and so on.

 

The first two sample's don't get a , or space.

 

 

Any ideas?

You lead me on the right path!

 

Here we go:

 

$query = "SELECT title FROM PHPAUCTION_auctions WHERE closed='0' AND suspended=0 AND private='n' ORDER BY RAND()";
$result = mysql_query($query);	  
if($result) {
   while($row = mysql_fetch_assoc($result)) {
     $title .= ", ".$row['title'];
}
} 

 

Thanks!

 

Your Awsome! ;D

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.