Click here to Skip to main content
16,020,432 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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);
?>
Posted
Comments
J3ffers 29-Jan-13 12:20pm    
Anyone else able to help?

You have your DB iterator

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


and inside this iterator you generate select box markup

PHP
<select name="<?=$objResult[" pidx="];?>"></select>


According to if criteria, you will create one select per each row.

Consider refactoring the code, by moving select tag generation outside of the items loop.
 
Share this answer
 
v2
Comments
J3ffers 28-Jan-13 11:51am    
I've tried this and still get a similar result?
Vyacheslav Voronenko 28-Jan-13 11:52am    
Where is updated code?
Vyacheslav Voronenko 28-Jan-13 12:01pm    
I think, some markup was filtered out during commenting
J3ffers 28-Jan-13 12:13pm    
Completely stuck on this one :(, I've tried it every way possible.. (I think)

Is there another way?
Vyacheslav Voronenko 28-Jan-13 14:05pm    
I think it is wrong to mix different entities (case, operating system) in one table/recordset. Better to split them into two different recordsets.
Managed to fix this myself some time ago, just clearing my old questions out.. Thanks to all that made suggestions...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



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