Jump to content

[SOLVED] pull data from DB based on Session ID?


fbm

Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.