Drop down menu's into MySQL
I have a drop down menu populated by items in a MySQL database. If the item has a space in it, it won't publish the information after the space to the database. Help?
Here is my code...
This populates the drop down menu...
<?php
//Connect to the database
include "manage/config.php";
mysql_connect("$server", "$username", "$password") or die;
mysql_select_db("$database") or die;
$result = mysql_query("SELECT * FROM Course ORDER BY Course_Value");
$options = "";
while ($row = mysql_fetch_array($result))
{
$Course_ID = $row["Course_ID"];
$Course_Value = $row["Course_Value"];
$options .= "<option value=" . $Course_Value . ">" . $Course_Value . "</option>";
}
?>
This displays the menu...
<?=$options?>
'
Thanks. The code is on an intranet so I can't link you guys to it, sorry.
Greg K posted this at 16:38 — 18th August 2007.
He has: 2,145 posts
Joined: Nov 2003
I'm a bit confused as to what is actually not working. (I just woke up, so I may be misreading this.. LOL)
Are you saying that if you hit a record with a space in the Course_Value field, then it won't show any more records after that, or just whatever comes after the space for that entry? Or do you mean a completely blank field?
Can you possibly post a sample of the source code generated by the script, showing how it is formatting the output?
-Greg
kb posted this at 21:15 — 18th August 2007.
He has: 1,380 posts
Joined: Feb 2002
Why not just have a simple if statement?
<?php
if (($whatevervalue != '') && ($whatevervalue != NULL)) {
// print
}
?>
sublimer posted this at 04:58 — 19th August 2007.
They have: 41 posts
Joined: Aug 2006
Okay. Lets say you have a drop down menu. It stores class names in it. So let's say it contains these classes...
Geometry
Honors Geometry
AP Calculus BC
Algebra 2
Trigonometry
If I select Geometry or Trigonometry from the list and click submit, there is not problems because they are one word, no spaces. However, if I select, Honors Geometry, AP Calculus BC or Algebra 2, then it only partially works. If I look in the database it would only say Honors, AP and Algebra respectively. The HTML that is generated is correct.
However, I forgot to put quotes around the values. So it was instead of the correct and working
kb posted this at 05:49 — 19th August 2007.
He has: 1,380 posts
Joined: Feb 2002
And it still doesn't work with the quotes?
Why not encode the space then as an HTML character? It's either %20 lr %40 if I'm not mistaken.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.