Click here to Skip to main content
15,894,460 members

PHP from mySQL into a drop down list dependant on group in table

J3ffers asked:

Open original thread
Hi Guys,

I'm trying to populate each drop down with items that are labled as productpr[number] and qty[number] from a database, however it keeps creating a new drop down for each result, probably something really simple, but would appreciate the help.

Regards,
James


data look like this...

ID | PIDx | QTYx | Price | jPrice | CartDescription | ViewDescription
1 | productpr1 | qty1 | 10 | 10 | 1 | 1
2 | productpr1 | qty1 | 10 | 10 | 1a | 1a
3 | productpr2 | qty2 | 11 | 11 | 2 | 2
4 | productpr2 | qty2 | 11 | 11 | 2a | 2a

creating a html like this;
XML
<b>Choose an Operating System</b>
<input type="hidden" value="1" name="qty1">
<select name="productpr1">
<option>---</option>
<option id="10" value="1:10">1</option>
</select>
<br><br>



PHP
<?
$objConnect = mysql_connect("localhost","username","password") or die(mysql_error());
$objDB = mysql_select_db("database");
$strSQL = "SELECT * FROM puterz";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<br><br><br><br><br><br><br>
<h1>Configure your own AMD Based PC and let us build it for you.</h1>

        <form action="http://wwx.aitsafe.com/cf/addmulti.cfm" method="post">
        <input name="userid" type="hidden" value="1234567">

<?
while($objResult = mysql_fetch_array($objQuery))
{
?>

<?
if($objResult["PIDx"] == "productpr1" && $objResult["QTYx"] == "qty1")
{
?>

Choose an Operating System
<input type="hidden" value="1" name="<?=$objResult["QTYx"];?>">
<select name="<?=$objResult["PIDx"];?>">
<option>---</option>
<option id="<?=$objResult["jPrice"];?>" value="<?=$objResult["CartDescription"];?>:<?=$objResult["Price"];?>"><?=$objResult["ViewDescription"];?></option>
</select>
<br><br>


<?
}
if($objResult["PIDx"] == "productpr2" && $objResult["QTYx"] == "qty2")
{
?>


Choose a Case
<input type="hidden" value="1" name="<?=$objResult["QTYx"];?>">
<select name="<?=$objResult["PIDx"];?>">
<option>---</option>
<option id="<?=$objResult["jPrice"];?>" value="<?=$objResult["CartDescription"];?>:<?=$objResult["Price"];?>"><?=$objResult["ViewDescription"];?></option>
</select>

<?
}
}
?>
			

			<!-- Send Button -->
			<input name="return" type="hidden" value="#">
			<input type="submit" value="Buy Now!">
			
			
        </form>

<?
mysql_close($objConnect);
?>
Tags: HTML, PHP, MySQL

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900