Hi i'm trying to split the pages by section insted of by $no_of_records = 5;
The sections are taken from the foriegn key. I want to be able to count the number of records which hold a specific forigen key and display on one page and then the next.
Thanks
Ross
<?php
require("c:\Inetpub\wwwroo
t\mysql_co
nnect.php"
);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
if (isset ($_GET['page']))
{
$page = $_GET['page'];
}
else
{
$page = 1;
}
//count sections
$records_to_display = 5;
$sql_paging = "SELECT COUNT(*) AS numRecords FROM question";
$newArray = mysql_query($sql_paging, $db) or die(mysql_error());
$records = mysql_fetch_array($newArra
y);
$recordsNum = $records['numRecords'];
$remainder = $recordsNum%$records_to_di
splay;
$recordsNum = $recordsNum - $remainder;
$pages = $recordsNum/$records_to_di
splay;
if ($remainder>0)
{
$pages++;
}
if ($page>$pages)
{
$page = 1;
}
$query = 'SELECT question_type.question_typ
e, question_group.question_gr
oup, question_id, question, question_order FROM question
LEFT JOIN question_group ON question.ID_question_group
= question_group.question_gr
oup_id
LEFT JOIN question_type ON question.ID_question_type = question_type.question_typ
e_id
ORDER BY question_group_order ASC, question_order ASC';
function newGroup($myresource)
{
print "<h1>".$myresource->questi
on_group."
</h1>";
}
$previous_group = -1;
$my_query_result = mysql_query ($query, $db);
if ($page>1)
{
for ($i=1; $i<$page; $i++)
{
for($j=0; $j<$records_to_display; $j++)
{
$myresource = mysql_fetch_object($my_que
ry_result)
;
}
}
}
$no = 0;
?>
</head>
<body>
<?php
while ($myresource = mysql_fetch_object($my_que
ry_result)
)
{
if ($myresource->question_gro
up != $previous_group)
{
newGroup($myresource);
$previous_group = $myresource->question_grou
p;
}
print $myresource->question_orde
r.", ";
print $myresource->question."<br
/>";
$no++;
if ($no==$records_to_display)
{
break;
}
}
mysql_close($db);
?>
<?php
if ($page<2)
{
print("<p><<");
}
else
{
print("<p><a href='".$_SERVER['PHP_SELF
']."?page=
".($page-1
)."'><&
lt;</a>");
}
for ($i=1; $i<=$pages; $i++)
{
if ($i==$page)
{
print (" <a href='".$_SERVER['PHP_SELF
']."?page=
".($i)."'>
<b>".$i."<
/b></a>");
}
else
{
print (" <a href='".$_SERVER['PHP_SELF
']."?page=
".($i)."'>
".$i."</a>
");
}
}
if ($page>=$pages)
{
print " >><p>";
}
else
{
print" <a href='".$_SERVER['PHP_SELF
']."?page=
".($page+1
)."'>>&
gt;</a><p>
";
}
?>
</body>
</html>