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
https://forums.phpfreaks.com/topic/79391-database-help/
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
https://forums.phpfreaks.com/topic/79391-database-help/#findComment-401907
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
https://forums.phpfreaks.com/topic/79391-database-help/#findComment-401968
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.