mysql_fetch_array

This is a discussion on mysql_fetch_array within the PHP Language forums, part of the PHP Programming Forums category; <?php echo "HI " . $name; $result = mysql_query("SELECT * FROM album WHERE username='{$name}'"); while ($next_row = mysql_fetch_array($...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-28-2003
Robert
 
Posts: n/a
Default mysql_fetch_array

<?php
echo "HI " . $name;
$result = mysql_query("SELECT * FROM album WHERE username='{$name}'");

while ($next_row = mysql_fetch_array($result)) {
$album_name = $next_row['name'];

echo "<a href=\"main.php?album=$album_name\"><font size=\"+1\"
color=\"#FFFFFF\">

$album_name

</font></a><br/>";
}
?>

This gives me a Warning that mysql_fetch_array isn't getting a valid MySQL
resource, but it has the right value in $name and doesn't have an obvious
problem, any debugging insight?

Thanks,
RG


Reply With Quote
  #2 (permalink)  
Old 10-28-2003
Daniel Tryba
 
Posts: n/a
Default Re: mysql_fetch_array

Robert <gtg463g@mail.gatech.edu> wrote:
> $result = mysql_query("SELECT * FROM album WHERE username='{$name}'");
> while ($next_row = mysql_fetch_array($result)) {

[snip]
> }
> ?>


Is this the entire script you are using?

> This gives me a Warning that mysql_fetch_array isn't getting a valid MySQL
> resource, but it has the right value in $name and doesn't have an obvious
> problem, any debugging insight?


YOu'r not checking if the query returns a valid response. Implement some
flow control: eg replace the $result line with:

$result=..........'{$name}'") or die(mysql_error());

And that might give you a usefull hint (like the fact that you forgot to
open a connection to a database).

--

Daniel Tryba

Reply With Quote
  #3 (permalink)  
Old 10-28-2003
Pedro
 
Posts: n/a
Default Re: mysql_fetch_array

Robert wrote:
> This gives me a Warning that mysql_fetch_array isn't getting a valid MySQL
> resource, but it has the right value in $name and doesn't have an obvious
> problem, any debugging insight?


use error-checking.

$sql = "select ...";
mysql_query($sql) or die(mysql_error() . " in [$sql]");


I couldn't recreate the error you got.


--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
Reply With Quote
  #4 (permalink)  
Old 10-28-2003
Robert
 
Posts: n/a
Default Re: mysql_fetch_array


"Daniel Tryba" <news_comp.lang.php@canopus.nl> wrote in message
news:bnkhu3$lcc$1@news.tue.nl...
> Robert <gtg463g@mail.gatech.edu> wrote:
> > $result = mysql_query("SELECT * FROM album WHERE username='{$name}'");
> > while ($next_row = mysql_fetch_array($result)) {

> [snip]
> > }
> > ?>

>
> Is this the entire script you are using?
>
> > This gives me a Warning that mysql_fetch_array isn't getting a valid

MySQL
> > resource, but it has the right value in $name and doesn't have an

obvious
> > problem, any debugging insight?

>
> YOu'r not checking if the query returns a valid response. Implement some
> flow control: eg replace the $result line with:
>
> $result=..........'{$name}'") or die(mysql_error());
>
> And that might give you a usefull hint (like the fact that you forgot to
> open a connection to a database).
>
> --
>
> Daniel Tryba
>


I was connecting, it was a selection problem. Thanks guys.


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:46 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0