SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Checkbox id in mysql query in php.

    PHP Code:
    <?php
    error_reporting
    (0);
    require(
    "connect.php");

       
    $details "SELECT qty_size, SUM(qty_qty) AS sum FROM tbl_qty WHERE qty_tbl_order_id IN (133, 137) GROUP BY qty_size";
    $details_result mysql_query$details)
        or die ( 
    "Couldn't get Products: ".mysql_error() );
    while ( 
    $det_row mysql_fetch_array $details_result ) )
    {
    echo 
    "<b>&nbsp ".$det_row'qty_size' ].":&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp </b>".$det_row'sum' ]."<br>";
    }

    ?>
    Hi

    I am getting below out put with the above script. Its ok.


    128: 304
    140: 429
    152: 429
    164: 358
    176: 268
    ******************************
    But when i use below script,


    PHP Code:
    <?php
    error_reporting
    (0);
    require(
    "connect.php");

    // get a total ...
    if(!empty($_POST['items8'])) {
        foreach(
    $_POST['items8'] as $item) {   
       

    $details "SELECT qty_size, SUM(qty_qty) AS sum FROM tbl_qty WHERE qty_tbl_order_id='$item' GROUP BY qty_size";
    $details_result mysql_query$details)
        or die ( 
    "Couldn't get Products: ".mysql_error() );
    while ( 
    $det_row mysql_fetch_array $details_result ) )
    {
    echo 
    "<b>&nbsp ".$det_row'qty_size' ].":&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp </b>".$det_row'sum' ]."<br>";
    }
    }
    }

    ?>
    then i get the out put as below.

    128: 183
    140: 258
    152: 258
    164: 215
    176: 161
    128: 121
    140: 171
    152: 171
    164: 143
    176: 107

    But my requirement is as
    128: 304
    140: 429
    152: 429
    164: 358
    176: 268

    Please advise me where is the problem.

    Thanks

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Echo out $details in your second script, and see what the query looks like.

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    If the contents of :
    PHP Code:
    $_POST['items8'
    do not equal 133 and 137 then you are effectively doing a different query so inspect it with
    PHP Code:
     var_dump($_POST['items8']) 

    Using IN is probably a faster way of doing things, so you should consider replicating the first query and using this:
    PHP Code:
    $in_clause "(" join(","$_POST['items8']) . ")";

    $details "SELECT qty_size, SUM(qty_qty) AS sum FROM tbl_qty WHERE qty_tbl_order_id IN $in_clause ORDER BY qty_size"


Bookmarks

Posting Permissions

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