Jump to content

Database help


Schlo_50

Recommended Posts

Ok, this isn't meant to be a double post but i apologise if it comes accross that way!

 

I have a script which calls and displays items from my database, each item has a unique product id. The idea is that the user views the page full of items and clicks a checkbox or any efficient method (suggestions) to select one or more items they want to purchase. For each item they select i want the product id of each to be sent into my database into one field separated by commas. What i need for the next part of the script is some code which will work with the $ProductId's to do what i want it to.

 

Any help? Im seriously stuck and need some ideas about how to achieve my goal.

 

 

<?php
$sql2 = odbc_exec($odbc, "SELECT * FROM Product1 ORDER BY CategoryName") or die (odbc_errormsg());

$prevCat='';
while($row = odbc_fetch_array($sql2))
{
$Category = $row["CategoryName"];
$ProductId = $row["ProductId"];
$ProductName = $row["ProductName"];
$Price = $row["Price"];

// has category changed
// if so, print it
if ($Category != $prevCat)  {
	echo "<h2>$Category</h2>";
}
echo  'Item Code: ', $ProductId, '<br/>Item Name:  ', $ProductName, '<br/><br/>Price: £', $Price, '<input name="code[]" type="text" size="2" /><br/><br/>';

$prevCat = $Category;
}
?>

 

Thanks

Link to comment
Share on other sites

For each item they select i want the product id of each to be sent into my database into one field separated by commas.

 

What you should want is each selected product_id to be written to its own record along with the customer_id

 

eg[pre]

cust_orders

-----+-----------+-----------+

id  | cust_id  |  prod_id  |

-----+-----------+-----------+

1  |  123    |  4321    |

2  |  123    |  4095    |

3  |  123    |  3255    |

4  |  123    |  2102    |

-----+-----------+-----------+

5  |  124    |  1121    |

6  |  124    |  4095    |

-----+-----------+-----------+

7  |  125    |  3255    |

8  |  125    |  1111    |

-----+-----------+-----------+

[/pre]

Link to comment
Share on other sites

Ok, like this you mean?

 

form name="the_form" id="the_form" method="post" action="<?php $_SERVER[php_SELF]; ?>">
<?php
$sql2 = odbc_exec($odbc, "SELECT * FROM Product1 ORDER BY CategoryName") or die (odbc_errormsg());

$prevCat='';
while($row = odbc_fetch_array($sql2))
{
$Category = $row["CategoryName"];
$ProductId = $row["ProductId"];
$ProductName = $row["ProductName"];
$Price = $row["Price"];

// has category changed
// if so, print it
if ($Category != $prevCat)  {
	echo "<h2>$Category</h2>";
}
echo  'Item Code: ', $ProductId, '<br/>Item Name:  ', $ProductName, '<br/><br/>Price: £', $Price, '//need some way of selecting item here, checkbox?<br/><br/>';

$prevCat = $Category;
}
?>
<hr />

  (Order Notes- If you have any comments to make about any of the products you are ordering please state them below.)<br />
<textarea name="ProductNotes" cols="50" rows="5"></textarea><br /><br />
<input name="submit" type="Submit" value="Submit" />
</p>
</form>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.