I have the following script to display some Keyword results:
<?php
// Get the search variable from URL
$var = @$_GET['q'] ;
$trimmed = trim($var);
$limit=10;
if ($trimmed == "")
{
echo "<p>Please enter a search...</p>";
exit;
}
if (!isset($var))
{
echo "<p>We dont seem to have a search parameter!</p>";
exit;
}
mysql_connect("localhost","xxxxxx","xxxxxx");
mysql_select_db("xxxxxx") or die("Unable to select database"); //select which database we're using
$query = "select * from store_items where item_title like \"%$trimmed%\"
order by item_title";
$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
if (empty($s)) {
$s=0;
}
$query .= " limit $s,$limit";
$result = mysql_query($query) or die("Couldn't execute query");
echo "<p>You searched for: "" . $var . ""</p>";
echo "Results";
$count = 1 + $s ;
while ($row= mysql_fetch_array($result)) {
$title = $row["item_title"];
echo "$count.) $title" ;
$count++ ;
}
$currPage = (($s/$limit) + 1);
echo "<br />";
if ($s>=1) {
$prevs=($s-$limit);
print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><<
Prev 10</a>  ";
}
$pages=intval($numrows/$limit);
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {
$news=$s+$limit;
echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>";
}
$a = $s + ($limit) ;
if ($a > $numrows) { $a = $numrows ; }
$b = $s + 1 ;
echo "<p>Showing results $b to $a of $numrows</p>";
?>
I would like to display the results in the same manner that
the items are displayed on the page below:
$display_block = "<h1><font color=#808080 face=Arial, Helvetica, sans-serif>PPS Healthcare-Product Categories</h1>
<P>Select a category to see items available in that category.</p>";
//show categories first
$get_cats = "select id, cat_title, cat_desc from
store_categories order by cat_title";
$get_cats_res = mysql_query($get_cats) or die(mysql_error());
if (mysql_num_rows($get_cats_res) < 1) {
$display_block = "<P><em><font color=#808080 face=Arial,
Helvetica, sans-serif>Sorry, no categories to browse.</em></p>";
} else {
while ($cats = mysql_fetch_array($get_cats_res)) {
$cat_id = $cats[id];
$cat_title = strtoupper(stripslashes($cats[cat_title]));
$cat_desc = stripslashes($cats[cat_desc]);
$display_block .= "<p><strong><a
href=\"$_SERVER[PHP_SELF]?cat_id=$cat_id\">$cat_title</a></strong>
<br>$cat_desc</p>";
if ($_GET[cat_id] == $cat_id) {
//get items
$get_items = "select id, item_title, item_price
from store_items where cat_id = $cat_id
order by item_title";
$get_items_res = mysql_query($get_items) or die(mysql_error());
if (mysql_num_rows($get_items_res) < 1) {
$display_block = "<P><em><strong>Sorry, no items in
this category.</strong></em></p>";
} else {
$display_block .= "<ul>";
while ($items = mysql_fetch_array($get_items_res)) {
$item_id = $items[id];
$item_title = stripslashes($items[item_title]);
$item_price = $items[item_price];
$display_block .= "<li><a
href=\"showitem.php?item_id=$item_id\">$item_title</a>
</strong> (\$$item_price)";
}
$display_block .= "</ul>";
Does anyone know what I would change in the first script, to
display the items in the same fashion in the second script?
PLEASE PLEASE help me!
Thanks so much!
Allie