slipperyfish Posted March 26, 2006 Share Posted March 26, 2006 Hey! Here is my PHP code:[code]<?php[CONNECT INFO]$feedbackSQL = "SELECT * FROM feedback ORDER BY time ASC LIMIT 10"; $feedback = mysql_query($feedbackSQL) or die("Error communicating with database."); If ($feedback) { while($feedbackInfo=mysql_fetch_array($feedback)) { $feedbackName = $feedbackInfo[feedbackName]; $feedbackEmail = $feedbackInfo[feedbackEmail]; $feedback = $feedbackInfo[feedback]; print "<u>Feedback</u><br /><b>Name:</b> " .$feedbackName. " - <b>Email:</b> " .$feedbackEmail. "<br />" .$feedback. ""; } // Display numbers $totalSQL = "SELECT COUNT(*) FROM feedback"; $totalRun = mysql_query($totalSQL); $total = mysql_fetch_array($totalRun); If ($total > "10") { $total = abs($total); $pages = ($total/10); $x = 1; while($x<$pages){ echo $x; $x++; } } } else { print "No feedback, soz boz!"; }?>[/code]Thats my work in progress .. however it, returns the first result form the db, then underneath has this error:Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/fhlinux218/n/newbiestyle.co.uk/user/htdocs/help/feedback.php on line 14.. confused I am, here's the script's URL:[a href=\"http://www.newbiestyle.co.uk/help/feedback.php\" target=\"_blank\"]http://www.newbiestyle.co.uk/help/feedback.php[/a]Help much appreciated.. Quote Link to comment Share on other sites More sharing options...
annihilate Posted March 26, 2006 Share Posted March 26, 2006 My guess is that you can't use mysql_fetch_array on a query that uses count.Try $total = mysql_result($totalRun, 0, 0); Quote Link to comment Share on other sites More sharing options...
slipperyfish Posted March 26, 2006 Author Share Posted March 26, 2006 still not working :S Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 26, 2006 Share Posted March 26, 2006 You are reusing your pointer to the results. You can't do that and expect it to work.Your code:[code]<?php $feedback = mysql_query($feedbackSQL) or die("Error communicating with database."); If ($feedback) { while($feedbackInfo=mysql_fetch_array($feedback)) { $feedbackName = $feedbackInfo[feedbackName]; $feedbackEmail = $feedbackInfo[feedbackEmail]; $feedback = $feedbackInfo[feedback]; // here's the problem?>[/code]The fix:[code]<?php $rs = mysql_query($feedbackSQL) or die('Problem with query: ' . $feedbackSQL . '<br>' . mysql_error()); // don't need long varibale names for query results. If you're going to use the "or die" clause, make the message it puts out meaningful so you can fix the error. If ($rs) { while($rw=mysql_fetch_assoc($feedback)) { // again, why the long variable name $feedbackName = $rw['feedbackName']; $feedbackEmail = $rw['feedbackEmail']; $feedback = $rw['feedback']; // now there is no conflict on the variable names?>[/code]See the comments in the above code. You will have to change the rest of your code appropriately.Ken Quote Link to comment Share on other sites More sharing options...
slipperyfish Posted March 26, 2006 Author Share Posted March 26, 2006 ok, iv done what you put ken.. this is my new code:[code]<?php$db = mysql_connect("*****", "*****", "*******") or die("Could Not Connect");if(!$db) die("no db");if(!mysql_select_db("*******",$db)) die("No database selected.");$feedbackSQL = "SELECT * FROM feedback"; $rs = mysql_query($feedbackSQL) or die('Problem with query: ' . $feedbackSQL . '<br>' . mysql_error()); If ($rs) { while($rw=mysql_fetch_assoc($feedback)) { $feedbackName = $rw['feedbackName']; $feedbackEmail = $rw['feedbackEmail']; $feedback = $rw['feedback']; print "<u>Feedback</u><br /><b>Name:</b> " .$feedbackName. " - <b>Email:</b> " .$feedbackEmail. "<br />" .$feedback. ""; } } else { print "No feedback, soz boz!"; }?>[/code]you can view this script:[a href=\"http://www.newbiestyle.co.uk/help/feedback.php\" target=\"_blank\"]http://www.newbiestyle.co.uk/help/feedback.php[/a]Im now getting the following error:Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/fhlinux218/n/newbiestyle.co.uk/user/htdocs/help/feedback.php on line 14so confused :S help appreciated! Quote Link to comment Share on other sites More sharing options...
annihilate Posted March 26, 2006 Share Posted March 26, 2006 while($rw=mysql_fetch_assoc($feedback)) {replace $feedback with $rs Quote Link to comment Share on other sites More sharing options...
slipperyfish Posted March 26, 2006 Author Share Posted March 26, 2006 luv ya guys! thanks for your help! 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.