Hello,
I am having trouble with a list that I am trying to make in php and mysql. I have got the basic list script and mysql table setup. Its all working all right and I want to make it a bit more advanced. The script is for people to submit there friend codes for popular apps on the ipod touch and iphone. I have got that part done but I want it so that it only displays 100 at a time and that the new codes get put to the top and not at the bottom of the table.
The code is as follows :
This is the index.php code where the table is shown and the submit form.
<html>
<body>
<form action="insert.php" method="post">
Code: <input type="text" name="code" />
<input name="submit" type="button" value="Submit" />
</form>
</body>
</html>
<?php
$con = mysql_connect("localhost","user","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("prx2_codes", $con);
$result = mysql_query("SELECT * FROM codes");
echo "<table border='1'>
<tr>
<th>Position</th>
<th>Codes</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['position'] . "</td>";
echo "<td>" . $row['code'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
This is the insert.php that is used in the form.
<?php
$con = mysql_connect("localhost","user","pass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("prx2_codes", $con);
$sql="INSERT INTO codes (code)
VALUES
('$_POST[code]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "Code Added To List";
mysql_close($con)
?>
If you could please help me in doing what I said it would be much appreciated.