ddonog115 Posted February 8, 2011 Share Posted February 8, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/227058-parse-error-syntax-error-unexpected-t_else/ Share on other sites More sharing options...
BlueSkyIS Posted February 8, 2011 Share Posted February 8, 2011 parses without error for me, after i add a closing ?> at the end of the posted code. Quote Link to comment https://forums.phpfreaks.com/topic/227058-parse-error-syntax-error-unexpected-t_else/#findComment-1171427 Share on other sites More sharing options...
ddonog115 Posted February 8, 2011 Author Share Posted February 8, 2011 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... Quote Link to comment https://forums.phpfreaks.com/topic/227058-parse-error-syntax-error-unexpected-t_else/#findComment-1171439 Share on other sites More sharing options...
Maq Posted February 8, 2011 Share Posted February 8, 2011 In the future, please use tags around your code. Quote Link to comment https://forums.phpfreaks.com/topic/227058-parse-error-syntax-error-unexpected-t_else/#findComment-1171443 Share on other sites More sharing options...
BlueSkyIS Posted February 8, 2011 Share Posted February 8, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/227058-parse-error-syntax-error-unexpected-t_else/#findComment-1171446 Share on other sites More sharing options...
BlueSkyIS Posted February 8, 2011 Share Posted February 8, 2011 I verify: With short tags turned off, I get the same parse error. updating <? to <?php fixes it for me. Quote Link to comment https://forums.phpfreaks.com/topic/227058-parse-error-syntax-error-unexpected-t_else/#findComment-1171449 Share on other sites More sharing options...
ddonog115 Posted February 8, 2011 Author Share Posted February 8, 2011 i tried it there and it worked, thanks for all the help! and i'll wrap my code in tags next time! Quote Link to comment https://forums.phpfreaks.com/topic/227058-parse-error-syntax-error-unexpected-t_else/#findComment-1171458 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.