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
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;

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

That will also put a comma in front of the first extracted record.

 

You might want something like:

 

$title .= (!isset($title)) ? $row['title'] : ", ".$row['title'];

 

But if the way you have works, it works...

Link to comment
Share on other sites

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.