Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts

    While Loop, Inside While Loop only displays once.

    Hi guys...

    I'm building a shopping cart... and cannot understand why the second while loop only runs once, is should runs twice (the second time the first loop does). All the correct data is in the MySQL, i've checked, double checked, and triple checked it, but cannot figure out what's wrong, any help would be appreciated, code below.

    PHP Code:
    <table width="100%" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td class="in"><b>Item Name</b></td>
                                    <td class="ip"><b>Item Price</b></td>
                                    <td class="sk"><b>SKU</b></td>
                                    <td class="qt"><b>Quantity</b></td>
                                    <td class="qt"><b>Sub-Total</b></td>
                                    <td class="st"><b>Actions</b></td>
                                </tr>
                                <?php
                                    $runningTotal 
    0.00;
                                    while(
    $c mysql_fetch_array($cart)) {
                                    
    $pid $c['product_id'];
                                    
    $productInfo mysql_query("SELECT * FROM catalouge1 WHERE id = '$pid'");
                                    
    $pinf mysql_fetch_array($productInfo);
                                
    ?>
                                <tr>
                                    <td class="in_i" align="left" valign="middle"><?php echo $pinf['item_name']; ?> (<?php echo $pid?>)</td>
                                    <td class="ip_i" align="left" valign="middle">&pound;<?php echo $pinf['sale_price']; ?></td>
                                    <td class="sk_i" align="left" valign="middle"><?php echo $pinf['sku']; ?></td>
                                    <td class="qt_i" align="left" valign="middle"><input type="text" style="width: 30px;" name="<?php echo $c['id']; ?>" value="<?php echo $c['qty']; ?>" /> (Max <?php echo $pinf['in_stock']; ?>)</td>
                                    <td class="qt_i" align="left" valign="middle" width="96">&pound;<?php echo number_format($pinf['sale_price'] * $c['qty'], 2"."","); ?></td>
                                    <td class="st_i" align="left" valign="middle" width="95" align="center"><a href="/deletefromcart/<?php echo $c['id']; ?>/">Remove Item</a></td>
                                </tr>
                                <?php
                                    
    if(mysql_num_rows($ccart) > 0) {
                                        
    $for_product $pid;
                                        while(
    $cc mysql_fetch_array($ccart)) {
                                            if(
    $cc['for_product'] == $for_product) {
                                                
    $cid $cc['chain_id'];
                                                
    $chainInfo mysql_query("SELECT * FROM chain_details WHERE id = '$cid'");
                                                
    $cinf mysql_fetch_array($chainInfo);
                                                
    $chain_style $cinf['style_id'];
                                                
    $chainStyleInfo mysql_query("SELECT * FROM chains WHERE id = '$chain_style'");
                                                
    $csinf mysql_fetch_array($chainStyleInfo);
                                
    ?>
                                <tr>
                                    <td class="in_i" align="left" valign="middle"><?php echo $csinf['name']; ?> Chain - <?php echo $cinf['length']; ?>"</td>
                                    <td class="ip_i" align="left" valign="middle">&pound;<?php echo $cinf['sale_price']; ?></td>
                                    <td class="sk_i" align="left" valign="middle"><?php echo $cinf['sku']; ?></td>
                                    <td class="qt_i" align="left" valign="middle" height="22"><?php echo $cc['qty']; ?></td>
                                    <td class="qt_i" align="left" valign="middle" width="96">&pound;<?php echo number_format($cinf['sale_price'] * $cc['qty'], 2"."","); ?></td>
                                    <td class="st_i" align="left" valign="middle" width="95" align="center"><a href="/deletefromcart/chain/<?php echo $cc['id']; ?>/">Remove Item</a></td>
                                </tr>
                                
                                <?php
                                            
    }
                                        
    $runningTotal $runningTotal + ($cinf['sale_price'] * $cc['qty']);    
                                        }
                                    }
                                
    ?>
                                <?php
                                $runningTotal 
    $runningTotal + ($pinf['sale_price'] * $c['qty']);
                                    }
                                
    ?>
                            </table>
                            <div align="right">
                            <table cellpadding="0" cellspacing="0" border="0" style="padding: 4px; border-left: 1px solid #333333; border-right: 1px solid #333333; border-bottom: 1px solid #333333;" width="210">
                                <tr>
                                    <td>
                                        <b>Made Changes? &nbsp;</b> 
                            <input type="submit" value="Update Cart!" />
                                    </td>
                                </tr>
                            </table>
    Thanks,
    ~ Christian

  • #2
    Regular Coder
    Join Date
    Apr 2009
    Location
    somewhere over the rainbow
    Posts
    105
    Thanks
    2
    Thanked 14 Times in 14 Posts
    first, well I'm sorry you are too messing up with the code sql within sql.
    I can't read this without trying the code myself.

    if it was my script the thing that I would do is to debug my-self. just print step-by-step the info you want to retrieve and find whats wrong..

    second, read here: http://www.w3schools.com/Sql/sql_join.asp about sql joins it's will improve 10 times your work (and it will be readable to all).

    good luck!
    :. -= | Eran | =- .:
    __________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •