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?

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

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

Archived

This topic is now archived and is closed to further replies.

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