princeofpersia Posted December 17, 2010 Share Posted December 17, 2010 Hi guys, can u help me to see what im doing wrong here? i keep getting this error Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource when i remove LIMIT $start, $per_page" it works but im working on pagination, thanks guys <?php session_start(); include ("../global.php"); //welcome messaage $username=$_SESSION['username']; echo "$username"; $query=mysql_query("SELECT id FROM users WHERE username='$username'"); while($row = mysql_fetch_array($query)) { $id = $row['id']; echo "$id"; } //get pageinatio in each page $per_page=5; $start=$_GET['start']; $record_count =mysql_num_rows(mysql_query("SELECT * FROM msg")); $max_page=$record_count/$per_page; $get= mysql_query("SELECT id, title,reference FROM msg LIMIT $start, $per_page"); while($row = mysql_fetch_assoc($get)) { $title=$row['title']; $reference=$row['msg']; echo "$title"; } ?> <table> <td><?php echo $reference; ?></td></tr> <td><?php echo $title; ?></td></tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/222015-what-im-doing-wrong-help-plzzzz/ Share on other sites More sharing options...
Rifts Posted December 17, 2010 Share Posted December 17, 2010 $query=mysql_query("SELECT id FROM users WHERE username='$username'"); while($row = mysql_fetch_array($query)) { $id = $row['id']; echo "$id"; } to $query=mysql_query("SELECT id FROM users WHERE username='$username'"); while($row = mysql_fetch_assoc($query)) { $id = $row['id']; echo $id; } Quote Link to comment https://forums.phpfreaks.com/topic/222015-what-im-doing-wrong-help-plzzzz/#findComment-1148797 Share on other sites More sharing options...
Maq Posted December 17, 2010 Share Posted December 17, 2010 Where do you define $start and $per_page? Give us the code that isn't working. Quote Link to comment https://forums.phpfreaks.com/topic/222015-what-im-doing-wrong-help-plzzzz/#findComment-1148799 Share on other sites More sharing options...
Pikachu2000 Posted December 17, 2010 Share Posted December 17, 2010 $start isn't defined. if( intval($_GET['start']) < 1 ) { $start = 0; } else { $start = (int) $_GET['start']; } [/code] (Double check the var names, I had to type this on my phone.) Quote Link to comment https://forums.phpfreaks.com/topic/222015-what-im-doing-wrong-help-plzzzz/#findComment-1148801 Share on other sites More sharing options...
princeofpersia Posted December 17, 2010 Author Share Posted December 17, 2010 thanks Pikachu2000, im gonna try it now & Maq this is my code which is not working Rifts thanks, im going to try the code and send the result thank u very much guys Quote Link to comment https://forums.phpfreaks.com/topic/222015-what-im-doing-wrong-help-plzzzz/#findComment-1148808 Share on other sites More sharing options...
princeofpersia Posted December 17, 2010 Author Share Posted December 17, 2010 Pikachu2000 it worked mate thanks, thank u for ur time guys, where would world be without u guys?!!! Quote Link to comment https://forums.phpfreaks.com/topic/222015-what-im-doing-wrong-help-plzzzz/#findComment-1148810 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.