Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I have a query I receive form a form, that spits out info. It works fine until I try to paginate. I know when i hit page 2 the "$querytest" variable does not follow. How can I get it to? I tried putting into a different variable and running the queries that way, it didn't work. I also tried making a session variable, it still didn't work. Here is the code I appreciate any suggestions.Code: Select all
// Get post info from lca_search_php form
$concat = " and ";
if(($_POST['state'] != null)) {
$querytest .= $con . " state = '$state' ";
$con = $concat;
}
elseif (($_POST['state'] == null))
{}
if(($_POST['exchange'] != null)) {
$querytest .= $con . " exchange like '%{$_POST['exchange']}%' ";
$con = $concat;
}
elseif (($_POST['exchange'] == null))
{}
if(($_POST['npa'] != null)) {
$querytest .= $con . " npa = '{$_POST['npa']}' ";
$con = $concat;
}
elseif (($_POST['npa'] == null))
{}
if(($_POST['nxx'] != null)) {
$querytest .= $con . " nxx = '{$_POST['nxx']}' ";
$con = $concat;
}
elseif (($_POST['nxx'] == null))
{}
// 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 = 20;
// 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
$query = "SELECT * FROM lca where $querytest LIMIT $from, $max_results";
$sql = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query); // show error
echo $query;
echo "<br>";
while($row = mysql_fetch_array($sql))
{
echo "<tr>";
echo "<td class='td'>";
echo $row['local_state'];
echo "</td>";
echo "<td class='td1'>";
echo $row['local_rate_center'];
echo "</td>";
echo "<td class='td'>";
echo $row['local_npa'];
echo "</td>";
echo "<td class='td'>";
echo $row['local_nxx'];
echo "</td>";
echo "<td class='td'>";
echo $row['type'];
echo "</td>";
echo "<td class='td1'>";
echo $row['telco'];
echo "</td>";
echo "</tr>";
}
echo "<br>";
echo "</table>";
echo "</fiedset>";
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM lca where $querytest"),0);
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
echo "<fieldset>";
// Build Page Number Hyperlinks
echo "<center>Select a Page<br />";
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> ";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>";
}
echo "</center>";
echo "</fiedset>";
?>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]