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
how to show data from database only by one name
Moderator: General Moderators
Re: how to show data from database only by one name
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
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
this is the code that i'm using but it's not workinmickd 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
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
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
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
SWEET it works, all i forgot was putting in the "$takeuser =" now it worksmickd 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
Thanks, Kedora19