Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 376
  • Last Modified:

PHP While Loop drop down menu problem

I have this problem with a while loop that keeps returning the first initial of someone's name when it runs. I want the full name. The loop is designed to create a drop down list that works fine, except for this stupid inconsistency. I checked the database, and the full name is definitely there. The last name comes out fine, so I dont know where the problem is. Here is the code:

$resulttwo=mysql_query("SELECT * FROM employees WHERE empnum>=1 ORDER BY firstname ASC") or die(mysql_error());

$displayth ='<select name="th" id="th">';


while ($rowtwo=mysql_fetch_array($resulttwo))
$displayth .='<option value="' . $empid[$p] . '">' . $firstname[$p] . " " . $lastname[$p] . '</option>';
$displayth .= '</font><font size="2" face="Eras Demi ITC">';

$displayth .='</select>';

echo $displayth;
  • 2
1 Solution
I see nothing wrong with your code. I realize you've checked your database, but it would probably be a good idea to check your output as well. Instead of using $firstname[$p] for your option text, try using $rowtwo['firstname']. Find out what's actually being pulled from the database. Also, since you're calling the variables as associative arrays, it might be a good idea to change "mysql_fetch_array" to "mysql_fetch_assoc".


This probably won't fix your error, but it might improve your performance slightly.
jcbodyworksAuthor Commented:
I just looked through the entire code of my site, turns out I have another variable like this:


this was causing the problem. I changed the variable, so now everything works like a charm! Thank you!
Hey, good job! Thanks for the points, and good luck.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now