zero-perfoliate
zero-perfoliate

Author Topic: 3 random results from one table  (Read 438 times)

Offline CodeMama

  • New PHP Members
  • Posts: 1
  • Karma: +0/-0
3 random results from one table
« on: November 28, 2008, 07:57:26 AM »
I have to get 3 random results to populate a 3 column table, so far I can only get one random result, I have tried to make more $title2 like that but it will just pull the same one, I think there is a math thing I'm missing here, I also have to count the times these blurbs appear...need guides please , so far I just keep ending up with endless loops that make the page time out....
here is my code so far:
Code: [Select]
<?php include 'inc/dbconnOpen.php';
ini_set('error_reporting'E_ALL);
ini_set('display_errors'true);

$sql ="select * from textads ORDER BY RAND() LIMIT 0,1";  /* query */
$resultmysql_query($sql);

$num=mysql_num_rows($result);

mysql_close();

echo 
"<b><center>Database Output</center></b><br><br>";

$i=0;
while (
$i $num) {

$href=mysql_result($result,$i,"href");
$blurb=mysql_result($result,$i,"blurb");
$title=mysql_result($result,$i,"title");



        
        
        
echo 
"<table border= 1 height=90px width=468px bgcolor=#cccccc><tr><td>$title<br>$blurb<br>
<A HREF='$href'>$href</a></td><td>$title<br>$blurb<br>
<A HREF='$href'>$href</a></td><td>$title<br>$blurb<br>
<A HREF='$href'>$href</a></td></tr></table>"
;

$i++;
}

?>

when I try
$sql ="select * from textads ORDER BY RAND() LIMIT 0,3" --- I get 3 full tables outputted all with the same blurb in each column