Good Day;
I'm new here, I've poked around for erroneous information from time to time. Generally I can find my resolve simply by using the Search Feature, but this time I just can't figure it out.
I read the guidelines, but I'll probably screw something up. I'm only human!!!
Here's the HTML -->
<form action="company-search.php" method="post" name="companynamesearch">
Search By Company: <input type="text" name="term" maxlength="50"/> <input type="submit" name="submit" value="Submit" />
</form>
/*Pretty simple stuff, right?*/
Now we'll take a look at the Query. I've ignored all Database related information (hostname, username, password, table name), as they are not relevant. None of that is causing issue.
We start building variables, creating the Pagination ->
$tableName="CompanySearch";
$targetpage = "company-search.php";
$limit = 10;
$query = "SELECT COUNT(*) as num FROM $tableName";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];
$stages = 3;
$page = mysql_escape_string($_GET['page']);
if($page){
$start = ($page - 1) * $limit;
}else{
$start = 0;
}
Note the above code works fine, it's simply for reference (unless there is something wrong, then yell away!)
Now for the query -->
// Get page data
$term = $_POST['term'];
$query1 = "select * from $tableName order by CompanyName limit $start, $limit" ;
$result = mysql_query($query1) or die('Unable to populate.');
As a result, this all works flawlessly injunction with my Pagination.
If I change $query1 to read like this -->
$query1 = "select * from $tableName where CompanyName like '%term%' limit $start, $limit";
Then I receive no information back from the Database query. if I add a on die(mysql_error());, I still get nothing, just blank. There's no CSS saying display this, or that. It's very straight forward.
For reference - I'm using while($row = mysql_fetch_array($result)) to show the results of the page.
JUST incase you wanted to see the ENTIRE pagination file, the rest of it is included below -->
// Initial page num setup
if ($page == 0){$page = 1;}
$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($total_pages/$limit);
$LastPagem1 = $lastpage - 1;
$paginate = '';
if($lastpage > 1)
{
$paginate .= "<div class='paginate' style='font-family:Arial, Helvetica, sans-serif;padding: 3px;margin: 3px;margin-top:50px;'>";
// Previous
if ($page > 1){
$paginate.= "<a style='padding:2px 5px 2px 5px;margin:2px;border:1px solid #c0c0c0;text-decoration:none;color:rgb(14,101,175);' href='$targetpage?page=$prev'>previous</a>";
}else{
$paginate.= "<span class='disabled' style='padding:2px 5px 2px 5px;margin:2px;border:1px solid #eee; color: rgb(14,101,175);'> previous </span>"; }
// Pages
if ($lastpage < 7 + ($stages * 2)) // Not enough pages to breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current' style='margin: 2px;padding: 2px 5px 2px 5px;border: 1px solid #c0c0c0;font-weight: bold;background-color:rgb(14,101,175);color:rgb(255,255,255);'>$counter</span>";
}else{
$paginate.= "<a style='padding:2px 5px 2px 5px;margin:2px;border:1px solid #c0c0c0;text-decoration:none;color:rgb(14,101,175);' onmouseover=\"this.style.css='border:1px solid #c0c0c0;'\" href='$targetpage?page=$counter'>$counter</a>";}
}
}
elseif($lastpage > 5 + ($stages * 2)) // Enough pages to hide a few?
{
// Beginning only hide later pages
if($page < 1 + ($stages * 2))
{
for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current' style='margin: 2px;padding: 2px 5px 2px 5px;border: 1px solid #c0c0c0;font-weight: bold;background-color:rgb(14,101,175);color:rgb(255,255,255);'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
$paginate.= "...";
$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";
}
// Middle hide some front and some back
elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
{
$paginate.= "<a href='$targetpage?page=1'>1</a>";
$paginate.= "<a href='$targetpage?page=2'>2</a>";
$paginate.= "...";
for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current' style='margin: 2px;padding: 2px 5px 2px 5px;border: 1px solid #c0c0c0;font-weight: bold;background-color:rgb(14,101,175);color:rgb(255,255,255);'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
$paginate.= "...";
$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";
}
// End only hide early pages
else
{
$paginate.= "<a href='$targetpage?page=1'>1</a>";
$paginate.= "<a href='$targetpage?page=2'>2</a>";
$paginate.= "...";
for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current' style='margin: 2px;padding: 2px 5px 2px 5px;border: 1px solid #c0c0c0;font-weight: bold;background-color:rgb(14,101,175);color:rgb(255,255,255);'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
}
}
// Next
if ($page < $counter - 1){
$paginate.= "<a style='padding:2px 5px 2px 5px;margin:2px;border:1px solid #c0c0c0;text-decoration:none;color:rgb(14,101,175);' href='$targetpage?page=$next'>next</a>";
}else{
$paginate.= "<span class='disabled' style='padding:2px 5px 2px 5px;margin:2px;border:1px solid #eee; color:rgb(14,101,175);'>next</span>";
}
$paginate.= "</div>";
}
// pagination
echo '<center>'.$paginate;'</center>'
Any help you can provide would be GREATLY appreciated, as this is truly the last hurdle that stands between me and publishing.