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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 > > > |
|
|||
|
"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 > > > > > > > > |
|
|||
|
"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 > > > > > > > > > > > > > > > > > > > > > > > > |
|
|||
|
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 > > > |