HoTDaWg Posted April 9, 2007 Share Posted April 9, 2007 hi, i know this script is very basic but i cant figure out what im doing wrong. take a look: <?php $conn = mysql_connect('localhost','xxxxxxx',xxxxxx'); mysql_select_db('xxxxxxxxxxxx'); $rowsPerPage = "4"; $pageNum = "1"; if(isset($_GET['page'])){ $pageNum = $_GET['page']; } $offset = ($pageNum - 1) * ($rowsPerPage); $sql = "SELECT id,itemname,itemprice,itemdescription FROM items". "LIMIT $offset,$rowsPerPage"; $result = mysql_query($sql,$conn)or die(mysql_error()); while($row = mysql_fetch_assoc($result)){ echo "$id"; echo "$itemname"; echo "$itemprice"; echo "$itemdescription"; } mysql_free_result($result); mysql_close($conn); ?> any help would be great. HoTDaWg Quote Link to comment https://forums.phpfreaks.com/topic/46287-solved-simple-paging-help/ Share on other sites More sharing options...
sasa Posted April 9, 2007 Share Posted April 9, 2007 what is wrong? it looks OK for me Quote Link to comment https://forums.phpfreaks.com/topic/46287-solved-simple-paging-help/#findComment-225174 Share on other sites More sharing options...
Lumio Posted April 9, 2007 Share Posted April 9, 2007 $conn = mysql_connect('localhost','xxxxxxx',xxxxxx'); <- missing quote $conn = mysql_connect('localhost','xxxxxxx','xxxxxx'); Quote Link to comment https://forums.phpfreaks.com/topic/46287-solved-simple-paging-help/#findComment-225175 Share on other sites More sharing options...
HoTDaWg Posted April 9, 2007 Author Share Posted April 9, 2007 im sorry it was a mistake on my part when i was posting. in the real script the quote is there. also, appologies for my lack of explaining things. i get the following error upon loading of the page. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0,4' at line 1 sorry, i just got this new kickin book on Ajax (w00t w00t). lol, only a nerd would get excited:P thanks for any help, HoTDaWg Quote Link to comment https://forums.phpfreaks.com/topic/46287-solved-simple-paging-help/#findComment-225200 Share on other sites More sharing options...
Lumio Posted April 9, 2007 Share Posted April 9, 2007 "SELECT id,itemname,itemprice,itemdescription FROM items". "LIMIT $offset,$rowsPerPage"; that's gonna change to: SELECT id,itemname,itemprice,itemdescription FROM itemsLIMIT 0,0 You see? the problem is because of items and LIMIT so make it like: "SELECT id,itemname,itemprice,itemdescription FROM items ". "LIMIT $offset,$rowsPerPage"; You see the difference? Quote Link to comment https://forums.phpfreaks.com/topic/46287-solved-simple-paging-help/#findComment-225203 Share on other sites More sharing options...
per1os Posted April 9, 2007 Share Posted April 9, 2007 $sql = "SELECT id,itemname,itemprice,itemdescription FROM items". "LIMIT $offset,$rowsPerPage"; TO $sql = "SELECT id,itemname,itemprice,itemdescription FROM items LIMIT $offset,$rowsPerPage"; OR $sql = "SELECT id,itemname,itemprice,itemdescription FROM items ". "LIMIT $offset,$rowsPerPage"; Quote Link to comment https://forums.phpfreaks.com/topic/46287-solved-simple-paging-help/#findComment-225204 Share on other sites More sharing options...
esukf Posted April 9, 2007 Share Posted April 9, 2007 <?php $sql = "SELECT id,itemname,itemprice,itemdescription FROM items". "LIMIT $offset,$rowsPerPage"; $sql = "SELECT id,itemname,itemprice,itemdescription FROM items ". "LIMIT $offset,$rowsPerPage"; //need a space between items and LIMIT ?> Quote Link to comment https://forums.phpfreaks.com/topic/46287-solved-simple-paging-help/#findComment-225206 Share on other sites More sharing options...
Lumio Posted April 9, 2007 Share Posted April 9, 2007 lol... all the same -.- Quote Link to comment https://forums.phpfreaks.com/topic/46287-solved-simple-paging-help/#findComment-225207 Share on other sites More sharing options...
HoTDaWg Posted April 9, 2007 Author Share Posted April 9, 2007 i changed the code too: <?php $conn = mysql_connect('********','******','*********'); mysql_select_db('***********'); $rowsPerPage = "4"; $pageNum = "1"; if(isset($_GET['page'])){ $pageNum = $_GET['page']; } $offset = ($pageNum - 1) * ($rowsPerPage); $sql = "SELECT id,itemname,itemprice,itemdescription FROM items ". "LIMIT $offset,$rowsPerPage"; $result = mysql_query($sql,$conn)or die(mysql_error()); while($row = mysql_fetch_assoc($result)){ echo "$id"; echo "$itemname"; echo "$itemprice"; echo "$itemdescription"; } mysql_free_result($result); mysql_close($conn); ?> but now it shows a blank page. ??? i do, of course have content in the table, check it out: CREATE TABLE `items` ( `id` int(11) NOT NULL auto_increment, `itemname` varchar(255) default NULL, `itemprice` varchar(255) default NULL, `itemdescription` varchar(255) default NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=21 ; -- -- Dumping data for table `items` -- INSERT INTO `items` VALUES (1, 'Couch', '$1.00', 'A comfy couch!'); INSERT INTO `items` VALUES (2, 'Cars', '$100.00', 'A comfy car!'); INSERT INTO `items` VALUES (3, 'Couch', '$1.00', 'A comfy couch!'); INSERT INTO `items` VALUES (4, 'Couch', '$1.00', 'A comfy couch!'); INSERT INTO `items` VALUES (5, 'Couch', '$1.00', 'A comfy couch!'); INSERT INTO `items` VALUES (6, 'Couch', '$1.00', 'A comfy couch!'); INSERT INTO `items` VALUES (7, 'Couch', '$1.00', 'A comfy couch!'); INSERT INTO `items` VALUES (8, 'Couch', '$1.00', 'A comfy couch!'); INSERT INTO `items` VALUES (9, 'Couch', '$1.00', 'A comfy couch!'); INSERT INTO `items` VALUES (10, 'Couch', '$1.00', 'A comfy couch!'); INSERT INTO `items` VALUES (11, 'Couch', '$1.00', 'A comfy couch!'); INSERT INTO `items` VALUES (12, 'Couch', '$1.00', 'A comfy couch!'); INSERT INTO `items` VALUES (13, 'Couch', '$1.00', 'A comfy couch!'); INSERT INTO `items` VALUES (14, 'Couch', '$1.00', 'A comfy couch!'); INSERT INTO `items` VALUES (15, 'Couch', '$1.00', 'A comfy couch!'); INSERT INTO `items` VALUES (16, 'Couch', '$1.00', 'A comfy couch!'); INSERT INTO `items` VALUES (17, 'Couch', '$1.00', 'A comfy couch!'); INSERT INTO `items` VALUES (18, 'Couch', '$1.00', 'A comfy couch!'); INSERT INTO `items` VALUES (19, 'Couch', '$1.00', 'A comfy couch!'); INSERT INTO `items` VALUES (20, 'Couch', '$1.00', 'A comfy couch!'); wierd ... HoTDaWg Quote Link to comment https://forums.phpfreaks.com/topic/46287-solved-simple-paging-help/#findComment-225216 Share on other sites More sharing options...
Lumio Posted April 9, 2007 Share Posted April 9, 2007 <?php while($row = mysql_fetch_assoc($result)){ echo $row['id']; echo $row['itemname']; echo $row['itemprice']; echo $row['itemdescription']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/46287-solved-simple-paging-help/#findComment-225218 Share on other sites More sharing options...
HoTDaWg Posted April 9, 2007 Author Share Posted April 9, 2007 thanks!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/46287-solved-simple-paging-help/#findComment-225252 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.