Jump to content

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/46287-solved-simple-paging-help/
Share on other sites

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

"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?


$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";

 

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.