0

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

2
Contributors
3
Replies
5
Views
5 Years
Discussion Span
Last Post by my3h
1

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

Votes + Comments
Correct
0

Hey thanks a ton! it worked for me... thank you

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.