Welshsteve
05-21-2009, 02:52 PM
Hi everyone,
I have the following SQL pulling data down from a MySQL database.
(SELECT * FROM Breaks_Prem)
UNION
(SELECT * FROM Breaks_A)
UNION
(SELECT * FROM Breaks_Comp)
ORDER BY Break DESC , Name , Club
I also have a pagination php script to split the displayed records on my website into manageable pages. However, for this particular SQL I'm not sure how to get the pagination script to work.
Basically, I need to count the number of records produced by the UNION statement. How do you do this? This is what I have tried but it doesn't work.
<?php
mysql_connect("SERVER","USER","PASSWORD");
mysql_select_db("DATABASE");
$perpage = 20;
$lynx = $html = "";
$startat = $_REQUEST[page] * $perpage;
$q = mysql_query("(SELECT COUNT(`Break`) FROM `Breaks_Prem`)
UNION
(SELECT COUNT(`Break`) FROM `Breaks_A`)
UNION
(SELECT COUNT(`Break`) FROM `Breaks_Comp`)");
$row = mysql_fetch_array($q);
$pages = ($row[0] + $perpage - 1) / $perpage;
$q = mysql_query("(SELECT * FROM Breaks_Prem)
UNION
(SELECT * FROM Breaks_A)
UNION
(SELECT * FROM Breaks_Comp)
ORDER BY Break DESC , Name , Club $startat,$perpage");
while ($row = mysql_fetch_assoc($q)) {
$text = strip_tags($row[entry_text]);
$text = substr($text,0,300);
$html .= "<tr><td> " . $row['Name'] . "</td><td> " . $row['Club'] . "</td><td>" . $row['Break'] . "</td><td>" . $row['Comp'] . "</td></tr>";
};
for ($k=0; $k<$pages; $k++) {
if ($k != $_REQUEST[page]) {
$lynx .= " <a href=$PHP_SELF"."?page=$k>".($k+1)."</a>";
} else {
$lynx .= " --".($k+1)."--";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Breaks List</title>
<link rel="stylesheet" type="text/css" href="css/css_main.css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1>Snooker - Breaks - Overall: Page <?= $_REQUEST[page]+1 ?></h1>
<p>Page: <?= $lynx ?></p>
<table>
<tr>
<th>Name</th>
<th>Club</th>
<th>Break</th>
<th>Competition</th>
</tr>
<?= $html ?>
</table>
<p>Page: <?= $lynx ?></p>
</body>
</html>
Is anybody able to help? The page in question is http://www.ldbsa.co.uk/s_breaks_o.php
I have the following SQL pulling data down from a MySQL database.
(SELECT * FROM Breaks_Prem)
UNION
(SELECT * FROM Breaks_A)
UNION
(SELECT * FROM Breaks_Comp)
ORDER BY Break DESC , Name , Club
I also have a pagination php script to split the displayed records on my website into manageable pages. However, for this particular SQL I'm not sure how to get the pagination script to work.
Basically, I need to count the number of records produced by the UNION statement. How do you do this? This is what I have tried but it doesn't work.
<?php
mysql_connect("SERVER","USER","PASSWORD");
mysql_select_db("DATABASE");
$perpage = 20;
$lynx = $html = "";
$startat = $_REQUEST[page] * $perpage;
$q = mysql_query("(SELECT COUNT(`Break`) FROM `Breaks_Prem`)
UNION
(SELECT COUNT(`Break`) FROM `Breaks_A`)
UNION
(SELECT COUNT(`Break`) FROM `Breaks_Comp`)");
$row = mysql_fetch_array($q);
$pages = ($row[0] + $perpage - 1) / $perpage;
$q = mysql_query("(SELECT * FROM Breaks_Prem)
UNION
(SELECT * FROM Breaks_A)
UNION
(SELECT * FROM Breaks_Comp)
ORDER BY Break DESC , Name , Club $startat,$perpage");
while ($row = mysql_fetch_assoc($q)) {
$text = strip_tags($row[entry_text]);
$text = substr($text,0,300);
$html .= "<tr><td> " . $row['Name'] . "</td><td> " . $row['Club'] . "</td><td>" . $row['Break'] . "</td><td>" . $row['Comp'] . "</td></tr>";
};
for ($k=0; $k<$pages; $k++) {
if ($k != $_REQUEST[page]) {
$lynx .= " <a href=$PHP_SELF"."?page=$k>".($k+1)."</a>";
} else {
$lynx .= " --".($k+1)."--";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Breaks List</title>
<link rel="stylesheet" type="text/css" href="css/css_main.css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1>Snooker - Breaks - Overall: Page <?= $_REQUEST[page]+1 ?></h1>
<p>Page: <?= $lynx ?></p>
<table>
<tr>
<th>Name</th>
<th>Club</th>
<th>Break</th>
<th>Competition</th>
</tr>
<?= $html ?>
</table>
<p>Page: <?= $lynx ?></p>
</body>
</html>
Is anybody able to help? The page in question is http://www.ldbsa.co.uk/s_breaks_o.php