Nusha
08-05-2003, 06:20 PM
Hi!
Can somebody please help me with this?
I have the table in my database(MySQL) named "dogs" with two columns in it "name" (varchar type) and "birth" (date type).
+-----------------+-----------------+
| Name | Birth |
+-----------------+-----------------+
| Buffy | 2001-12-27 |
+-----------------+-----------------+
| Neko | 1998-03-05 |
+-----------------+-----------------+
| Sonya | 1997-01-13 |
+-----------------+-----------------+
| Rony | 1996-02-07 |
+-----------------+-----------------+
| Lord | 1996-07-15 |
+-----------------+-----------------+
| Aris | 1995-10-10 |
+-----------------+-----------------+
| Lin | 1999-09-19 |
+-----------------+-----------------+
| Art | 1992-11-08 |
+-----------------+-----------------+
I needed to be able to retrieve dogs with certain age , so I used this html form
<html>
<form action=search.php method=POST>
age min: <input type=text name=min><br>
age max: <input type=text name=max><br>
<input type=submit name=submit value="Submit">
</form>
</html>
and this script (search.php)
<?php
$conn = mysql_connect("host", "root", "pass") or die(mysql_error());
mysql_select_db("db",$conn) or die(mysql_error());
$sql = "SELECT name, birth, current_date, (year(current_date)-year(birth)) - (right(current_date,5)<right(birth,5)) AS age FROM dogs where (year(current_date)-year(birth)) - (right(current_date,5)<right(birth,5)) <= $_POST[max] AND (year(current_date)-year(birth)) - (right(current_date,5)<right(birth,5)) >= $_POST[min]";
$result = mysql_query($sql, $conn) or die(mysql_error());
echo "<table><tr>";
while ($user = mysql_fetch_array($result)) {
$name = $user['name'];
$age = $user['age'];
echo "<td>$name<br>$age</td>";
if (++$resultcount % 3 == 0)
echo "</tr><tr>";
}
echo "</tr></table>";
?>
Everything works just fine.
But now I would like to retrieve only 6 results on one page and to have "PREVIOUS PAGE" and "NEXT PAGE" links where it needed.
If you have any ideas how to do it please help me.
Can somebody please help me with this?
I have the table in my database(MySQL) named "dogs" with two columns in it "name" (varchar type) and "birth" (date type).
+-----------------+-----------------+
| Name | Birth |
+-----------------+-----------------+
| Buffy | 2001-12-27 |
+-----------------+-----------------+
| Neko | 1998-03-05 |
+-----------------+-----------------+
| Sonya | 1997-01-13 |
+-----------------+-----------------+
| Rony | 1996-02-07 |
+-----------------+-----------------+
| Lord | 1996-07-15 |
+-----------------+-----------------+
| Aris | 1995-10-10 |
+-----------------+-----------------+
| Lin | 1999-09-19 |
+-----------------+-----------------+
| Art | 1992-11-08 |
+-----------------+-----------------+
I needed to be able to retrieve dogs with certain age , so I used this html form
<html>
<form action=search.php method=POST>
age min: <input type=text name=min><br>
age max: <input type=text name=max><br>
<input type=submit name=submit value="Submit">
</form>
</html>
and this script (search.php)
<?php
$conn = mysql_connect("host", "root", "pass") or die(mysql_error());
mysql_select_db("db",$conn) or die(mysql_error());
$sql = "SELECT name, birth, current_date, (year(current_date)-year(birth)) - (right(current_date,5)<right(birth,5)) AS age FROM dogs where (year(current_date)-year(birth)) - (right(current_date,5)<right(birth,5)) <= $_POST[max] AND (year(current_date)-year(birth)) - (right(current_date,5)<right(birth,5)) >= $_POST[min]";
$result = mysql_query($sql, $conn) or die(mysql_error());
echo "<table><tr>";
while ($user = mysql_fetch_array($result)) {
$name = $user['name'];
$age = $user['age'];
echo "<td>$name<br>$age</td>";
if (++$resultcount % 3 == 0)
echo "</tr><tr>";
}
echo "</tr></table>";
?>
Everything works just fine.
But now I would like to retrieve only 6 results on one page and to have "PREVIOUS PAGE" and "NEXT PAGE" links where it needed.
If you have any ideas how to do it please help me.
