ORDER BY RAND()....

From: Payne (payne_at_magidesign.com)
Date: 10/29/03


Date: Wed, 29 Oct 2003 14:24:04 -0500
To: php-general@lists.php.net

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



Relevant Pages

  • Re: [PHP] ORDER BY RAND()....
    ... > I have been working on a simple PHP script that called to a mysql ... SELECT url FROM sponsors ORDER BY RAND() LIMIT 1; ...
    (php.general)
  • Re: [PHP] ORDER BY RAND()....
    ... >>I have been working on a simple PHP script that called to a mysql ... >>database, ... >SELECT url FROM sponsors ORDER BY RANDLIMIT 1; ...
    (php.general)
  • Re: permissions?
    ... kkk333@freemail.hu (Daniel Barna) wrote: ... >> create user accounts in mysql, then call mysql to check it. ... > But now username and password is hardcoded in my php script, ...
    (comp.lang.php)
  • Re: permissions?
    ... > I tried to play with mysql: set up a password for the database. ... > php script itself, or in a file, or whereever. ... > file permissions are set up in a way that other users can not directly ...
    (comp.lang.php)
  • Re: permissions?
    ... > create user accounts in mysql, then call mysql to check it. ... But now username and password is hardcoded in my php script, ... readable by wwwrun, so any other local users can also ...
    (comp.lang.php)