justuptime.com - monitor your servers & websites

Drop down menu's into MySQL

You are viewing this site as a guest. Join our community to get your questions answered and share knowledge. Active members may advertise and ask for a website critique.
sublimer's picture

They have: 41 posts

Joined: Aug 2006

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.

wwwDOTcom Solutions

Greg K's picture
Moderator

He has: 1,652 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

[This space intentionally left blank]

Cool Geek Supplies: www.ThinkGeek.com

brady.k's picture

He has: 1,383 posts

Joined: Feb 2002

Why not just have a simple if statement?

<?php
if (($whatevervalue != '') && ($whatevervalue != NULL)) {
 
// print
}
?>

Kyle Brady, President, Intuitive Industries LLC.
http://www.int-ind.com
[EMAIL=brady.k@gmail.com]brady.k@gmail.com[/EMAIL] - [EMAIL=brady.kyle@int-ind.com]brady.kyle@int-ind.com[/EMAIL]

sublimer's picture

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

wwwDOTcom Solutions

brady.k's picture

He has: 1,383 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.

Kyle Brady, President, Intuitive Industries LLC.
http://www.int-ind.com
[EMAIL=brady.k@gmail.com]brady.k@gmail.com[/EMAIL] - [EMAIL=brady.kyle@int-ind.com]brady.kyle@int-ind.com[/EMAIL]