Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8557137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:30:27+00:00 2026-06-11T15:30:27+00:00

I have looked at a few examples on using arrays in a query, but

  • 0

I have looked at a few examples on using arrays in a query, but I just cant seem to get something that will help me…

I need to use an array of selected items from check boxes to the processing page and use them in a query. Note all my data is live, the data from the checkboxes to the data being used /or required from the query.

The first part, query1 calculates the totals of the selected array (from the checkboxes) and the second part, query2 displays all the data from the database from the selected array brought forward.

Can anybody help me with this query? (if only one item is selected, both queries work fine but not with multiple selections)
The name of my data array is “interest”, I have tried using implode and the IN clause in my WHERE query:

<?php
$date = date("F-Y",$_SESSION[diesel_date]);
$matches = implode(',', $_POST[interest]);

include("../xxx.xxx");
$cxn = mysqli_connect($host,$user,$password,$dbname);
$query = "SELECT SUM(`diesel_qty`) d_q FROM `diesel` 
            WHERE MONTH(`diesel_date`)= MONTH( '$dd' )
            AND `diesel_vehicle_no` IN ('$matches') ";
$result = mysqli_query($cxn,$query);
    while($row = mysqli_fetch_assoc($result))
    {
    extract($row);
    echo "<h7>Total Diesel Filled during $dd is&nbsp;</h7><b>";
    print $d_q;
    echo "</b><h7>&nbsp;Litres.</h7><br><br>\n";
    }
?>
<?php
      include("../xxx.xxx");
$cxn = mysqli_connect($host,$user,$password,$dbname)
    or die ("Couldn't connect to server.");
$query = "SELECT
                  `diesel_date`, 
                  `diesel_time`, 
                  `location_id`, 
                  `company_id`, 
                  `diesel_vehicle_no`, 
                  `diesel_driver_name`, 
                  `diesel_qty`,
                  `diesel_feed_id` 
    FROM`diesel` 
    WHERE MONTH(`diesel_date`)= MONTH( '$dd' )
    AND `diesel_vehicle_no` IN ('$matches') 
    ORDER BY `diesel_date`";
$result = mysqli_query($cxn,$query)
    or die ("Couldn't execute query.");

echo "<table><br>
<tr>
 <th>DieselFillDate</th>
 <th>Time</th>
 <th>Location</th>
 <th>CompanyOwning Plant/Vehicle</th>
 <th>Plant/Vehicle No</th>
 <th>DriversName</th>
 <th>Quantity</th>
 <th>DieselFeed</th>
</tr>";
while($row = mysqli_fetch_assoc($result))
{
    extract($row);
    echo "<tr>\n
        <td width='100'>$diesel_date</td>\n
        <td>$diesel_time</td>\n
        <td>$location_id</td>\n
        <td>$company_id</td>\n
        <td>$diesel_vehicle_no</td>\n
        <td>$diesel_driver_name</td>\n
        <td>$diesel_qty</td>\n
        <td>$diesel_feed_id</td>\n
        </tr>\n";
}
echo "</table><br>";
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:30:28+00:00Added an answer on June 11, 2026 at 3:30 pm

    I found the solution, maybe this can help someone else who is struggling with something simular.

    I first assigned the array to a variable…

    $matches = $_POST[interest];
    

    Then replaced…

    $matches = implode(',', $_POST[interest]);
    

    With this

    $amf = implode("', '", array_keys($matches));
    

    The problem I was having with my script was that my variable is not a number, but a string therefor I had to insert “” into the implode statement. Here’s the code and it works perfectly now:

    <?php 
    $date = date("F-Y",$_SESSION[diesel_date]); 
    $amf = implode("', '", array_keys($matches));
    
    include("../xxx.xxx"); 
    $cxn = mysqli_connect($host,$user,$password,$dbname); 
    $query = "SELECT SUM(`diesel_qty`) d_q FROM `diesel`  
            WHERE MONTH(`diesel_date`)= MONTH( '$dd' ) 
            AND `diesel_vehicle_no` IN ('$matches') "; 
    $result = mysqli_query($cxn,$query); 
        while($row = mysqli_fetch_assoc($result)) 
        { 
        extract($row); 
        echo "<h7>Total Diesel Filled during $dd is&nbsp;</h7><b>"; 
        print $d_q; 
        echo "</b><h7>&nbsp;Litres.</h7><br><br>\n"; 
        } 
    ?> 
    <?php 
      include("../xxx.xxx"); 
    $cxn = mysqli_connect($host,$user,$password,$dbname) 
        or die ("Couldn't connect to server."); 
    $query = "SELECT 
                  `diesel_date`,  
                  `diesel_time`,  
                  `location_id`,  
                  `company_id`,  
                  `diesel_vehicle_no`,  
                  `diesel_driver_name`,  
                  `diesel_qty`, 
                  `diesel_feed_id`  
        FROM`diesel`  
        WHERE MONTH(`diesel_date`)= MONTH( '$dd' ) 
        AND `diesel_vehicle_no` IN ('$matches')  
        ORDER BY `diesel_date`"; 
    $result = mysqli_query($cxn,$query) 
    or die ("Couldn't execute query."); 
    
    echo "<table><br> 
    <tr> 
     <th>DieselFillDate</th> 
     <th>Time</th> 
     <th>Location</th> 
     <th>CompanyOwning Plant/Vehicle</th> 
     <th>Plant/Vehicle No</th> 
     <th>DriversName</th> 
     <th>Quantity</th> 
     <th>DieselFeed</th> 
    </tr>"; 
    while($row = mysqli_fetch_assoc($result)) 
    { 
        extract($row); 
        echo "<tr>\n 
        <td width='100'>$diesel_date</td>\n 
        <td>$diesel_time</td>\n 
        <td>$location_id</td>\n 
        <td>$company_id</td>\n 
        <td>$diesel_vehicle_no</td>\n 
        <td>$diesel_driver_name</td>\n 
        <td>$diesel_qty</td>\n 
        <td>$diesel_feed_id</td>\n 
        </tr>\n"; 
    } 
    echo "</table><br>"; 
    ?> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've read and looked a quite a few examples for Threadpooling but I just
I have an application that's locked down using forms authentication. There are few nightly
I have looked but have not found a specific answer for changing just one
A few years ago I looked into using some build system that isnt Make
I have looked at few examples here Calling a Method from an Expression and
This is something I have always wondered about, and looked up a few times
I have come to the conclusion that using app domains for my project will
I have looked at a few of the well-known AOP-oriented frameworks for .Net such
I have looked at Spring MVC a few times briefly, and got the basic
Have looked quite hard for this answer but having no luck. I have 3

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.