Jump to content

Recommended Posts

Hi,

 

I was looking to add pagination to my site and I found a resource for it at

http://www.w3cgallery.com/w3c-blog/php-mysql-ajax-hacks-trick/ajax-fetch-records-by-phpmysql-with-pagination

 

however, I downloaded the source and eventhough I've changed the database connection, table fields it still comes up with an error

 

"Parse error: syntax error, unexpected T_ELSE on line 95",

 

I appreciate it if anyone could help! thanks!

 

 

 

 

<?php

$dbhost = 'localhost';
$dbuser = 'xxxxx';
$dbpass = 'xxxxx';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

$dbname = 'xxxxx';
mysql_select_db($dbname);
############# must create your db base connection

$strPage = $_REQUEST[Page];
if($_REQUEST[mode]=="Listing"){

$query = "SELECT * FROM user";
$result = mysql_query($query) or die(mysql_error());

$Num_Rows = mysql_num_rows ($result);

########### pagins

$Per_Page = 5;   // Records Per Page

$Page = $strPage;
if(!$strPage)
{
$Page=1;
}

$Prev_Page = $Page-1;
$Next_Page = $Page+1;


$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($Num_Rows<=$Per_Page)
{
$Num_Pages =1;
}
else if(($Num_Rows % $Per_Page)==0)
{
$Num_Pages =($Num_Rows/$Per_Page) ;
}
else
{
$Num_Pages =($Num_Rows/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}

$query.=" order  by Id ASC LIMIT $Page_Start , $Per_Page";
$result = mysql_query($query) or die(mysql_error());
?>
<table border="0">
<tbody>
<tr>
<td>Name</td>
<td>Email</td>
</tr>
<?php
// Insert a new row in the table for each person returned
if(mysql_num_rows($result) > 0 ) {
while($data= mysql_fetch_array($result)){ ?>
<tr>
<td><?php echo $data['Name'] ?></td>
<td><?php echo $data['Email'] ?></td>
</tr>
<div class="resultbg pagination">
<!--Total <?php //echo $Num_Rows;?> Record : -->
<?
}
if($Prev_Page) 
{
echo " <li><a href=\"JavaScript:SANAjax('Listing','$Prev_Page')\"> << Back</a> </li>";
}

for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
	echo " <li><a href=\"JavaScript:SANAjax('Listing','$i')\">$i</a> </li>";
}
else
{
	echo "<li class='currentpage'><b> $i </b></li>";
}
}
if($Page!=$Num_Pages)
{
echo " <li><a href=\"JavaScript:SANAjax('Listing','$Next_Page')\">Next >></a> </li>";
}
?>
</div>
<?php
############
}
else{
echo "<div class='error'>No Records Found!</div>";
}
} 

################ end

thanks for your reply and sorry forgot to add it closing ?>.... i had run it through an online check aswell and it didn't show any errors..i don't know, there was afew people on the source page i got it from having the same error without much success...

the only thing that i can think of that would make some php installations fail is the short tag, <? which should be <?php

 

<? // WRONG
}
if($Prev_Page) 

 

<?php // CORRECT
}
if($Prev_Page) 

 

... which tells me that my installation has short tags enabled. going to turn that off right now.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.