Jump to content

Drop down menu MYSQL

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
bajerocks

bajerocks

    Newbie

  • Members
  • Pip
  • 5 posts
I am having a bit of a problem with PHP and mysql.
What I am trying to do is, I want to make a drop down selection for the users to be able to selcet the choices from it, however, these options in the drop down box are retrieved from a mysql table. But now I want to display the table using the selection of the users. Sorry for my "engrish". Her is are the code snippets:

This one is for the drop down box:
$sql="SELECT id, thing FROM table";
$result=mysql_query($sql);

$options="";

while ($row=mysql_fetch_array($result)) {
	$id=$row["id"];
    $thing=$row["thing"];
    $options.="<OPTION VALUE=\"$id\">".$thing;
}
?> 
<form method="post" action="display.php">
<select>
<option VALUE=0>Choose
<?=$options?>
</select><input type="Submit" name="Submit" value="Submit"></form>


Please note that i have already made the connection to database and everything.

This next one is for the display:

<?php
mysql_connect("****","****","****"); 

mysql_select_db("****"); 

$search=$_POST["$thing"];
$count = 0;

$result = mysql_query("SELECT * FROM table WHERE thing LIKE '%$search%'");

echo "<table border=1>";
echo "<tr>";
   		echo "<td>col1</td>";
   		echo "<td>col2</td>";
   		echo "<td>col3</td>";
   		echo "<td>col4</td>";
   		echo "</tr>";


while($r = mysql_fetch_array($result))
{	
 
  
   $col1=$r["col1"];
   $col2=$r["col2"];
   $col3=$r["col3"];

   $col4=$r["col4"];
   
	if(($col4 = "y") || ($col4 = "Y"))        //This is just a part where I check against the value
	{
   		echo "<tr>";
   		echo "<td>$col1</td>";
   		echo "<td>$col2</td>";
   		echo "<td>$col3</td>";
   		echo "<td>$col4</td>";
      		echo "</tr>";
	}
	else{
		echo "<tr>";
   		echo "<td bgcolor='#ffff00'>$col1</td>";
   		echo "<td bgcolor='#ffff00'>$col2</td>";
   		echo "<td bgcolor='#ffff00'>$col3</td>";
   		echo "<td bgcolor='#ffff00'>$col4</td>";
   	
   		echo "</tr>";
	}
   
   $count = $count + 1;
   
   
}
echo "</table><br />";


echo "only found $count number of datas";
?>


Ok, there are two things going on in the second code snippet.
first thing is I am trying to check a value and display the table or rows with color if it comes out true. second thing is, I am trying to display the results using the selection that the user made earlier.
Please help, where I am doin wrong?
Neither it is showing the color after the check, not is it showing the values using the user selection.

#2
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
You assign $col4 to the value "Y" instead of compare to it. add an equal sign extra into your if statements both places and it will work better.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall