Forum Moderators: coopster
<html>
<?php
$db = mysql_connect("localhost","root","");
mysql_select_db("project",$db);
$result = mysql_query("SELECT * FROM products",$db);
echo "<table border=2>";
echo "<tr><td> </td><td><b>Category</b> <td><b>Id</b><td><b>Description</b><td><b>Price</b> <td><b>Quantity</b></tr>";
while ($myrow = mysql_fetch_array($result))
{echo "<TR><TD><INPUT TYPE=CHECKBOX Value='".$myrow["Id"]."'><TD>".$myrow["cat"]. "<TD>".$myrow["Id"]."<TD>".$myrow["desc"]."<TD>" ."$".$myrow["price"]."<TD><input type='text' size=2 maxlength=2 value='0'>";
}
echo "</table>";
?>
<p><a href="home.php"><img src="garlic.jpg" width="50" height="46" border="0"></a>
<strong><a href="home.php">Home</a></strong> </p>
</html>
<style type="text/css">
<!--
body {
background-color: #FFFF99;
}
body,td,th {
color: #333333;
}
-->
</style>
<title>Products</title>
<body>
<div align="center"></div>
<FORM METHOD=GET ACTION="http://localhost/~calista/project/viewcart.php" TARGET="" >
<div align="center"><FONT SIZE="+1" COLOR="#000000" FACE="Times Roman">
<INPUT TYPE=SUBMIT VALUE="Put these in my cart!">
</FONT> </div>
</FORM>
</body>
</html>
[edited by: jatar_k at 4:04 pm (utc) on April 14, 2004]
[edit reason] fixed sidescroll [/edit]
<html>
<style type="text/css">
<!--
body {
background-color: #FFFF99;
}
body,td,th {
color: #333333;
}
-->
</style>
<title>Products</title>
<body><?php
$qty = 50; //the number of item per page
if(isset($_GET["rowstart"])) {$rowstart = $_GET["rowstart"];} else {$rowstart = "0";} //check is rowstart is not NULL, if NULL then rowstart is equal to 0 otherwise rowstart is equal to its current value$db = mysql_connect("localhost","root","");
mysql_select_db("project",$db);
$result = mysql_query("SELECT * FROM products LIMIT $rowstart,$halfb",$qty); // set a limit, that is starting from rowstart and show qty images (here 50)
$numrows=mysql_num_rows($result); // Count the total No of rowsecho "<table border=2>";
echo "<tr><td> </td><td><b>Category</b><td> <b>Id</b><td><b>Description</b><td><b>Price</b> <td><b>Quantity</b></tr>";
while ($myrow = mysql_fetch_array($result))
{echo "<TR><TD><INPUT TYPE=CHECKBOX Value='".$myrow["Id"]."'><TD>".$myrow["cat"]. "<TD>".$myrow["Id"]."<TD>".$myrow["desc"]."<TD>" ."$".$myrow["price"]."<TD><input type='text' size=2 maxlength=2 value='0'>";}
echo "</table>";
?>
<p><a href="home.php"><img src="garlic.jpg" width="50" height="46" border="0"></a>
<strong><a href="home.php">Home</a></strong> </p>
</html><div align="center"></div>
<FORM METHOD=GET ACTION="http://localhost/~calista/project/viewcart.php" TARGET="" >
<div align="center"><FONT SIZE="+1" COLOR="#000000" FACE="Times Roman">
<INPUT TYPE=SUBMIT VALUE="Put these in my cart!">
</FONT> </div>
</FORM>$rowstart_prev = $rowstart-$qty;
$rowstart_next = $rowstart+$qty;if ($rowstart > $qty) {
echo "<< <a href='http://localhost/~calista/project/viewcart.php?rowstart=".$rowstart_prev."'>Previous</a>";}
//Check if rowstart is bigger than qty, if yes it means that there is a previous pageif ($rowstart_next > $numrows) { } else {
echo "<a href='http://localhost/~calista/project/viewcart.php?rowstart=".$rowstart_next."'>Next >></a>";}
// check if rowstart_next is bigger than the total numbers of rows, if yes then there are no next page, else there is.</body>
</html>
Tomda
[edited by: jatar_k at 4:05 pm (utc) on April 14, 2004]
[edit reason] fixed sidescroll [/edit]
TheLIMITclause can be used to constrain the number of rows returned by the
SELECT [dev.mysql.com] statement.LIMITtakes one or two numeric arguments, which must be integer
constants. With two arguments, the first argument specifies the offset of the first row
to return, and the second specifies the maximum number of rows to return.
The offset of the initial row is 0 (not 1):SELECT * FROM table LIMIT 5,10; # Retrieve rows 6-15With one argument, the value specifies the number of rows to return from the
beginning of the result set:SELECT * FROM table LIMIT 5; # Retrieve first 5 rowsIn other words, LIMIT n is equivalent to LIMIT 0,n.
I'm not sure where the $halfb variable comes in here...? Perhaps inadvertently left over by tomda as he was laying it out for you? Tracking his line of thought, I would think the query should read as follows...
$result = mysql_query("SELECT * FROM products LIMIT $rowstart,$qty");