PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old May 3rd, 2012, 10:08 PM
SB2 SB2 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Posts: 6 SB2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 29 m 51 sec
Reputation Power: 0
Insert Into with multiple Products under 1 order

Hello,

I can not figure out how to get multiple product ID's to print 1 per row under the same Order number. It only outputs the last Prod_id (or $part_id) with the correct associated QTY, and Order#, sellprice (referring to $sql3)

Any help would be appreciated.

$connection = mysql_connect("localhost",XXXX","XXXXX");
mysql_select_db("xxxx",$connection);

$sql1 = "insert into customer (cust_id, fn, ln, addr, addr2, city, st, zip) values
('','$fn','$ln','$addr', '$addr2','$city','$st','$zip')";
$result1 = mysql_query($sql1,$connection) or die(mysql_error());
$cust_id = mysql_insert_id();

$sql2 = "insert into orders (order_num, order_dt, cust_id, shipcost, pymthd) values
('', NOW(''),'$cust_id','$shipcost', '$paymthd')";
$result2 = mysql_query($sql2,$connection) or die(mysql_error());
$order_num = mysql_insert_id();

foreach ($cart as $part_id=>$quantity)
{
$sql3 = "insert into transaction (part_id, order_num, qty, sellprice) values

('$part_id','$order_num', '$quantity','$curprice')";
}
$result3 = mysql_query($sql3,$connection) or die(mysql_error());

Reply With Quote
  #2  
Old May 4th, 2012, 07:20 PM
SB2 SB2 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Posts: 6 SB2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 29 m 51 sec
Reputation Power: 0
I figured out what was wrong with my loop it was just a {} issue for the For Each part of my statement. Almost all The data is loading all except the $curprice. and I believe that it may be that the SQL statement after the first foreach loop (which I did not originally include) pulls the $curprice...and it again is only pulling the last $curprice.
so.....

(is something like this possible, all I need is that $curprice.....this was the same query that was further up in the script, but I don't think it's needed at the top if it can be repeated b4 the insert statement.)
===========================

foreach ($cart as $part_id=>$quantity)
{
$sql3 = "select part_id, item, curprice from products where part_id = $part_id";
$result3 = mysql_query($sql3,$connection) or die(mysql_error());
$sql4 = "insert into transaction (part_id, order_num, qty, sellprice) values
('$part_id','$order_num', '$quantity','$curprice')";
$result4 = mysql_query($sql4,$connection) or die(mysql_error());
}

Reply With Quote
  #3  
Old May 7th, 2012, 10:02 PM
SB2 SB2 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Posts: 6 SB2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 29 m 51 sec
Reputation Power: 0
solved

I solved this one :


foreach( $cart as $part_id => $quantity){
$sql3 = "select part_id, curprice from products where part_id = $part_id";
$result3 = mysql_query($sql3,$connection) or die(mysql_error());
{

while ($record = mysql_fetch_array($result3))
{
$curprice = isset($record['curprice']) ? htmlentities($record['curprice']) : '';
$part_id = isset($record['part_id']) ? htmlentities($record['part_id']) : '';

$sql4 = "insert into transaction (part_id, order_num, qty, sellprice) values ('$part_id','$order_num', '$quantity','$curprice')";
$result4 = mysql_query($sql4,$connection) or die(mysql_error());

}
}
}


But will be posting my next issue in a second

Reply With Quote
  #4  
Old May 8th, 2012, 09:38 PM
Pauline224 Pauline224 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 4 Pauline224 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 39 sec
Reputation Power: 0
URLURLURLURL

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Insert Into with multiple Products under 1 order


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap