I am currently trying to create a ticketing system from scratch using PHP and MYSQL. I would like to have a drop down that allows you to assign tickets to a user based on the user list from MYSQL. Currently this is the code I have to populate the with options:
$sqlq1 = "SELECT fname, lname FROM ticket_users";
$query = mysql_query($sqlq1);
$array = mysql_fetch_array($query);
foreach($array as $row){
echo '<option value ='."$row[fname]".'>'.$row[fname].$row[lname].'</option>';
}
The issues I'm having are three fold:
- The code only prints from the first row of the SQL
- The code does not cycle equal to the number of user records
- When the code does print the information from the first row it's only printing the first characters from each field and is multiplying them.
The output looks like this:
<h3> Assign To: <select name="assignee">
<option value =J>JJ</option>
<option value =J>JJ</option>
<option value =F>FF</option>
<option value =F>FF</option>
</select></h3>
And this is what a print_r of the array looks like:
Array ( [0] => Jim [fname] => Jim [1] => Frail [lname] => Frail )
And Here's the var dump:
array(4) { [0]=> string(3) "Jim" ["fname"]=> string(3) "Jim" [1]=> string(5) "Frail" ["lname"]=> string(5) "Frail" }
I wasn't even sure how to search for a solution to this issue so hopefully my title will help some other people find the solution as well.
Thanks in advance for the help.
PS. After some looking in to it I have been able to determine that the J's all come from the first name of the first row and all the F's come from the last name of the first row. Hope this helps.