Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: HTML PHP MySQL
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;
<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>
 

<?
$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 28-Jan-13 6:21am
J3ffers210
Comments
J3ffers at 29-Jan-13 12:20pm
   
Anyone else able to help?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You have your DB iterator
 
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
 
and inside this iterator you generate select box markup
 
<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.
  Permalink  
v2
Comments
J3ffers at 28-Jan-13 11:51am
   
I've tried this and still get a similar result?
Vyacheslav Voronenko at 28-Jan-13 11:52am
   
Where is updated code?
Vyacheslav Voronenko at 28-Jan-13 12:01pm
   
I think, some markup was filtered out during commenting
J3ffers at 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 at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Managed to fix this myself some time ago, just clearing my old questions out.. Thanks to all that made suggestions...
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 120
4 DamithSL 105
0 OriginalGriff 6,045
1 DamithSL 4,611
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 9 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100