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 6247581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:54:13+00:00 2026-05-24T12:54:13+00:00

I am busy creating an order system. I am having issues trying to create

  • 0

I am busy creating an order system.

I am having issues trying to create a form that requires only one order button.

Currently the form is for each product result. The user has the ability to enter in a quantity desired of a certain product, then can order the product based on the quantity chosen. The item id and quantity chosen are then added to sessions.

The problem with this, is that if there are 5 items, there are 5 order buttons.

I am trying to simplify this, where for 5 products, there will be only one order button controlling the entire selection of products.

Here is the code relating to this:

//Now we search for our search term, in the field the user specified 

$dataQuery = "SELECT * FROM `products` WHERE upper(`desc`) LIKE '%" 
   . implode("%' AND upper(`desc`) LIKE '%", $keywords_array) 
   . "%' ORDER BY `desc`";

$data = mysql_query($dataQuery) or die(mysql_error());

$tempVar = 0;
//And we display the results 
while ($result = mysql_fetch_array($data)) {
$prId = $result['id'];
$prRefCode = $result['refCode'];
$prDesc = $result['desc'];
$prPack = $result['pack'];
$prMeasure = $result['measure'];
$prQuantity = $result['quantity'];
$prDeptCode = $result['deptCode'];
$prTaxable = $result['taxable'];
$prPrice1 = $result['price1'];
$prPrice2 = $result['price2'];
$prCrdCode = $result['crdCode'];
$prCost1 = $result['cost1'];
$prCost2 = $result['cost2'];

if ($tempVar == 0) {
$pageContent .= '
<p><u>All prices are inclusive of VAT</u></p>
<table class="searchResults" border="1" align="center" width="90%">
<thead>
    <tr>
        <th>Stock Code</th>
        <th>Description</th>
        <th>Packsize</th>
        <th>Price</th>
        <th>In-Stock?</th>
        <th>Quantity</th>
        <th>Submit</th>
    </tr>
</thead>
<tbody>
';
}

    $pageContent .= '
<tr>
    <td>' . $prId . '</td>
    <td>' . $prDesc . '</td>
    <td>' . $prPack . 'x' . $prSize . ' ' . $prMeasure . '</td>
    <td>R' . $prPrice1 . '</td>
';
    if (empty($prQuantity)) {
        $pageContent .= '
<td>No</td>
';
    } else {
        $pageContent .= '
<td>Yes</td>
';
    }
    $pageContent .= '
    <form id="validated" action="" method="post">
    <td>            
            <div>
                <input type="text" 
onkeydown="return ( event.ctrlKey || event.altKey 
                || (47<event.keyCode && event.keyCode<58 && event.shiftKey==false) 
                || (95<event.keyCode && event.keyCode<106)
                || (event.keyCode==8) || (event.keyCode==9) 
                || (event.keyCode>34 && event.keyCode<40) 
                || (event.keyCode==46) )" 
                name="quantity" size ="2" 
                value ="1" 
                style="background: #F4F4F4;
                       font-family: Monaco, monospace;" />
            </div>            
    </td>
    <td>
            <div>
                <input type="hidden" name="id" value="' . $prId . '" />
                <input type="submit" name="action" value="Order" />
            </div>            
    </td>
    </form>     
</tr>
';
$tempVar ++;
}



//This counts the number of results - and if there wasn't any it gives them a little message explaining that 
$anymatches = mysql_num_rows($data);
if ($anymatches == 0) {
    $pageContent .= '
<p>Sorry, but we can not find an entry to match your query</p>
<!-- end .aliLeft --></div>
';
}

if ($anymatches > 0 and count($tempVar) == count($anymatches)) {
    $pageContent .= '
</tbody>
</table>
<!-- end .aliLeft --></div>
';
}

And here is the code controlling the instance of a user clicking on the order button:

if (!isset($_SESSION['order']))
{
$_SESSION['order'] = array();
}

if (!isset($_SESSION['quantity']))
{
$_SESSION['quantity'] = array();
}

if (isset($_POST['action']) and $_POST['action'] == 'Order' and $_POST['quantity'] > 0)
{
// Add item to the end of the $_SESSION['order'] array
$_SESSION['order'][$_POST['id']] = $_POST['id'];
$_SESSION['quantity'][$_POST['id']] = $_POST['quantity'];
header('Location: .');
exit();
}

And here is the code that configures the quantity value for totalling the order:

$total = 0;
if (count($order) > 0)
{
foreach ($order as $product)
{
    mysql_data_seek( $totalsSql, 0);  //<- this line, to reset the pointer for every EACH.
while($row = mysql_fetch_assoc($totalsSql))
    {
     $prodId = $row['id'];
     $prodPrice1 = $row['price1'];
     $prodQuantity = $quantity[$prodId];
    if ($product == $prodId) 
        {
        $total += ($prodPrice1*$prodQuantity);
        break;
        }
    }
}
}

As you can see, when the user searches for a product, the mysql table is queried, if results are found, then they are returned.

In this process, the form is created for each result.

What I am trying to do, is extend this form to cover the entire set of results, then have only one input for “Order”, so essentially, the user can enter quantities on various products, then have those products and quantities added to their order.

Does anyone have any advice on how i would go about this task?

I would appreciate any input what so ever, thank you!

  • 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-05-24T12:54:14+00:00Added an answer on May 24, 2026 at 12:54 pm

    Encode the product identifier in the field name:

    <input type="text" onkeydown="…" name="quantity<?php echo $prId; ?>" size ="2" value ="1" style="…" />
    

    In your process script you then do something like:

    foreach ($_POST as $sKey => $sQuantity) {
        if (preg_match('/^quantity([1-9][0-9]*)$/DX', $sKey, $asMatch) === 1) {
            // User added $sQuantity times product $asMatch[1]
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am busy creating an order system. I am having issues trying to create
I am currently busy creating a search function that queries a user input string
I have been busy in my project creating a webapp (in struts) that manages
I am busy creating a system where I need to keep track of every
I'm busy creating a very simplistic ruby on rails app that won't need a
I am currently creating a quote system which works like this: User submits data
I'm busy creating a metaclass that replaces a stub function on a class with
I am busy developing a Delphi App that uses F12 When I am running
I'm busy writing a class that monitors the status of RAS connections. I need
I'm busy introducing myself to jQuery by implementing a little system where onmouseover on

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.