Jump to content

problem: mysql tables rows - one row per page


moran1409

Recommended Posts

hello all,

i want to display each row from mysql table in a different page using this code:

		<?
	require_once('config.php');
//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
	die("can't connect: " . mysql_error());
}

$db = mysql_select_db(DB_DATABASE);
if(!$db) {
	die("can't select database");
}
mysql_query("SET NAMES 'hebrew'");
//mysql_set_charset('utf8',$link);

if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; }; 
  $start_from = $page-1; 

	$qry='SELECT * FROM ordering limit 0, 1';
	$result = mysql_query($qry);
	while($row = mysql_fetch_array($result)){

	echo     "<div dir='rtl' charset='utf8'><h2>"," hover cam: ",$row['hover_camera'],
	"<br> stills: ",$row['stills'],
	"<br> video_photographers: ",$row['video_photographers'],
	"<br> increase: ",$row['increase'],
	"<br> video_edit: ",$row['video_edit'],
	"<br> digital_album: ",$row['digital_album'],
	"<br> photo_album: ",$row['photo_album'],
	"<br> small_digital_album: ",$row['small_digital_album'],
	"<br> video_clip: ",$row['video_clip'],
	"<br> magnets: ",$row['magnets'],
	"<br> comments: ",$row['comments'],
	"<br> date: ",$row['date'],
	"<br><br></h2></div>";	

}
	$sql = "SELECT COUNT(userid) FROM ordering"; 
	$result = mysql_query($sql,$link); 
	$row2 = mysql_fetch_row($result); 
	$total_records = $row2[0]; 
	$total_pages = $total_records ; 

for ($i=1; $i<=$total_pages; $i++) { 
            echo "<a href='table.php?page=".$i."'>".$i."</a> "; 
}; 

	?>

 

this is the table:

CREATE TABLE IF NOT EXISTS `ordering` (
`userid` int(11) unsigned NOT NULL AUTO_INCREMENT,
`hover_camera` varchar(10) DEFAULT NULL,
`stills` int(5) NOT NULL,
`video_photographers` int(5) NOT NULL,
`increase` int(5) NOT NULL,
`video_edit` varchar(10) NOT NULL,
`digital_album` varchar(10) DEFAULT NULL,
`photo_album` varchar(10) DEFAULT NULL,
`small_digital_album` varchar(20) DEFAULT NULL,
`video_clip` varchar(10) DEFAULT NULL,
`magnets` int(10) NOT NULL,
`comments` text NOT NULL,
`date` date NOT NULL,
PRIMARY KEY (`userid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;

 

the problem is that only the first row is displayed no matter which page i choose

and i want each page to display the row assigned to it (page 15 = row 15 etc...)

any suggestions?

Link to comment
Share on other sites

You need to say:

'SELECT * FROM ordering WHERE userid=$page LIMIT 0,1'

 

The $page variable will obviously be the page number you wish to load. This way you have to make sure that the content you want for page 5 is put in the record with id 5, and so on with every page/record.

 

Denno

Link to comment
Share on other sites

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.