ORDER BY RAND()....

From: Date: Wed, 29 Oct 2003 19:24:04 +0000
Subject: ORDER BY RAND()....
Groups: php.general 
Request: Send a blank email to php-general+get-168046@lists.php.net to get a copy of this message
Hi, I have been working on a simple PHP script that called to a mysql database, where I do the following.... SELECT url FROM sponsors ORDER BY RAND(); When I do a refresh I keep getting the same url, I have test this sql statement in mysql and it works great. I think my problem is this... Here is my php script.... <?
               $db = mysql_connect("69.15.40.130","cepayne","death");
               mysql_select_db("links",$db);
               $result = mysql_query("SELECT url FROM sponsors order by rand() LIMIT 1", $db);
              if ($myrow = mysql_fetch_array($result)) {
               echo"<table width='500' border='0' cellspacing='0' cellpadding='0'>";
                    do {
                           printf("<tr><td>%s</td></tr>\n",$myrow[url]);
                    } while ($myrow = mysql_fetch_array($result));
                    } else {
                                echo "Sorry, no message of day today";
              }
             echo "</table>"
?> I know that what I have got here must be the problem because this code was use to get mutli line of results. Is there a way to retype this so that I only get the one statement I need? Payne

« previous php.general (#168046) next »