Gatsu Posted November 13, 2007 Share Posted November 13, 2007 hi, I have a login site that wants to list something with the username.I use this $result = mysql_query("SELECT * FROM orders WHERE login='".$_SESSION['login']."' ORDER BY id DESC");while($row = mysql_fetch_array($result)) { echo "<table border='2' cellpadding='0'><tr>"; echo "<th>id</th>"; echo "<th>user</th>"; echo "<th>Order Status</th></tr>"; echo "<tr><td>" . $row['id'] . "</td>"; echo "<td>" . $row['login'] . "</td>"; echo "<td>" . $row['os'] . "</td></tr></table>"; } echo "I'm working on this atm... <br \>"; the '".$_SESSION['login']."' works when I am adding the username in the user row in the db but how do I use this to list the logged in user only? Link to comment Share on other sites More sharing options...
justsomeguy Posted November 13, 2007 Share Posted November 13, 2007 It looks like it already is. The WHERE clause in the statement says to get records only where the login field equals the value in the session. That should be doing the filtering. Link to comment Share on other sites More sharing options...
Gatsu Posted November 13, 2007 Author Share Posted November 13, 2007 its not working so maybe you can look at all code if its not too much to ask :$ <?phpsession_start();?><style type="text/css"><!--body,td,th { color: #FFFF00;}body { background-image: url(); background-color: #21474B;}--></style><?php$con = mysql_connect("localhost","********","******");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("******", $con);$result = mysql_query("SELECT * FROM orders WHERE login='".$_SESSION['login']."' ORDER BY id DESC");while($row = mysql_fetch_array($result)) { echo "<table border='2' cellpadding='0'><tr>"; echo "<th>id</th>"; echo "<th>user</th>"; echo "<th>Vocation</th>"; echo "<th>Current Level</th>"; echo "<th>Desired Level</th>"; echo "<th>World Type</th>"; echo "<th>Account Status</th>"; echo "<th>Skills</th>"; echo "<th>Mag lvl</th>"; echo "<th>Equipment</th>"; echo "<th>Leveler</th>"; echo "<th>Order Status</th></tr>"; echo "<tr><td>" . $row['id'] . "</td>"; echo "<td>" . $row['login'] . "</td>"; echo "<td>" . $row['vocation'] . "</td>"; echo "<td>" . $row['cl'] . "</td>"; echo "<td>" . $row['dl'] . "</td>"; echo "<td>" . $row['wt'] . "</td>"; echo "<td>" . $row['prem'] . "</td>"; echo "<td>" . $row['skills'] . "</td>"; echo "<td>" . $row['mag'] . "</td>"; echo "<td>" . $row['eq'] . "</td>"; echo "<td>" . $row['leveler'] . "</td>"; echo "<td>" . $row['os'] . "</td></tr></table>"; } echo "I'm working on this atm... <br \>";mysql_close($con);?> Link to comment Share on other sites More sharing options...
justsomeguy Posted November 13, 2007 Share Posted November 13, 2007 It looks fine, what are you seeing it do? You can print $_SESSION['login'] to check the value. Also, don't put HTML comments in CSS, that's an error. Link to comment Share on other sites More sharing options...
Gatsu Posted November 13, 2007 Author Share Posted November 13, 2007 I should see a table that shows me the rows for the username only but all I see is teh text "I'm working on this atm..."the "print $_SESSION['login']" gave me the right result, my username. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 13, 2007 Share Posted November 13, 2007 That means that there were no rows that matched the query. You can print out the query to see what you're asking the database, and check the database to see what's in there already. Link to comment Share on other sites More sharing options...
Gatsu Posted November 14, 2007 Author Share Posted November 14, 2007 thank you Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.