fbm Posted March 3, 2009 Share Posted March 3, 2009 Hi, I have 2 tables in my DB [clients] [invoices] Clients table has an ID field set to primary key so each client has a unique ID. On invoice table i pass the unique ID by selecting the client from a drop down list when creating the invoice. The ID is added to the DB correclty. I'm now trying to pull out data which is relevent to the ID stored in the session. Clients login ID is added to session. At the moment my code just pulls out all teh invoices listed and not ID specific rows My code is <?php session_start();?> <?php include "includes/header.php"; ?> <div id="page_content"> <div id="sub_menu"></div> <div id="content"> <h1>Clients Invoices</h1> <div id="client_list_table"> <table width="860" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="id">ID</td> <td class="company">Company</td> <td class="contact">Contact Name</td> <td class="email">Email</td> <td class="phone">Phone</td> <td class="actions">Actions</td> </tr> <?php $result = mysql_query("SELECT * FROM invoices ORDER BY id ASC"); while($row = mysql_fetch_array($result)) { echo "<tr>\n"; echo "<td class='row_id'>".$row['id']."</td>\n"; echo "<td class='row'>".$row['date']."</td>\n"; echo "<td class='row'>".$row['invoice_number']."</td>\n"; echo "<td class='row'>".$row['title']."</td>\n"; echo "<td class='row'>".$row['value']."</td>\n"; echo "<td class='row'>".$row['pdf']."</td>\n"; echo "<td class='row'>".$row['status']."</td>\n"; echo "</tr>\n"; } ?> </table> </div> </div> </div> <?php include "includes/footer.php"; ?> Any ideas? Quote Link to comment Share on other sites More sharing options...
fbm Posted March 3, 2009 Author Share Posted March 3, 2009 solved i was selecting my clients table on the invoice list rather than my invoice table changed $result to $result = mysql_query("SELECT * FROM invoices WHERE `id` = '".$_SESSION['id']."'"); now pulls invoices from the DB which have the ID = to the client session ID Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted March 3, 2009 Share Posted March 3, 2009 Change your query to this: $sql = "SELECT * FROM invoices WHERE id = " . $_SESSION['id'] . " ORDER BY id ASC"; $result = mysql_query($sql); if (!$result){ echo "Unable to execute query: $sql" . mysql_error(); } Where $_SESSION['client_id'] is whatever you saved the session variable as. Edit: Too slow Quote Link to comment Share on other sites More sharing options...
fbm Posted March 3, 2009 Author Share Posted March 3, 2009 cheers huggiebear got there through trial and error lol Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.