how to show data from database only by one name

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kedora19
Forum Commoner
Posts: 34
Joined: Tue Apr 07, 2009 10:05 am

how to show data from database only by one name

Post 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
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Re: how to show data from database only by one name

Post 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 :)
kedora19
Forum Commoner
Posts: 34
Joined: Tue Apr 07, 2009 10:05 am

Re: how to show data from database only by one name

Post 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
 ?>
 
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Re: how to show data from database only by one name

Post 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 :)
kedora19
Forum Commoner
Posts: 34
Joined: Tue Apr 07, 2009 10:05 am

Re: how to show data from database only by one name

Post 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
Post Reply