Page 1 of 1

My search engine...

Posted: Sat Jun 10, 2006 3:24 pm
by JellyFish
Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Code: Select all

while ($row = mysql_fetch_array($result)) {

	//keywords handling
	if ($row['keywords'] != "") {
		$keywords = $row['keywords'];
	} else {
		$keywords = "";
	}

	$hit = 0;
	$_GET['search'] = trim($_GET['search']);

	$search = explode(" ", $_GET['search']);
	$keywords = explode(",", $keywords);

	$l = 0;
	$usrloop = 0;

	for ($l=0; $keywords[$l] != ""; $l++) {
		$keywords[$l] = trim($keywords[$l]);
		echo "<font color=red>".$keywords[$l]."</font>".",";
		for ($usrloop=0; $search[$usrloop] != ""; $usrloop++) {
			$search[$usrloop] = trim($search[$usrloop]);
			echo $search[$usrloop].",";
			if ((strtoupper($search[$usrloop]) == strtoupper($keywords[$l]))) {
				$hit++;
			}
		}

	}

	$display_block[$hit] .= "My objects information";
	echo $hit;

}
?>
<?
for ($length=count($display_block); $length > 1; $length-=1) {
	echo "<table width=100% border=0 cellspacing=0 cellpadding=0 align=center><tr><td>".$display_block[$length-1]."</td></tr></table>";
}
?>
<?
include ("jscontrol.php");
?>
This is my search engine. It's obvious I connect to my database before this to select the objects that contain keywords. Now for some reason when ever I type two keywords as my search and an object has those two, the object isn't displayed. I've been racking my brains all day trying to figure out why it doesn't work.

If you see anything wrong with the code, or know of a better way to code this, please spot it out for me, I'd very much appreciate it. :D

Thanks.


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sat Jun 10, 2006 5:11 pm
by JellyFish
Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Okay I figured it out. I'm using the $length which isn't the length of the array, for example:

Code: Select all

$display_block[0] = "whatever";
$display_block[2] = "what";
$display_block[4] = "ever";

$length = count($display_block);   //returns 3 since there are only three values in that array

while ($length > 1) {
echo $display_block[$length-1];    //read the comment below in quotes, I did this bc the long text makes the code weird
$length--;
comment:
in the first loop, $length should be 4 since 4 is the largest index of $display_block array, but no, it's 3 in the first loop because it just counts the values of this index where as if //index 3 of $display_block had a value $length would be 4
So, my conclusion is this. How can I get the length of an array? I need the actual index counting, for example I need $length to equal the largest index in $display_block array, in the example above, 4 is the largest index in $display_block array.

So if I'm not clear enough on what I need, please post questions on things you didn't understand. And again, I need $length to equal the largest index in $display_block.

Thanks and all help is appreciated.


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]