Jump to content

[SOLVED] creating invoice


jakebur01

Recommended Posts

Ok, I am trying to join 3 tables together to retrieve information to display on an invoice. I am new to joining tables and I keep confusing myself.

 

Heres what I've got:

 

customers table - has customerid, name, address, city, state, zip, and country

 

orders table - has orderid, customerid, amount, date, order_status, ship_name, ship_address, ship_city, ship_state, ship_zip, ship_country, c_phone, c_email, card_type, card_number, card_month, card_year, card_name

 

order_items table - has orderid, isbn, item_price, and quanity

 

 

Here's what i'm trying to do:

 

display address

 

display shipping address

 

display orders

 

display credit card information

 

Thank you,

 

`Jake

Link to comment
https://forums.phpfreaks.com/topic/52962-solved-creating-invoice/
Share on other sites

so would i do three seperate querys under one connection?

 

Like:

$conn = db_connect();

//then

$query = select * from customers where

//then do a second query??

$query = select * from orders where

//and a third??

$query = select * from order_items

//??? I'm not sure exactly how to separate them???

Not jumbled up, that is the structure of the arrays when printed.  But I now see a flaw in the logic I gave you, try this instead:

 

<?php
$query = "SELECT * FROM orders WHERE whatever";
$result = mysql_query($query) or die(mysql_error());

while ($row = mysql_fetch_assoc($result)) {
     $rows[] = $row; // added the [] =) my bad.
}

echo '<pre>' . print_r($rows) . '</pre>';

?>

ok ok, i see

 

now it returns this

 

Array ( [0] => Array ( [orderid] => 14 [isbn] => 30-015 [item_price] => 15.82 [quantity] => 1 ) )

1

 

with this code:

 

$query = "SELECT * FROM order_items WHERE orderid = '$coolid'";
$result = mysql_query($query, $db) or die(mysql_error());

while ($row = mysql_fetch_assoc($result)) {
   $rows[] = $row; 

}


echo '<pre>' . print_r($rows) . '</pre>';


That should answer the question

 

What do I do when I am retrieving multible rows, like from the order items table where I have 5 rows where the orderid column equals 14 ?

 

Should it not? If there were multiple rows in that table with that id it would have been returned in that array.

I'm sorry, I'm a little slow.

 

How do I implement that in with this following code?

 

$query = "SELECT * FROM order_items WHERE orderid = '$coolid'";
$result = mysql_query($query, $db) or die(mysql_error());

while ($row = mysql_fetch_assoc($result)) {
   $rows[] = $row; 

}

<?php

$query = "SELECT * FROM order_items WHERE orderid = '$coolid'";
$result = mysql_query($query, $db) or die(mysql_error());

while ($row = mysql_fetch_assoc($result)) {
   $rows[] = $row;
}

$i = 1;

foreach($rows as $rowid => $rowarray) {
echo "<b>---- Row $rowid ----</b><br />\n\n";
foreach($rowarray as $rowfield => $rowvalue) {
  echo " $rowfield = $rowvalue<br />\n";
}
}

?>

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.