Jump to content


Search results showing more then one?


2 replies to this topic

#1 tiki

    Young Padawan

  • Members
  • Pip
  • 259 posts
  • Gender:Male
  • Location:California

Posted 23 January 2006 - 08:58 PM

They only show one, im positive why but how else can I write this so they show the rest of the results?

///////////////////////////////////////////////////////////////////////////////
//  Search
///////////////////////////////////////////////////////////////////////////////
	break;
	case "search": 
	
// Set variables and check if submitted
if(isset($_POST["submit"])) {
	$search = htmlspecialchars(addslashes($_POST["search"]), ENT_QUOTES);
	
	if(!$search) {
		$errormsg = "No keywords entered, please go back and fill in the fields properly. <br />";
	} else {
		$query = db_query("SELECT * FROM store_product WHERE description LIKE '%$search%'");
		$rows = db_num_rows($query);
		
		if($rows > 0) { 
		
			// Starts spitting out the data
			while($search = db_fetch_object($query)) {
			$description  = htmlspecialchars($search->description); 
			if ($search->type == "bag") {
				$quantity = $search->quantity_0;
			} elseif ($search->type == "shirt") {
				$quantity = $search->quantity_1 + $search->quantity_2 + $search->quantity_3; }
				
			$results = "
			<div class=\"entry\">
				<div class=\"itemLeft\">
					<a href=\"store.php?page=product&amp;id=$search->id\">
					<img src=\"$search->image_small\" alt=\"$search->name\" width=\"70\" height=\"70\" />
					</a>
				</div>
				
				<div class=\"itemRight\">
					<p><a href=\"store.php?page=product&amp;id=$search->id\">$search->name</a></p>
					<p>$description</p>
					<p>Price: <b>\$$search->price</b></p>
					<p>Quantity: <b>$quantity</b></p>
				</div>
				<br class=\"clear\" />
			</div>";

			}
		} else {
			$errormsg = "There were no matches to your search. Please try again.";
		}
	}
}
?>

			<!-- Search -->
			<h1>Search</h1>
				
			<? // Error Messages
			if (!empty($errormsg)) { ?>
				<div class="error">
					<b>Error</b><br />
					<? echo "$errormsg"; ?>
				</div>
			<? } ?>

			<form action="store.php?page=search" method="post" id="form">
			<fieldset>
				<legend><img src="/images/help-popup.gif" alt="" /> Search Store</legend>
				
					<div class="blue">Keywords:</div>
					<label for="search">
						<input type="text" name="search" id="search" size="20" />
						<? err2($errors->search)?> 
					</label>
					
					<p>Please enter any keywords you would like to search within the store and then press search. Its as easy as that.</p>
					
					<input type="hidden" value="TRUE" name="submit" id="submit" />
					<p class="button"><input type="image" src="/images/button-search.gif" alt="Search" /></p>
					
			</fieldset>
			</form>
			
			<? // Results
			if (!empty($results)) { ?>
				<h2>Results</h2>
					
				<? echo "$results"; ?>
			<? } ?>
			<!-- // Search -->


#2 liveman

    Young Padawan

  • Members
  • Pip
  • 246 posts
  • Location:New Jersey

Posted 23 January 2006 - 10:50 PM

while($r = mysql_fetch_array())

http://us2.php.net/m...fetch-array.php

#3 tiki

    Young Padawan

  • Members
  • Pip
  • 259 posts
  • Gender:Male
  • Location:California

Posted 24 January 2006 - 01:33 AM

It didnt work, I just put the whole php underneath the search :D





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users