My page new_items.php displays all the contents from the ‘items’ table of my database, however I want to display solely the data where type equals 1 when the url is new_items.php?type=1
My current code :
[code=php]<?
require_once (‘../db2connect.php’);
// Number of records to show per page:
$display = 8;
$type = (isset($_GET[‘type’])) ? $_GET[‘type’] : “%”;
$genre = (isset($_GET[‘genre’])) ? $_GET[‘genre’] : “%”;
// Determine how many pages there are.
if (isset($_GET[‘np’])) { // Already been determined.
$num_pages = $_GET[‘np’];
} else { // Need to determine.
// Count the number of records
$query = “SELECT COUNT(i.id) FROM gitems as i ORDER BY i.id ASC”;
$result = mysql_query ($query);
$row = mysql_fetch_array ($result, MYSQL_NUM);
$num_records = $row[0];
// Calculate the number of pages.
if ($num_records > $display) { // More than 1 page.
$num_pages = ceil ($num_records/$display);
} else {
$num_pages = 1;
}
} // End of np IF.
// Determine where in the database to start returning results.
if (isset($_GET[‘s’])) {
$start = $_GET[‘s’];
} else {
$start = 0;
}
?>
<p class=”maintext”>We are constantly adding new items to our web site and here
is where you’ll find them first. <br />Please take a look around items adding in the
last month.</p>
<center>
<form name=”jump”>
<select name=”type” onChange=”location=document.jump.type.options[document.jump.type.selectedIndex].value;” value=”GO”>
<option value=”new_items.php”>Select…</option>
<?
require_once (‘../mysql_connect.php’); // Connect to the database
$query = “SELECT type, id FROM types ORDER BY id”;
$result = mysql_query ($query); // Run the Query
while ($row = mysql_fetch_array($result)) {
echo ‘<option value=”new_items.php?type=’ . $row[‘id’] . ‘”>’ . $row[‘type’] . ‘</option>’;
}
?>
</select>
</form>
</center>
<?
if (!isset($type) || empty($type)) {
$query2 = “SELECT i.id, i.name, i.types, i.descr, i.thumb, i.price, t.id, t.type, p.id, p.name FROM gitems as i, publishers as p, types as t WHERE i.publisher = p.id AND i.types = t.id ORDER BY i.id DESC LIMIT $start, $display”;
$result2 = mysql_query($query2) or die(mysql_error());
}
else
{
$query2 = “SELECT i.id, i.name, i.types, i.descr, i.thumb, i.price, t.id, t.type, p.id, p.name FROM gitems as i, publishers as p, types as t WHERE i.publisher = p.id AND i.types = t.id AND i.types = ‘$type’ ORDER BY i.id DESC LIMIT $start, $display”;
}
$result2 = mysql_query($query2) or die(mysql_error());
echo ‘<table width=”100%” border=”0″ class=”maintext” cellpadding=”2″>’;
while ($row2 = mysql_fetch_array($result2)) {
echo ‘<tr>
<td width=”250″ valign=”top”>Title : <b><a href=”item.php?id=’ . $row2[0] . ‘”>’ . $row2[1] . ‘</a></b>(‘ . $row2[7] . ‘)<br /><br />Description : ‘ .substr($row2[3],0,140). ‘…</td>
<td><a href=”item.php?id=’ . $row2[0] . ‘”><img src=”CrashBandicoot.jpg” width=”80″ height=”80″ border=”3″ style=”border-color:#cccccc” hspace=”5″></a></td>
</tr>
<tr>
<td width=”250″></td>
<td valign=”top”>Price : £’ . $row2[5] . ‘ GBP</td>
</tr>
<tr>
<td width=”250″><a href=”item.php?id=’ . $row2[0] . ‘”>Further Information</a></td>
<td><a href=”add_cart.php?item=’ . $row2[0] . ‘”><img src=”add_item.jpg” border=”0″ alt=”Add ‘ . $row2[1] . ‘ to your cart!” /></a></td>
</tr>
<tr>
<td colspan=”2″><hr size=1 color=#00CCFF /></td>
</tr>’;
}
echo ‘</table>’;
// Make the links to other pages, if necessary.
if ($num_pages > 1) {
echo ‘<br /><p class=”maintext”>’;
// Determine what page the script is on.
$current_page = ($start/$display) + 1;
// If it’s not the first page, make a Previous button.
if ($current_page != 1) {
echo ‘<a href=”new_items.php?s=’ . ($start – $display) . ‘&np=’ . $num_pages . ‘”>Previous</a> ‘;
}
// Make all the numbered pages.
for ($i = 1; $i <= $num_pages; $i++) {
if ($i != $current_page) {
echo ‘<a href=”new_items.php?s=’ . (($display * ($i – 1))) . ‘&np=’ . $num_pages . ‘”>’ . $i . ‘</a> ‘;
} else {
echo $i . ‘ ‘;
}
}
// If it’s not the last page, make a Next button.
if ($current_page != $num_pages) {
echo ‘<a href=”new_items.php?s=’ . ($start + $display) . ‘&np=’ . $num_pages . ‘”>Next</a>’;
}
echo ‘</p>’;
} // End of links section.
?>
Any ideas ?
Thankyou,,