Jump to content

help with if statement


MDanz

Recommended Posts

can i store in an array, when results come from a loop?.. if so, how?

 

i know with the array i can use array_unique for duplicate values, so that solves that.  But i don't know how to implement an array into a loop.

 

<?php


mysql_connect("localhost", "Master", "pword");
mysql_select_db("db");

$letter = htmlentities($_GET['search']); 
$user = mysql_query("SELECT * FROM Stacks WHERE keywords LIKE '$letter%' ORDER BY keywords")or die (mysql_error());  


while($rowz = mysql_fetch_array($user)){
$keyword = $rowz['keywords'];
$name = $rowz['name'];                                         
$bad = mysql_query("SELECT * FROM Stacks WHERE keywords LIKE '$letter%' ORDER BY keywords")or die (mysql_error()); 
$num_rows = mysql_num_rows($bad)or die (mysql_error());  
}

if ($num_rows == 0)
{
echo "<font face='Courier New' font size=18px font color=#FF9900>$letter</font><br /><br />";
echo "<font face='Courier New' font size=3px font color=#FBB917>No Stacks</font><br>";
}
else {




echo "<font face='Courier New' font size=18px font color=#FF9900>$letter</font><br /><br />";
echo "<font face='Courier New' font size=3px font color=#FBB917><a href='stack.php?search=$keyword&submit=Go!' style='text-decoration: none';>$keyword</a></font><br>";
}
?>

Set this up before your while

$words_output = array();

 

then the else half of your loop looks like

else 
{
if(!in_array($keyword,$words_output))
{
	$words_output[] = $keyword;
	echo "<font face='Courier New' font size=18px font color=#FF9900>$letter</font><br /><br />";
	echo "<font face='Courier New' font size=3px font color=#FBB917><a href='stack.php?search=$keyword&submit=Go!' style='text-decoration: none';>$keyword</a></font><br>";
}
}

is there a way to remove the duplicate result from the loop if the same result is there already?.. what i'm getting is i want to display 10 results.  Say 3 of those results are duplicate.  Only 8 results are now displayed... the other two are "hidden"...

 

any way around this?

array_unique?

it's because of this line...

 

"SELECT * FROM Stacks ORDER BY id DESC LIMIT 9";

 

it hides duplicate values but it is still counted in the loop.  So if there is 20 results in mysql database.  the first 5 results are the same value.  then it will show 4 result...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.