SunQuest
 
           General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

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:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old December 26th, 2002, 07:35 PM
DDDooGGG DDDooGGG is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97 DDDooGGG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 33 sec
Reputation Power: 6
Question For loop ????

how can i use the for loop command to insert multiple records?
__________________
regards,


Fulton

Reply With Quote
  #2  
Old December 26th, 2002, 07:50 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
PHP Code:
 $records /* your array of records */;

for ( 
$i '1'$i <= count$records ); $i++ ) {

   
/* do your insertion code here */




$records will contain your array of records you would like to insert. The for loop in english says this ->

$i starts with the value of one (1), while $i is less than or equal to the number of values in the $records array - execute the loop. After each execution of the loop, increment the value of $i one (1) time.

Is that what you are looking for?
__________________
~ Joe Penn

We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set?

Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you.




Reply With Quote
  #3  
Old December 26th, 2002, 09:11 PM
DDDooGGG DDDooGGG is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97 DDDooGGG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 33 sec
Reputation Power: 6
PHP Code:
 $records = array($itemid$qty);

for ( 
$i '1'$i <= count$records ); $i++ ) {

$strQuery mysql_query("INSERT INTO  userorder (UserID, itemId, qty, IpAddress, PaymentStatus, TimeKey,OrderDate,GrandTotal) "
$strQuery .= "VALUES ('$details[0]', '$records[0]', '$records[1]', '$IP', 'Pending', " time().", NOW(''), " $_POST['totalCost'] . ")");

 
mysql_query($strQuery);
        } 


Hi thanks for your help. Above is what i am using and it works, but but i would like to do is create an array from my FORM id variables, so with each insert that is made, the quantity and itemid for that specific item is inserted.
Do i have to create an array inside an array? if so how do i accomplish this?

Reply With Quote
  #4  
Old December 26th, 2002, 09:36 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
Are there multiple products on the same page? If so, let me see the product page...

Reply With Quote
  #5  
Old December 26th, 2002, 10:22 PM
DDDooGGG DDDooGGG is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97 DDDooGGG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 33 sec
Reputation Power: 6
PHP Code:
<body topmargin="0">
<? 
if(
$UserLoggedIn)  // If user is registered and logged in.
    

?>
<?php 
$IP 
getenv("REMOTE_ADDR");

$db mysql_connect("localhost""username""password");
mysql_select_db("database",$db);

if (
$_POST["Submit"] == "Purchase")      // when Purchase button is pressed
{
    
$itemid $_POST["itemid"] ;
    
$qty $_POST["qty"] ;
    
$orderid uniqid();
    
//Inserts records into USERORDER table
        
$records = array($itemid$qty);
    
        for ( 
$i '1'$i <= count$records ); $i++ ) {
        
//echo $records[1];
        
mysql_query("INSERT INTO  userorder (UserID, itemId, qty, IpAddress, PaymentStatus, TimeKey,OrderDate,GrandTotal) VALUES ('$details[0]', '$records[0]', '$records[1]', '$IP', 'Pending', " time().", NOW(''), " $_POST['Total'] . ")");
        }        

    
//header("location: redirect.php?orderid=$orderid&Total=" . $_POST['Total'] . "");
        
}

    
$query_record sprintf("select * from cart inner join items on cart.itemid = items.itemId where cart.cookieid = '%s' "$_COOKIE["cartId"]);
    
$result mysql_query($query_record$db);
            
        
?>

<form action="pay.php?purchase=yes" method="post" name="frmPay" id="frmPay"  >
  <table width="600" border="0" align="center" cellpadding="1" cellspacing="0" class="TableMain">
    <tr> 
      <td colspan="4" align="center"></td>
    </tr>
    <tr> 
      <td width="144"><font color="#FFFFFF"><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Quantity</strong></font></td>
      <td width="9"><font color="#FFFFFF">&nbsp;</font></td>
      <td width="288"><font color="#FFFFFF"><strong>Package</strong></font></td>
      <td width="151"><font color="#FFFFFF"><strong>Price</strong></font></td>
    </tr>
    <tr> 
      <td colspan="4" align="center"></td>
    </tr>
    <?    while ($myrow mysql_fetch_array($result))  
        {
        
$Total += ($myrow["qty"] * $myrow["itemPrice"]);
        
?>
    <tr> 
     
      <td width="144"><font color="#FFFFFF"></font><?php echo $myrow['qty']; ?> 
        <input name="qty" type="hidden" id="qty" value="<?php echo $myrow['qty']; ?>"> 
      </td>
      <td>&nbsp;</td>
      <td width="288"><?php echo $myrow['itemName']; ?></td>
      <td width="151">$<?php echo $myrow['itemPrice']; ?> <input name="itemid" type="hidden" id="itemid" value="<? echo $myrow['itemId'];?>"></td>
    </tr>
    <tr> 
      <td colspan="4" align="center"></td>
    </tr>
    <tr> 
      <?php    
        
}     //end while loop    
?>
      <td width="144">&nbsp;</td>
      <td>&nbsp;</td>
      <td width="288" align="right">&nbsp;</td>
      <td width="151">&nbsp;</td>
    </tr>
    <tr> 
      <td colspan="4" align="center"></td>
    </tr>
  </table>
  <table width="94%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr> 
      <td width="30%" align="center"> <input name="cart" type="button" class="SubmitButtons" id="cart" value="Return to Cart" onClick="javascript: location.replace('cart.php')"> 
      </td>
      <td width="44%" align="center"><strong><font color="#FFFFFF">Total:</font> 
        $<? echo  number_format($Total2"."","); ?> </strong></td>
      <td width="24%" align="center"><input name="Total" type="hidden" id="Total" value="<? echo  number_format($Total2"."","); ?>"> 
        <input name="Submit" type="submit" class="SubmitButtons"  value="Purchase"> 
      </td>
    </tr>
    <tr> 
      <td colspan="4" align="center"></td>
    </tr>
  </table>
</form>
<? } else {
        
// If user is NOT registered
        
header"location: login.php");        
    }
?>


</body> 

Reply With Quote
  #6  
Old December 27th, 2002, 11:57 AM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
Hey DDDooGGG,

Can you post a link to an actuall page generated by your server. I can't do to much with your code there without simulating your database on my server. A link to an actuall generated page would be much better....

Thanks -

Reply With Quote
  #7  
Old December 27th, 2002, 07:04 PM
DDDooGGG DDDooGGG is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97 DDDooGGG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 33 sec
Reputation Power: 6
thanks for your help, i got it working with the following:
PHP Code:
//Create array
                
$sql "select * from cart where cookieid = '" $_COOKIE["cartId"] . "' "
                
$result mysql_query($sql); 
                while(
$row mysql_fetch_row($result)) 
                    { 
                    
$myArray[$row[2]] = $row[3]; 
                    } 
                
//now we expand it 
                    
while(list($item,$qty) = each($myArray)) 
                    { 
                    
//Inserts records into USERORDER table
                        
mysql_query("INSERT INTO  table (value) VALUES ('$item', '$qty')");
                    } 

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > For loop ????


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 | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway