Click here to Skip to main content
12,395,183 members (59,698 online)
Rate this:
 
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."]");
?>
Posted 28-Jan-13 5:21am
J3ffers210
Comments
J3ffers 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 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.
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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 9 Jul 2013
Copyright © CodeProject, 1999-2016
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