Hi all
I am new to PHP and have got myself in a bit of a bind with the loop statement. At least I think so.
I am using an ms access database table and trying to create a small pagination system. The structure is below.
I believe the problem is here…
<?
// This is the Next and Previous code.
for ( $i = 1; $i <= $totalpage; $i++ ){
if ( $i == $pageid ){
echo "<b>" .$i. "</b> | ";
}
else{
echo '<a href = '.$PHP_SELF.' ?pageid= '.$i.' > <b> ' .$i.' </b> </a> | ';
}
}
?>
because I get nothing but a blank page except this when I load the page.
" .$i. " | "; } else{ echo ' ' .$i.' | '; } } ?> tag). while($row=odbc_fetch_assoc($result)){ ?>
I am a newbie with PHP and understand it a bit. If someone could check this and explain what is wrong and have an idea on how to correct it, it would be much appreciated.
It took me a fair amount of time to get this far and I would really like to have this solved.
Thanks
<body>
<?
// Connect database
odbc_connect('TVSERIES', 'root', '');
$pagesize=5; // Set number of records to view on a page.
// get a single column (id) from table.
$result=odbc_query("SELECT ID FROM stargatesg1;");
// Count the total of number of records and set it to $totalrecord.
$totalrecord=odbc_num_rows($result);
// How many pages will be created?
$totalpage=(int)($totalrecord/$pagesize);
if(($totalrecord%$pagesize)!=0){
$totalpage+=1;
}
If not, $pageid set to 1 and $start set at 0 (first record in table) /
if(isset($pageid)){
$start=$pagesize($pageid-1);
}
else{
$pageid=1;
$start=0;
}
// Select records from table with the limit statement and place them in $result.
$result=odbc_query("SELECT ID, series, season, episodeName FROM stagatesg1 ORDER BY season ASC limit $start, $pagesize;");
?>
<?
// This is the Next and Previous loop code.
for ( $i = 1; $i <= $totalpage; $i++ ){
if ( $i == $pageid ){
echo "<b>" .$i. "</b> | ";
}
else{
echo '<a href = '.$PHP_SELF.' ?pageid= '.$i.' > <b> ' .$i.' </b> </a> | ';
}
}
?>
<table border="1">
<tr>
<td>Series</td>
<td>Season</td>
<td>Episode</td>
</tr>
<?
// Show records made by the while loop on table rows.
while($row=odbc_fetch_assoc($result)){
?>
<tr>
<td><? echo $row['series']; ?></td>
<td><? echo $row['season']; ?></td>
<td><? echo $row['episodeName']; ?></td>
</tr>
<?
// End while loop.
}
// Close the connection.
odbc_close();
?>
</table>
</body>
</html>
</body>
</html>