Welcome to WebmasterWorld Guest from 54.161.147.106

Forum Moderators: open

pulling data from mysql db

   
7:44 pm on Mar 28, 2013 (gmt 0)



I'm trying to display data on a webpage that is relevant to that particular username. The only thing that would be completely unique for each row of data is the ID column.

Currently, I'm able to display the data from each row but it displays all of the rows due to a while loop.

while($rows=mysql_fetch_array($result)){
?>

Then the table code echos the $rows amd variables.

<?php
// close while loop
}
?>

How do I get this to only display data that is relevant for that particular username?
8:21 pm on Mar 28, 2013 (gmt 0)

WebmasterWorld Administrator brotherhood_of_lan is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



>completely unique for each row of data is the ID column.

You need to add a WHERE clause, assuming the ID column is called `id` the query would be

SELECT your,columns FROM tablename WHERE id = 1

This page [dev.mysql.com] from the manual is long and would take 30 minutes to ready but is a solid foundation to learn the basics of constructing a query.
8:35 pm on Mar 28, 2013 (gmt 0)



I will read the material on that page, thank you but what I'm trying to do is have the system recognize what the ID is based on the login of the user and based on the login of that user, it will pull the data from the db based on the ID since.
8:42 pm on Mar 28, 2013 (gmt 0)

WebmasterWorld Administrator brotherhood_of_lan is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Where is the id variable stored at the moment. In a cookie, or session?

If you already have the variable and verified the person is logged in, then use that variable in the query.

post the query and include some more info about what variables you have available to identify the user.
8:50 pm on Mar 28, 2013 (gmt 0)



<?php
session_start();
if(!session_is_registered(username)){
header("location:login.php");
}
?>

is a the top of every page. What do i add to display only that relevant usernames data
9:00 pm on Mar 28, 2013 (gmt 0)



the id data is stored in mysql db and increments for every registration
9:02 pm on Mar 28, 2013 (gmt 0)

WebmasterWorld Administrator brotherhood_of_lan is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



If you try print_r($_SESSION); you will see all the variables you have stored in the session.

..... assuming your variable is $_SESSION['id']

mysql_query('SELECT your,columns FROM tablename WHERE id = '.$_SESSION['id']);

PHP manual - sessions [php.net]
9:07 pm on Mar 28, 2013 (gmt 0)



i will check that out and try it, thanks....
 

Featured Threads

Hot Threads This Week

Hot Threads This Month