Re: Stupid newbie looping MySQL question
| From: | JJeffman | Date: | Sat, 06 Jan 2001 23:33:11 +0000 |
| Subject: | Re: Stupid newbie looping MySQL question | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-5659@lists.php.net to get a copy of this message | ||
This kind of error happen when you have and invalid query .
Remember that table names and field names are case sensitive, keywords not.
If the name of your table "mytable" or the field "name" are not exactly the
query fails and $result will be null (0) and generate the error : "Supplied
argument is not a valid MySQL result resource..." when you attempt to use
$result as an argument to php functions.
Try this:
$result = mysql_query ("Select name from mytable") or die(mysql_error());
if($result){
while ($row = mysql_fetch_array ($result)) {
$newTableName = $row['0'];
$sSQL = "Select id,thread,subject,author,datestamp from
$newTableName order by datestamp desc limit 30";
}
}
Jayme.
http://www.conex.com.br/jjeffman
-----Mensagem Original-----
De: Lynn Siprelle <lynn@siprelle.com>
Para: Todd Pillars <kazoot@nettaxi.com>
Cc: <php-db@lists.php.net>
Enviada em: sábado, 6 de janeiro de 2001 20:46
Assunto: RE: [PHP-DB] Stupid newbie looping MySQL question
> At 4:37 PM -0500 1/6/01, Todd Pillars wrote:
> >that warning means there is no - meaning 0 - results. You might try
> >
> >if (!$result = mysql_query ("Select name from mytable")) {
> > printf("error: %d %s", mysql_errno($link), mysql_error($link));
> >} else {
> >while ($row = mysql_fetch_array ($result)) {
> > $newTableName = $row['0'];
> > $sSQL = "Select id,thread,subject,author,datestamp from $newTableName
order
> >by datestamp desc limit 30";
> >}
> >
> >and see if an error is being reported.
>
> It just reports the same error: not a valid MySQL result resource,
pointing at the line starting with "while". The thing is if I run "select
name from mytable" in MySQL from the command line it pulls up three rows
just fine; the data is there and available from that query. And I imagine
that's why the "if(!$result..." clause returns false and goes into the
"else" clause. For some reason, the "while" isn't picking anything up. Why
would it give a warning that there isn't any data in $row when it's finding
data in $result?
>
> Thanks.
>
> Lynn
> --
> Lynn Siprelle, Siprelle & Associates: Web Construction and Publishing
> Chief Assoc. Josephine b. 9/9/97 * New Assoc. Louisa due 5/1/01
> Business: lynn@siprelle com | Personal: lynsa@siprelle.com
> The New Homemaker: http://www.newhomemaker.com/
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
> For additional commands, e-mail: php-db-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>