
October 17th, 2003, 12:24 AM
|
|
Contributing User
|
|
Join Date: Sep 2003
Posts: 117
Time spent in forums: 2 h 30 m 29 sec
Reputation Power: 6
|
|
|
page numbering prob
Hi guys,
I wanted to do page numbering in my results page. My code used to be okay before i put the code for page numbering.
I am wondering where did i do wrong because now it seems like not able to search properly. Now i am not able to get any results even the record is in the db. It seems like i screwed up with the sql query. Can you give me a hint where i've done wrong. Thanks..
Please advise
my code:
PHP Code:
<?php
// Database Connection
mysql_connect("", "user","pass") or die("Unable to connect to the server");
mysql_select_db("user_db") or die("Unable to connect to database");
// 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 = 15;
// 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 = 'select * from `club1` ';
$joiner = 'where ';
if (!empty($c_category))
{
$sql .= "{$joiner}`bcategory` LIKE '{$c_category}'";
$joiner = 'and ';
}
if (!empty($c_desc))
{
$sql .= "{$joiner}`c_desc` LIKE '%$c_desc%'";
$joiner = 'and ';
}
if (!empty($c_name))
{
$sql .= "{$joiner}`bcompany` LIKE '%$c_name%'";
$joiner = 'and ';
}
if (!empty($c_state))
{
$sql .= "{$joiner}`bstate` LIKE '%$c_state%'";
$joiner = 'and ';
}
if (!empty($c_country))
{
$sql .= "{$joiner}`bcountry` LIKE '$c_country'";
$joiner = 'and ';
}
//continue for the rest of the variables
$result = mysql_query ("$sql ORDER BY `bcompany` LIMIT $from, $max_results") or die (mysql_error());
//$sql = mysql_query("SELECT * FROM club1 LIMIT $from, $max_results") or die (mysql_error());
echo "<u><b>Your search: </b></u><br>" ;
if (!empty($c_category))
{
echo '<b>Category :</b>';
echo $c_category,'<br>';
}
if (!empty($c_country))
{
echo '<b>Country :</b>';
echo $c_country ,'<br>';
}
if (!empty($c_desc))
{
echo '<b>Description :</b>';
echo $c_desc ,'<br>';
}
if (!empty($c_name))
{
echo '<b>Name :</b>';
echo $c_name,'<br>';
}
if (!empty($c_state))
{
echo '<b>State :</b>';
echo $c_state,'<br>';
}
?>
<br></font></p>
<table border="0" width="656">
<tr>
<td width="72" bordercolor="#CCCCCC" bgcolor="#FFCCFF">
<p><font size="2" face="Arial" color="#3300CC"><b>Results:</b></font></p>
</td>
<td width="259" bordercolor="#CCCCCC" bgcolor="#FFCCFF">
<p>
<font size="2" face="Arial" color="#3300CC"><b>
<?
if($no == 0){
echo " <b>Sorry, no results found. Please try again.</b>";
include ("list_pgbd_new.htm");
exit ();
}
?>
</b></font>
</p>
</td>
<td width="94" bordercolor="#CCCCCC" bgcolor="#FFCCFF">
<p><font size="2" face="Arial" color="#3300CC"><b>No of results:</b></font></p>
</td>
<td width="203" bordercolor="#CCCCCC" bgcolor="#FFCCFF">
<p>
<font size="2" face="Arial" color="#3300CC"><b><?php
echo "( $no )";
?></b></font>
</p>
</td>
</tr>
<?
while ($row = mysql_fetch_array ($result)) {
?>
<tr>
<td width="72">
<p><font size="2" face="Arial" color="#3300CC"> Company:</font></p>
</td>
<td width="568" colspan="3">
<p><font size="2" face="Arial" color="#3300CC"><b><?php echo $row["bcompany"]; ?></b></font></p>
</td>
</tr>
<tr>
<td width="72">
<p><font size="2" face="Arial" color="#3300CC"> Address:</font></p>
</td>
<td width="259">
<p><font size="2" face="Arial" color="#3300CC"><?php echo $row["badd"]; ?></font></p>
</td>
<td width="94">
<p><font size="2" face="Arial" color="#3300CC">ZipCode:</font></p>
</td>
<td width="203">
<p><font size="2" face="Arial" color="#3300CC"><?php echo $row["bzipcode"]; ?></font> </p>
</td>
</tr>
<tr>
<td width="72">
<p><font size="2" face="Arial" color="#3300CC"> State:</font></p>
</td>
<td width="259">
<p><font size="2" face="Arial" color="#3300CC"><?php echo $row["bstate"]; ?></font></p>
</td>
<td width="94">
<p><font size="2" face="Arial" color="#3300CC">Country:</font> </p>
</td>
<td width="203">
<p><font size="2" face="Arial" color="#3300CC"><?php echo $row["bcountry"]; ?></font></p>
</td>
</tr>
<tr>
<td width="72">
<p><font size="2" face="Arial" color="#3300CC"> Phone:</font></p>
</td>
<td width="259">
<p>
<font size="2" face="Arial" color="#3300CC"><?
echo $row["b_phone_country"].$row["b_phone_area"].'-'.$row["b_phone_no"];
?></font>
</p>
</td>
<td width="94">
<p><font size="2" face="Arial" color="#3300CC"> Fax:</font></p>
</td>
<td width="203">
<p>
<font size="2" face="Arial" color="#3300CC"><?
echo $row["b_fax_country"].$row["b_fax_area"].'-'.$row["b_fax_no"];
?></font>
</p>
</td>
</tr>
<tr>
<td width="646" colspan="4">
<p><font size="2" face="Arial" color="#3300CC"><?php
if ( $row["c_desc"]!="")
{
echo "<br><b>Description: </b>";
echo $row["c_desc"];
}
?></font>
</p>
</td>
</tr>
<tr>
<td width="646" colspan="4">
<p><font size="2" face="Arial" color="#3300CC"><?php
if ( $row["url"]!="")
{
echo "<br><b>URL: </b>";
echo $row["burl"]," | ";
echo $row["Contact_us"];
}
?></font>
</p>
</td>
</tr>
<tr>
<td width="646" colspan="4">
<p><font size="2" face="Arial" color="#3300CC"> </font></p>
</td>
</tr>
<? } ?>
</table>
<?
//page numbering
$total_results = mysql_result(mysql_query
/*why i need to put count then follow by 'as Num' in this query.,, my friend said i should put there even it is not used, is that so ?? */
("SELECT COUNT(*) as Num FROM club1"),0);
$total_pages = ceil($total_results / $max_results);
echo "<center>Select a Page<br />";
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> ";
}
}
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>";
}
echo "</center>";
?>
|