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

x
  • 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">';

$p=0;

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


$p++;
}
$displayth .='</select>';

echo $displayth;
0
jcbodyworks
Asked:
jcbodyworks
  • 2
1 Solution
 
MasonWolfCommented:
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".

http://us.php.net/manual/en/function.mysql-fetch-assoc.php

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

$firstname=$_SESSION['firstname'];

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

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