Start New Discussion Reply to this Discussion Populating checkboxlist from the database
Hi,
I want to have multiple selection checkbox in my website, where user can check for the multiple options.
But for checkbox i should get the data from the database table.
$query2 = "select * from Products where CategoryID = '$CategoryName' ";
mysql_query($query2) or die(mysql_error());
$array = array();
while($row = mysql_fetch_assoc($query2)){
$array[] = $row;}
I dont know is this the right way. but after this i dont know what to do. Please help me with the script . thanks
11 Months Ago
Last Updated
my3h
Light Poster
27 posts since May 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Hello somebody can help me in this
my3h
Light Poster
27 posts since May 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Not entirely sure what you're trying to do, but how about this:
$query2 = "select * from Products where CategoryID = '$CategoryName' ";
$result = mysql_query($query2) or die(mysql_error());
if ($result && mysql_num_rows($result)>0) {
while($row = mysql_fetch_assoc($result)){
$array[] = $row;
}
}
But why you want to transfer the data from one array to another beats me.
If you're wanting to use the data for a series of checkboxes, why not do that instead:
$query2 = "select * from Products where CategoryID = '$CategoryName' ";
$result = mysql_query($query2) or die(mysql_error());
if ($result && mysql_num_rows($result)>0) {
while($row = mysql_fetch_assoc($result)){
echo "<input type=\"checkbox\" name=\"fieldname\" value=\"{$row['product']}\" /> {$row['product']}<br />
}
}
would save you a step
tiggsy
Junior Poster
131 posts since Jul 2009
Reputation Points: 16
Solved Threads: 10
Skill Endorsements: 2
Hey thanks a ton! it worked for me... thank you
my3h
Light Poster
27 posts since May 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
© 2013 DaniWeb® LLC
Page rendered in 0.0652 seconds
using 2.69MB