Forum Moderators: coopster

Message Too Old, No Replies

Getting one records at a time from a database

         

99naa

12:47 am on Apr 19, 2006 (gmt 0)

10+ Year Member



I am not much of a programmer. I am trying to get one record at a time from a mysql database and then click on the next button to go to the next table. This is being done in PHP.

This is the code that I have so far. I am getting an error on this line of code. '$result = mysql_query($query)or die ("error");'

MyKey is the primary key.

<html>
<head></head>
<body>
<?php
include ("connect.php");
$MyKey=$_GET['MyKey'];
$query = "select * from teletext where category = 'world' limit 1, $MyKey";
$result = mysql_query($query)or die ("error");

echo "<table border = '1' width='65%'>";
echo "<tr><td><b>Page</b></td>";
echo '<td><b>World News</b></td></tr>';
while ($row = mysql_fetch_array($result))
{
echo "<tr><td>".stripslashes($row['page_nos'])."</td>";

echo "<td><b>" . stripslashes($row['headline'])."</b><br>" .stripslashes($row['news'])."</td></tr>";
}
echo "<a href page.php?MyKey=$MyKey+1>Next";
echo "<table border='1' width='40%'>";
echo "<tr><td align='center'><a href='welcome_page.php'>Home</a></td>";
echo "<td align='center'><a href='page.php?MyKey=$MyKey+1'>Next Page</a></td>";
echo "<td align='center'><a href='page.php?MyKey=$MyKey-1'>Previous Page</a></td></td>";
echo "</table>";
echo "</table>";
mysql_close();
?>
</body>
</html>

Any help would be greatfully received.

Many thanks

99naa

Habtom

3:55 am on Apr 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why do you have the $MyKey there?

//$query = "select * from teletext where category = 'world' limit 1, $MyKey";

But it shall work without it:

$query = "select * from teletext where category = 'world' limit 1";

Habtom

hakre

4:36 pm on Apr 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



it's
$query = "select * from teletext where category = 'world' limit $MyKey, 1";

put a sorting (order by clause) into the query to ensure you get the right results. $MyKey start at 0.

99naa

8:07 pm on Apr 24, 2006 (gmt 0)

10+ Year Member



thank you all so much for your help.

Vonz