homepage Welcome to WebmasterWorld Guest from 54.198.148.191
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
pulling data from mysql db
jp12




msg:4559325
 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?

 

brotherhood of LAN




msg:4559330
 8:21 pm on Mar 28, 2013 (gmt 0)

>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.

jp12




msg:4559335
 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.

brotherhood of LAN




msg:4559338
 8:42 pm on Mar 28, 2013 (gmt 0)

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.

jp12




msg:4559340
 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

jp12




msg:4559341
 9:00 pm on Mar 28, 2013 (gmt 0)

the id data is stored in mysql db and increments for every registration

brotherhood of LAN




msg:4559342
 9:02 pm on Mar 28, 2013 (gmt 0)

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]

jp12




msg:4559345
 9:07 pm on Mar 28, 2013 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved