You are here: Re: fetch_array() « PHP Programming Language « IT news, forums, messages
Re: fetch_array()

Posted by Geoff Berrow on 12/22/06 00:31

Message-ID: <1166741903.577897.67580@80g2000cwy.googlegroups.com> from
Jerim79 contained the following:

>$random=rand(1,5);
>$query="SELECT Message FROM random_quote WHERE MessageID=$random";
>$message = mysql_query($query) or die(mysql_error());
>echo $message;
>
>But it only returns "Resource #5." I had someone mention
>mysql_fetch_array, but that seems like an unecessary way to go about
>it. To me, logically the code above should work.

No, it returns a resource, as you have found out. The output you
require may just be one thing, but a query can return many rows and
columns of data. It needs further processing before you can do anything
useful with it. You might only be interested in the number of rows
where you could use mysql_num_rows()

But in your case, since you know that MessageID is unique you know it
will only return one row.

$random=rand(1,5);
$query="SELECT Message FROM random_quote WHERE MessageID=$random";
$result = mysql_query($query) or die(mysql_error());
$row= mysql_fetch_array($result);
echo $row['Message'];
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация