What is the column name in the database for the user name in that table? That will be your array key (case-sensitive).
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Unless there is some syntax error I'm not seeing, the code you posted originally looks OK to me. The only problem I could see was if "username" was not the correct column name. If it is, then you code ought to work OK, I think. You could do a quick check by changing it to this just for debugging:
PHP Code:
<?php
$user_result = mysql_query("SELECT * FROM users ORDER BY username", $db);
while($user_row = mysql_fetch_array($user_result))
{
// delete or comment out after done debuggin:
echo "<pre>".print_r($user_row, true)."</pre>";
exit;
// end debug code
?>
<!-- rest of code -->
That will show you exactly what data was retrieved by your query and what the array keys are.
PS: Just a little "style" note: if you are only going to reference the row results by column name, I'd suggest using mysql_fetch_assoc() instead of mysql_fetch_array(), as the latter stores each column twice: once with the column name key and once with a numeric index in the array.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
<?php
$user_result = mysql_query("SELECT * FROM users ORDER BY username", $db);
while($user_row = mysql_fetch_array($user_result))
{
// delete or comment out after done debuggin:
echo "<pre>".print_r($user_row, true)."</pre>";
exit;
// end debug code
?>
<!-- rest of code -->
That will show you exactly what data was retrieved by your query and what the array keys are.
Oh forgot when I did that it hid/erased the usernames in the list fyi.
I tried the user_rows just still not implementing it correctly I guess
It seems that you must not know the correct names of the columns in your table. Apparently `username` is not one of the column names, maybe it is user_name, or usernames or last_name, first_name which could be combined in mysql with something like;
PHP Code:
$query = "SELECT CONCAT(first_name, " ", last_name) AS username FROM users ORDER BY username ASC";
If I am having a query problem I often sort out the problem using phpMyAdmin and doing queries there before committing them to php code.
Thanks Dasher yeah I'll look into that but how was this define then?
Code:
<select>
<?php
$user_result = mysql_query("SELECT * FROM users ORDER BY username", $db);
while($user_row = mysql_fetch_array($user_result))
{
?>
<option value="<?php echo $user_row['user_id']; ?>"><?php echo $user_row['username']; ?></option>.......
It shows the username there as a select box...I can select the user and then get the results....RESULTS is where i want a column with the USERNAME there...so I added another column in the result where it showed from what user it was made from which it does work:
I just need this to be username. Obviously it doesn't make sense if i looked it under the username, but it will make sense if i do a report base on the 'date' and so on....
I need to define the $user_row for the report_row..
Bookmarks