Page 1 of 1
how to show data from database only by one name
Posted: Thu May 07, 2009 10:05 pm
by kedora19
well i have my database and the messages. my question is how could i only show the messages from a certain username.
thanks in advance, Kedora19
Re: how to show data from database only by one name
Posted: Thu May 07, 2009 10:17 pm
by mickd
You'll need to query your database and retrieve all the information from the table with that specific username. For example,
SELECT * FROM table WHERE username=$username
Run through the results using
mysql_fetch_assoc, or one of the ones similar to it. Then print the messages out.
If you're still stuck, or have any questions, post some code and I'm sure someone will be glad to help you more

Re: how to show data from database only by one name
Posted: Thu May 07, 2009 10:28 pm
by kedora19
mickd wrote:You'll need to query your database and retrieve all the information from the table with that specific username. For example,
SELECT * FROM table WHERE username=$username
Run through the results using
mysql_fetch_assoc, or one of the ones similar to it. Then print the messages out.
If you're still stuck, or have any questions, post some code and I'm sure someone will be glad to help you more

this is the code that i'm using but it's not workin
Code: Select all
<?php
include '../login/dbc.php';
//first open connection to your database
mysql_query("SELECT * FROM userstatus WHERE username=$_SESSION[user]");
while ($row=mysql_fetch_array($takeuser)) { //Taking the result set
echo 'Message: ' . $row['user'] . '</a><br /><br />';
} //closing the loop
mysql_close($link); //and then we close connection
?>
Re: how to show data from database only by one name
Posted: Thu May 07, 2009 10:44 pm
by mickd
mysql_fetch_array is given $takeuser, but you haven't assigned $takeuser as the mysql_query from above.
Also if that doesn't work, try changing the query to:
"SELECT * FROM userstatus WHERE username='{$_SESSION['user']}'"
P.S. Make sure session_start() is called aswell (and of course, $_SESSION['user'] was previously assigned).
If it still doesn't work, post back

Re: how to show data from database only by one name
Posted: Fri May 08, 2009 9:39 am
by kedora19
mickd wrote:mysql_fetch_array is given $takeuser, but you haven't assigned $takeuser as the mysql_query from above.
Also if that doesn't work, try changing the query to:
"SELECT * FROM userstatus WHERE username='{$_SESSION['user']}'"
P.S. Make sure session_start() is called aswell (and of course, $_SESSION['user'] was previously assigned).
If it still doesn't work, post back

SWEET it works, all i forgot was putting in the "$takeuser =" now it works
Thanks, Kedora19