Home > Archive > PHP Programming > December 2006 > Re: fetch_array()
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| hackajar@gmail.com 2006-12-25, 7:59 am |
| This works too:
$random=3Drand(1,5);
$query=3D"SELECT Message FROM <database>.random_quote WHERE
MessageID=3D$random"; //Don't forget to include your database!
$message =3D mysql_result(mysql_query($query),0) or die(mysql_error());
Hackajar
Kim Andr=E9 Aker=F8 wrote:
> Kimmo Laine wrote:
>
m";[color=darkred]
>
> Why go through all the hoops of using arrays when you only need the one
> element?
>
> $random=3Drand(1,5);
> $query=3D"SELECT Message FROM random_quote WHERE MessageID=3D$random";
> $result =3D mysql_query($query) or die(mysql_error());
> echo mysql_result($result, 0);
>
> --
> Kim Andr=E9 Aker=F8
> - kimandre@NOSPAMbetadome.com
> (remove NOSPAM to contact me directly)
| |
| Kim André Akerĝ 2006-12-27, 3:59 am |
| hackajar@gmail.com wrote:
> This works too:
>
> $random=rand(1,5);
> $query="SELECT Message FROM <database>.random_quote WHERE
> MessageID=$random"; //Don't forget to include your database!
> $message = mysql_result(mysql_query($query),0) or die(mysql_error());
Or even better:
$query = "SELECT Message FROM random_quote ORDER BY RAND() LIMIT 1";
$message = mysql_result(mysql_query($query),0) or die(mysql_error());
--
Kim André Akerĝ
- kimandre@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)
|
|
|
|
|