1 Replies - 483 Views - Last Post: 28 November 2008 - 12:40 PM Rate Topic: -----

#1 Terion  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 29-October 08

Randomization of Outputs

Posted 28 November 2008 - 07:26 AM

Hi everyone, I have a project where I have to pull 3 random text blurbs from a db, I have it pulling one random one no problem, but am confused as to how to make it pull 3 different ones output in a table with three columns:
here is my code so far:
<?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 */
$result= mysql_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++;
}

?>





Do I make a function or variable or something for the three different pulls?

Is This A Good Question/Topic? 0
  • +

Replies To: Randomization of Outputs

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2834
  • View blog
  • Posts: 9,738
  • Joined: 08-August 08

Re: Randomization of Outputs

Posted 28 November 2008 - 12:40 PM

Why not do this?

$sql ="select * from textads ORDER BY RAND() LIMIT 3";
$result = mysql_query($sql) or die(mysql_error())

and loop through the results with a while statment to get your three items:

while($row = mysql_fetch_array($result))
{
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1