Hello,
I have a table with 10 columns in MySQL. This table is one of several in the database. The columns hold enum values 0 or 1.
Tom's answer to the question 'I have the following animals' is entered using checkboxes in a form:
<input type="checkbox" name="m_cats" value="1">
<input type="checkbox" name="m_dogs" value="1">
<input type="checkbox" name="m_birds" value="1">
<input type="checkbox" name="m_ferrets" value="1">
<input type="checkbox" name="m_horses" value="1">
If the column value is '1', the record is true and should be displayed on the page (when the query relating to that table is executed).
Ie: Select all columns for tom in the table where the value is 1.
The code I have now seems bulky:
$sql = "SELECT * FROM m_animals WHERE m_name = 'Tom'";
$result = mysql_query($sql);
if ($myrow = mysql_fetch_array($result))
{
do {
if($myrow["m_dogs"] ==1)
{ echo "dogs";
}
if($myrow["m_cats"] ==1)
{ echo "cats";
}
and so on.
Is there a better way to do this? Two considerations are that I need to be able to edit the info (right now I call the records back into check boxes, checked=1 if value=1), and that I want to be able to display the results using bullets and in 2 columns (I can sort this out myself, but just FYI).
thanks in advance for any tips...