Luvac Zantor Posted November 2, 2003 Share Posted November 2, 2003 This is the code, pretty straight forward. $server = mysql_connect($host, $username, $password) or die(mysql_error()); $connection = mysql_select_db($database, $server); $sql = \'SELECT PASSING.Player, PASSING.Cmp, PASSING.Att, PASSING.Yds, PASSING.TD, PASSING.Ints\'; $sql .= \'FROM PASSING\'; $sql .= \'ORDER BY PASSING.Yds DESC LIMIT 0, 3\'; $result = mysql_query($sql); echo $result ?> I\'ve tried many variations, but obviously I\'m new and have no clue. I assume it\'s parsing, because I get a blank page (when I mess around with the query, i\'ll get errors). It\'s the damn blank page. Any suggestions? Thanks! Quote Link to comment Share on other sites More sharing options...
DylanBlitz Posted November 2, 2003 Share Posted November 2, 2003 3 comments. Something to keep in mind when your coding, about 99% of the things in php need to end in ; You executed the query but after that you need to fetch the array you just told mysql to get. And lastly, when you pull something from mysql, it assigns the results to an array, so you need to tell php what part of the array you want to show. So you made a good effort and got real close give this a shot [php:1:602bbf1d27]<?php $server = mysql_connect($host, $username, $password) or die(mysql_error()); $connection = mysql_select_db($database, $server); $sql = \'SELECT PASSING.Player, PASSING.Cmp, PASSING.Att, PASSING.Yds, PASSING.TD, PASSING.Ints\'; $sql .= \'FROM PASSING\'; $sql .= \'ORDER BY PASSING.Yds DESC LIMIT 0, 3\'; $query = mysql_query($sql); $result = mysql_fetch_array(query); echo \"Player is \" . $result[Player] . \"<BR>\"; echo \"Players yards are \" . $result[Yds] . \"<BR>\"; ?>[/php:1:602bbf1d27] Quote Link to comment Share on other sites More sharing options...
Luvac Zantor Posted November 2, 2003 Author Share Posted November 2, 2003 this is the error I get Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/Zantor/public_html/af2/test.php on line 24 line 24 is $result = mysql_fetch_array(query); I noticed,, did you forget the $ before query? going to try that.. *shrugs* Quote Link to comment Share on other sites More sharing options...
Luvac Zantor Posted November 2, 2003 Author Share Posted November 2, 2003 nope same error..... Quote Link to comment Share on other sites More sharing options...
Luvac Zantor Posted November 2, 2003 Author Share Posted November 2, 2003 btw, if I use a query analizer..... the query DOES return information, so it\'s there.... Quote Link to comment Share on other sites More sharing options...
DylanBlitz Posted November 2, 2003 Share Posted November 2, 2003 look at this tutorial, http://www.phpfreaks.com/tutorials/33/0.php Once you query the database you need to fetch the data into an array. Yes the database was queried but the info is not really in a variable that\'s usable until you fetch it. Quote Link to comment Share on other sites More sharing options...
Luvac Zantor Posted November 2, 2003 Author Share Posted November 2, 2003 thanks for the link looking now. Quote Link to comment Share on other sites More sharing options...
Luvac Zantor Posted November 2, 2003 Author Share Posted November 2, 2003 looks like my query is wrong.. too many lines maybe? regardless it works now as this.... $server = mysql_connect($host, $username, $password) or die(mysql_error()); $connection = mysql_select_db($database, $server); $sql = \'SELECT * FROM PASSING\'; $query = mysql_query($sql); $result = mysql_fetch_array($query); echo "Player is " . $result[Player] . "<BR>"; echo "Players yards are " . $result[Yds] . "<BR>"; It displays now, but how do I get it to display just the top 3 in yards? Quote Link to comment Share on other sites More sharing options...
Luvac Zantor Posted November 2, 2003 Author Share Posted November 2, 2003 got it, my query has to be one line. I just put all the query info into ONE line, and it appears to be working now. Quote Link to comment Share on other sites More sharing options...
Luvac Zantor Posted November 2, 2003 Author Share Posted November 2, 2003 ok, how do I query the \"next\" row in an array? I tried mysql_fetch_row() but it failed.... Quote Link to comment Share on other sites More sharing options...
DylanBlitz Posted November 2, 2003 Share Posted November 2, 2003 ah okay, what was probably happening was your query was returning nothing. If you have phpmyadmin you can paste the query in there and see what you get back. The query might of worked but if nothing gets returned then you\'d get that error on the fetch array. And to move through the records you want to do a for or while loop, I prefer for\'s. [php:1:bb865c6431] $server = mysql_connect($host, $username, $password) or die(mysql_error()); $connection = mysql_select_db($database, $server); $query = mysql_query(\"SELECT Player, Yds FROM PASSING ORDER BY Yds DESC LIMIT 3\"); for ($i = 0; $i < mysql_num_rows($query); $i++) { $result = mysql_fetch_row($query); echo \"Player is \" . $result[Player] . \"<BR>\"; echo \"Players yards are \" . $result[Yds] . \"<BR>\"; } [/php:1:bb865c6431] That should work. If that works then just start adding stuff to your query, like the TD and other fields. Let me know if it doesn\'t work and I\'ll crank on it some more Quote Link to comment Share on other sites More sharing options...
DylanBlitz Posted November 2, 2003 Share Posted November 2, 2003 btw, the query doesn\'t have to be on one line. The way you were building the query was right. Quote Link to comment Share on other sites More sharing options...
Luvac Zantor Posted November 2, 2003 Author Share Posted November 2, 2003 trying that now. I agree that it should work, you\'d think, but if my query is multiple lines,, doesn\'t work. I put it in one line, it works *Shrugs* Also the query works in phpmyadmin, which is why I was initially confused. btw, thanks for the help!!! Quote Link to comment Share on other sites More sharing options...
Luvac Zantor Posted November 2, 2003 Author Share Posted November 2, 2003 the page is displaying multiple lines with NO stats showing. Quote Link to comment Share on other sites More sharing options...
DylanBlitz Posted November 2, 2003 Share Posted November 2, 2003 the only reason I could see it not working is because of the spacing you had. You\'d run into the problem of it looking like SELECT PASSING.Player, PASSING.Cmp, PASSING.Att, PASSING.Yds, PASSING.TD, PASSING.IntsFROM PASSINGORDER BY PASSING.Yds DESC LIMIT 0, 3\'; with no space between the Ints and From and Passing and order. Quote Link to comment Share on other sites More sharing options...
DylanBlitz Posted November 2, 2003 Share Posted November 2, 2003 hmm, okay, try two different things. Maybe someone that knows more about mysql can explain it but this is what I get twisted on all the time heh [php:1:1c734f0c85] for ($i = 0; $i < mysql_num_rows($query); $i++) { $result = mysql_fetch_row($query); echo \"Player is \" . $result[0] . \"<BR>\"; echo \"Players yards are \" . $result[1] . \"<BR>\"; } [/php:1:1c734f0c85] or [php:1:1c734f0c85] for ($i = 0; $i < mysql_num_rows($query); $i++) { $result = mysql_fetch_array($query); echo \"Player is \" . $result[Player] . \"<BR>\"; echo \"Players yards are \" . $result[Yds] . \"<BR>\"; } [/php:1:1c734f0c85] let me know if either of those work Quote Link to comment Share on other sites More sharing options...
Luvac Zantor Posted November 2, 2003 Author Share Posted November 2, 2003 got it... I modified what you had slightly and it\'s working now $connection = mysql_select_db($database, $server); $sql = \'SELECT * FROM PASSING ORDER BY PASSING.Yds DESC LIMIT 0, 3 \'; $query = mysql_query($sql); $i = 0; while ($i < mysql_num_rows($query)) { $result = mysql_fetch_array($query); echo "Player is " . $result[Player] . "<BR>"; echo "Players yards are " . $result[Yds] . "<BR>"; $i++; } some changes probably not needed, but changed the internal num_row to fetch_array and it\'s doing what it should! THANKS FOR THE INSIGHT, it utterly helped me fix the problem. THANKS!!! Quote Link to comment Share on other sites More sharing options...
Luvac Zantor Posted November 2, 2003 Author Share Posted November 2, 2003 dang you were quick to respond.... I just guessed at using the fetch_array, which apparently is what you replied with. again, thanks for the help!!!!! Quote Link to comment Share on other sites More sharing options...
DylanBlitz Posted November 2, 2003 Share Posted November 2, 2003 hehe glad you got it working. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.