Forum Moderators: coopster

Message Too Old, No Replies

Pagination Help

         

steves

2:43 pm on May 29, 2007 (gmt 0)

10+ Year Member



I have read tutorials online and even posts here, problem is a lot of it is all new to me and I am at the point now where its beyond frustration. I have removed the sql login information and the domain name since the site is no where near completion. Any help is greatly appreciated. Here is my current code, but I just get an error message

Parse error: syntax error, unexpected $end in /home/ncfinder/public_html/florida/display.php on line 163

Which line 163 is the very last line of my page. </html>

<?php
$search = @$_GET['search'];
mysql_connect("localhost","username","password");
mysql_select_db("dbname") or die("Unable to select database");

if($search)
{
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}

// Define the number of results per page
$max_results = 25;

// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);

$query = "SELECT * FROM job_listings WHERE city LIKE '%$search%' and showad='y' ORDER by date DESC LIMIT $from, $max_results";
$result = mysql_query($query) or die(mysql_error());

mysql_close();
while ($row = mysql_fetch_array($result))
{
echo "
<table cellspacing=0 cellpadding=0>
<tr>
<td width=320 bgcolor=#dde8ec>
<div class=results>
<b><a href=http://www.websitename.com/florida/ad.php?ad=".$row["ad"].">".$row["job_title"]."</a></b>
</div>
</td>
<td width=5 bgcolor=#dde8ec></td>
<td width=200 bgcolor=#dde8ec>
<div class=results>
".$row["company_name"]."
</div>
</td>
<td width=100 bgcolor=#dde8ec>
<div class=results>
".$row["date"]."
</div>
</td>
</tr>
</table>
";}

// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM job_listings WHERE city LIKE '%$search%'"),0);

// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
echo "<center>$total_results Total results<br />";

// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo "<a href=\"".$_SERVER['php_SELF']."?page=$prev&search=$search\">Previous</a>&nbsp;";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "[$i]&nbsp;";
}
else {
echo "<a href=\"".$_SERVER['php_SELF']."?page=$i&search=$search\">$i</a>&nbsp;";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=\"".$_SERVER['php_SELF']."?page=$next&search=$search\">Next</a>";
}
?>

henry0

2:55 pm on May 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



At very first glance
you are not ending the first {

Make the last lines:
echo "<a href=\"".$_SERVER['php_SELF']."?page=$next&search=$search\">Next</a>";
}
}// ends first {
?>

You need a good editor that allows for PHP higlighting
it will help you among many functions to figure
ends and beginnings of { } ( ) etc...

steves

3:05 pm on May 29, 2007 (gmt 0)

10+ Year Member



With that change it now displays 25 results on the page, however it now gives me this error after the results.

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/ncfinder/public_html/florida/display.php on line 103

and line 103 is

$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM job_listings WHERE city LIKE '%$search%'"),0);

henry0

3:12 pm on May 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I guess $search is not passing any value
when you are in test mode remove @
$search = $_GET['search'];
and echo its value
$search = $_GET['search']; echo"SEARCH: $search<p>";

BTW
Welcome to WebmasterWorld! :)

steves

3:21 pm on May 29, 2007 (gmt 0)

10+ Year Member



Ok I removed

mysql_close();

and everything now works just fine. So all my frustrations have been between that and me missing the } ... what a morning I tell you. Thank you for the welcome, Ive read the forums on and off for the past year or so, this time I had to ask for help. Thanks again for your assistance.

henry0

3:23 pm on May 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're welcome!
Glad it worked OK, let us know if you have more troubles.
I did not see the close() killing the job at hand