query error

This is a discussion on query error within the PHP Language forums, part of the PHP Programming Forums category; I have a query that I expect to return 3 or 4 entries -- but I seem to be getting only ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-06-2003
Wm
 
Posts: n/a
Default query error

I have a query that I expect to return 3 or 4 entries -- but I seem to be
getting only the most recent entry, repeated 4 times. What am I doing wrong
here?

$query="SELECT artistID,email,city,state,country from artists WHERE
email='$email'";
$result=mysql_query($query) or die(mysql_error("Could not execute
query."));
if (mysql_num_rows($result) > 0){
$alreadylisted = "1";
echo "<CENTER>$email is already in our database. Are you listed
below?</CENTER><BR>";
while($row = mysql_fetch_array($result)) {
$artistID = $row['artistID'];
$email = $row['email'];
$city = $row['city'];
$state = $row['state'];
$country = $row['country'];
echo "<CENTER><HR><FONT size=\"2\" face=\"Arial, Helvetica,
sans-serif\">
<A HREF=\"javascript:;\"
onClick=\"openProfile('artist.php?artistID=".$arti stID.

"','Artist','resizable=yes,width=600,height=300')\ ">".$firstname."
".$lastname."</A><BR>"
.$city.", ".$state." ".$country."</FONT><BR></CENTER>";
}
echo "<HR><CENTER>If you are already listed above,
congratulations!<BR>
If needed, you may edit your listing using the link at
left.</CENTER>";
mysql_free_result($result);
}


Thanx,
Wm



Reply With Quote
  #2 (permalink)  
Old 08-06-2003
DjDrakk
 
Posts: n/a
Default Re: query error

try echoing your query to screen so you can read exactly what is being sent
to the database beforehand.

--

Warren Butt
-- Custom web design, cheap like cheese


"Wm" <LAshooter@hotmail.com> wrote in message
news:1haYa.1802083$ZC.268155@news.easynews.com...
> I have a query that I expect to return 3 or 4 entries -- but I seem to be
> getting only the most recent entry, repeated 4 times. What am I doing

wrong
> here?
>
> $query="SELECT artistID,email,city,state,country from artists WHERE
> email='$email'";
> $result=mysql_query($query) or die(mysql_error("Could not execute
> query."));
> if (mysql_num_rows($result) > 0){
> $alreadylisted = "1";
> echo "<CENTER>$email is already in our database. Are you listed
> below?</CENTER><BR>";
> while($row = mysql_fetch_array($result)) {
> $artistID = $row['artistID'];
> $email = $row['email'];
> $city = $row['city'];
> $state = $row['state'];
> $country = $row['country'];
> echo "<CENTER><HR><FONT size=\"2\" face=\"Arial, Helvetica,
> sans-serif\">
> <A HREF=\"javascript:;\"
> onClick=\"openProfile('artist.php?artistID=".$arti stID.
>
> "','Artist','resizable=yes,width=600,height=300')\ ">".$firstname."
> ".$lastname."</A><BR>"
> .$city.", ".$state." ".$country."</FONT><BR></CENTER>";
> }
> echo "<HR><CENTER>If you are already listed above,
> congratulations!<BR>
> If needed, you may edit your listing using the link at
> left.</CENTER>";
> mysql_free_result($result);
> }
>
>
> Thanx,
> Wm
>
>
>



Reply With Quote
  #3 (permalink)  
Old 08-06-2003
Wm
 
Posts: n/a
Default Re: query error

"DjDrakk" <DjDrakk@drakkradio.servemp3.com> wrote in message
news:vj2dmnopl9h08d@corp.supernews.com...
> try echoing your query to screen so you can read exactly what is being

sent
> to the database beforehand.
>
> Warren Butt
> -- Custom web design, cheap like cheese
>


echo "Query result = ".$result;

yields this output:

ArrayQuery result = Resource id #21

I'm not sure where the word "Array" is coming from, nor what the "Resource
id #21" is.....????

Wm



>
> "Wm" <LAshooter@hotmail.com> wrote in message
> news:1haYa.1802083$ZC.268155@news.easynews.com...
> > I have a query that I expect to return 3 or 4 entries -- but I seem to

be
> > getting only the most recent entry, repeated 4 times. What am I doing

> wrong
> > here?
> >
> > $query="SELECT artistID,email,city,state,country from artists WHERE
> > email='$email'";
> > $result=mysql_query($query) or die(mysql_error("Could not execute
> > query."));
> > if (mysql_num_rows($result) > 0){
> > $alreadylisted = "1";
> > echo "<CENTER>$email is already in our database. Are you listed
> > below?</CENTER><BR>";
> > while($row = mysql_fetch_array($result)) {
> > $artistID = $row['artistID'];
> > $email = $row['email'];
> > $city = $row['city'];
> > $state = $row['state'];
> > $country = $row['country'];
> > echo "<CENTER><HR><FONT size=\"2\" face=\"Arial, Helvetica,
> > sans-serif\">
> > <A HREF=\"javascript:;\"
> > onClick=\"openProfile('artist.php?artistID=".$arti stID.
> >
> > "','Artist','resizable=yes,width=600,height=300')\ ">".$firstname."
> > ".$lastname."</A><BR>"
> > .$city.", ".$state." ".$country."</FONT><BR></CENTER>";
> > }
> > echo "<HR><CENTER>If you are already listed above,
> > congratulations!<BR>
> > If needed, you may edit your listing using the link at
> > left.</CENTER>";
> > mysql_free_result($result);
> > }
> >
> >
> > Thanx,
> > Wm
> >
> >
> >

>
>



Reply With Quote
  #4 (permalink)  
Old 08-06-2003
Wm
 
Posts: n/a
Default Re: query error

"Trent Stith" <trents@airmail.net> wrote in message
news:bgribl$d9c@library2.airnews.net...
> You need to echo the query itself, not the result of the query.
>
> echo "<pre>";
> echo $query;
>
> that will return what your query is actually doing it may shed some light.
>


I pasted the lines above in after the query and got this result output to
the browser:

"Array
address@hotmail.com is already in our database. Are you listed below?"

I'm still not sure why I'm getting the word "Array" output, nor why I don't
see the query that I'm trying to verify. And I'm still getting the same info
output 4 times rather than 4 separate listings, but I'm sure that's a
different problem... <groan>

Thanx,
Wm


************************************************** ********
ORIGINAL MESSAGE(S):
************************************************** ********
> "Wm" <LAshooter@hotmail.com> wrote in message
> news:oLaYa.1378547$Ho4.9675373@news.easynews.com.. .
> > "DjDrakk" <DjDrakk@drakkradio.servemp3.com> wrote in message
> > news:vj2dmnopl9h08d@corp.supernews.com...
> > > try echoing your query to screen so you can read exactly what is being

> > sent
> > > to the database beforehand.
> > >
> > > Warren Butt
> > > -- Custom web design, cheap like cheese
> > >

> >
> > echo "Query result = ".$result;
> >
> > yields this output:
> >
> > ArrayQuery result = Resource id #21
> >
> > I'm not sure where the word "Array" is coming from, nor what the

"Resource
> > id #21" is.....????
> >
> > Wm
> >
> >
> >
> > >
> > > "Wm" <LAshooter@hotmail.com> wrote in message
> > > news:1haYa.1802083$ZC.268155@news.easynews.com...
> > > > I have a query that I expect to return 3 or 4 entries -- but I seem

to
> > be
> > > > getting only the most recent entry, repeated 4 times. What am I

doing
> > > wrong
> > > > here?
> > > >
> > > > $query="SELECT artistID,email,city,state,country from artists

WHERE
> > > > email='$email'";
> > > > $result=mysql_query($query) or die(mysql_error("Could not execute
> > > > query."));
> > > > if (mysql_num_rows($result) > 0){
> > > > $alreadylisted = "1";
> > > > echo "<CENTER>$email is already in our database. Are you

listed
> > > > below?</CENTER><BR>";
> > > > while($row = mysql_fetch_array($result)) {
> > > > $artistID = $row['artistID'];
> > > > $email = $row['email'];
> > > > $city = $row['city'];
> > > > $state = $row['state'];
> > > > $country = $row['country'];
> > > > echo "<CENTER><HR><FONT size=\"2\" face=\"Arial,

Helvetica,
> > > > sans-serif\">
> > > > <A HREF=\"javascript:;\"
> > > > onClick=\"openProfile('artist.php?artistID=".$arti stID.
> > > >
> > > > "','Artist','resizable=yes,width=600,height=300')\ ">".$firstname."
> > > > ".$lastname."</A><BR>"
> > > > .$city.", ".$state." ".$country."</FONT><BR></CENTER>";
> > > > }
> > > > echo "<HR><CENTER>If you are already listed above,
> > > > congratulations!<BR>
> > > > If needed, you may edit your listing using the link at
> > > > left.</CENTER>";
> > > > mysql_free_result($result);
> > > > }
> > > >
> > > >
> > > > Thanx,
> > > > Wm
> > > >
> > > >
> > > >
> > >
> > >

> >
> >

>
>



Reply With Quote
  #5 (permalink)  
Old 08-07-2003
James Jiao
 
Posts: n/a
Default Re: query error

Ok insert the echo "$query" line in the following places where indicated
with 'echo', that's how you should isolate the problem to one line of code:


"Wm" <LAshooter@hotmail.com> wrote in message
news:1haYa.1802083$ZC.268155@news.easynews.com...
> I have a query that I expect to return 3 or 4 entries -- but I seem to be
> getting only the most recent entry, repeated 4 times. What am I doing

wrong
> here?
>


echo

> $query="SELECT artistID,email,city,state,country from artists WHERE
> email='$email'";


echo

> $result=mysql_query($query) or die(mysql_error("Could not execute
> query."));


echo

> if (mysql_num_rows($result) > 0){
> $alreadylisted = "1";
> echo "<CENTER>$email is already in our database. Are you listed
> below?</CENTER><BR>";
> while($row = mysql_fetch_array($result)) {
> $artistID = $row['artistID'];
> $email = $row['email'];
> $city = $row['city'];
> $state = $row['state'];
> $country = $row['country'];
> echo "<CENTER><HR><FONT size=\"2\" face=\"Arial, Helvetica,
> sans-serif\">
> <A HREF=\"javascript:;\"
> onClick=\"openProfile('artist.php?artistID=".$arti stID.
>
> "','Artist','resizable=yes,width=600,height=300')\ ">".$firstname."
> ".$lastname."</A><BR>"
> .$city.", ".$state." ".$country."</FONT><BR></CENTER>";
> }
> echo "<HR><CENTER>If you are already listed above,
> congratulations!<BR>
> If needed, you may edit your listing using the link at
> left.</CENTER>";
> mysql_free_result($result);
> }
>
>
> Thanx,
> Wm
>
>
>



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 12:02 PM.


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