Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Hey,
Hi,
I have a script that is used to display records from mysql database ..
Below is a basic layout of how it is setup for pagination etc ..
I havnt been able to create a function that will search mysql table and display results in the following format apon posting from a form:Code: Select all
<?php
require("db.php");
// If current page number use it, if not set one.
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
// Define the number of results per page.
$max_results = 10;
// Figure out the limit for the query based on the current page number.
$from = (($page * $max_results) - $max_results);
// Perform MySQL query on only the current page number's results.
$sql = mysql_query("SELECT * FROM items LIMIT $from, $max_results");
// Figure out the total number of results in DB.
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM items"),0);
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
echo "<center>";
// Build Previous Link.
if($page > 1){
$prev = ($page - 1);
echo "<font size="2" face="tahoma"><< <a href="".$_SERVER['PHP_SELF']."?action=products&cmd=$item&page=$prev">Previous</a> | </font>";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "<font size="2" face="tahoma"><a href="".$_SERVER['PHP_SELF']."?action=products&cmd=$item&page=$i">$i</a> </font>";
}
}
// Build Next Link.
if($page < $total_pages){
$next = ($page + 1);
echo "<font size="2" face="tahoma"> | <a href="".$_SERVER['PHP_SELF']."?action=products&cmd=$item&page=$next">Next</a> >></font>";
}
echo "</center><br>";
while($row = mysql_fetch_array($sql)){
$item = $row['item'];
$product = $row['product'];
// Build your formatted results here.
echo "bla bla";
}
// Figure out the total number of results in DB.
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM items"),0);
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
echo "<center>";
// Build Previous Link.
if($page > 1){
$prev = ($page - 1);
echo "<font size="2" face="tahoma"><< <a href="".$_SERVER['PHP_SELF']."?action=products&cmd=$item&page=$prev">Previous</a> | </font>";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "<font size="2" face="tahoma"><a href="".$_SERVER['PHP_SELF']."?action=products&cmd=$item&page=$i">$i</a> </font>";
}
}
// Build Next Link.
if($page < $total_pages){
$next = ($page + 1);
echo "<font size="2" face="tahoma"> | <a href="".$_SERVER['PHP_SELF']."?action=products&cmd=$item&page=$next">Next</a> >></font>";
}
echo "</center>";
?>Code: Select all
$sql = "SELECT * FROM items WHERE itemDesc LIKE '%$desc%' OR `product` LIKE '%$desc%' OR `filter` LIKE '%$desc%'";feyd | Help us, help you. Please use
Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]