我知道mysql_num_rows用于获取行计数,但我在这里使用它并且当有更多结果显示时它会一直显示10。我究竟做错了什么?
代码:
//check if the starting row variable was passed in the URL or not
if (!isset($_GET['pg']) or !is_numeric($_GET['pg'])) {
//we give the value of the starting row to 0 because nothing was found in URL
$startrow = 0;
//otherwise we take the value from the URL
} else {
$startrow = (int)mysql_real_escape_string($_GET['pg']);
}
//Unseen
$variis = "Need Help";
$myid = "This is the user's id;"
$sql = "select car_help.car_id, agent_names.agent_name, help_box.status,
car_help.why_car, car_help.date_time_added, car_help.just_date,
car_help.type, agent_names.agent_id
from car_help LEFT JOIN agent_names on car_help.agent_whois = agent_names.agent_id
where agent_names.system_id = '$myid' and car_help.system_id='$myid'
and added_by <> '$myid' and help_box.status = '$variis'
UNION
select magazine_help.note_id, agent_names.agent_name, help_box.status,
magazine_help.note_name, magazine_help.date_time_added,
magazine_help.just_date, magazine_help.type, agent_names.agent_id
from magazine_help LEFT JOIN agent_names on
magazine_help.agent_id = agent_names.agent_id
where agent_names.system_id='$myid' and
magazine_help.system_id = '$myid' and added_by <> '$myid'
and help_box.status = '$variis'
UNION
select motorcycle_help.rand_id, agent_names.agent_name,
help_box.status, motorcycle_help.rand_name, motorcycle_help.date_time_added,
motorcycle_help.just_date, motorcycle_help.type, agent_names.agent_id
from motorcycle_help LEFT JOIN agent_names ON
motorcycle_help.by_who = agent_names.agent_id
where agent_names.system_id = '$myid' and
motorcycle_help.system_id='$myid' and added_by <> '$myid'
and help_box.status = '$variis'
UNION
select mobile_questions.bal_test_id, agent_names.agent_name,
help_box.status, mobile_questions.bal_why, mobile_questions.date_time_added,
mobile_questions.just_date, mobile_questions.type, agent_names.agent_id
from mobile_questions LEFT JOIN agent_names ON
mobile_questions.agent_who_ordered = agent_names.agent_id
where agent_names.system_id = '$myid' and
mobile_questions.system_id='$myid' and added_by <> '$myid'
and help_box.status = '$variis'
ORDER BY date_time_added DESC LIMIT $startrow, 10";
$result = mysql_query($sql);
$query = mysql_query($sql) or die ("Error: ".mysql_error());
if ($result == "")
{
echo "";
}
echo "";
$rows = mysql_num_rows($result);
if($rows == 0)
{
print("");
}
elseif($rows > 0)
{
while($row = mysql_fetch_array($query))
{
$row1 = $row['row_name'];
print("$row1");
}
}
if($rows > 10) {
echo '<a id=pgnvg href="'.$_SERVER['PHP_SELF'].'?pg='.($startrow+10).'&q='.($q).'">
Next</a>';
}
$prev = $startrow - 10;
//only print a "Previous" link if a "Next" was clicked
if ($prev >= 0) {
echo '<a id=pgnvg2 href="'.$_SERVER['PHP_SELF'].'?pg='.$prev.'&q='.($q).'">
Previous</a>';
}