Page 1 of 1

Please help -- Checkboxes -- So close, yet so far...

Posted: Sat Jul 16, 2005 12:48 pm
by jjfletch
Newbie here....

I have a form that has a number of checkboxes. Upon initial submission, the values of the checked boxes are stored as one variable via "implode" and placed into my database.

In an effort to make the form editable (that is, a user can select/deselect boxes as they wish) , I've been trying to place "checked" inside the input tag for the values that are actually in the database.

But, I can't figure out how to check to see if that particular item is in the database... I've pasted the code below and indicated where I'm having a problem.

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');

   $query = "SELECT * FROM qtable WHERE id='$did'";
   $result = @mysql_query ($query);
 
   while($row=mysql_fetch_array($result)) {
   $item=$row['items']; 
   $brd=$row['brand'];
   $st=$row['store'];
   } 

foreach ($array as $item) {

    if ( $item is in database)  // THIS IS WHERE I'M STUCK
         $chk = 'checked';
    else
         $chk = '';
    echo "<input type='checkbox' name='$item' value='1' $chk> $item<br>";
}
r of checkboxes. Upon initial submission, the values of the checked boxes are stored as one variable via "implode" and placed into my database.

In an effort to make the form editable (that is, a user can select/deselect boxes as they wish) , I've been trying to place "checked" inside the input tag for the values that are actually in the database.

But, I can't figure out how to check to see if that particular item is in the database... I've pasted the code below and indicated where I'm having a problem.

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');

   $query = &quote;SELECT * FROM qtable WHERE id='$did'&quote;;
   $result = @mysql_query ($query);
 
   while($row=mysql_fetch_array($result)) {
   $item=$row&#1111;'items']; 
   $brd=$row&#1111;'brand'];
   $st=$row&#1111;'store'];
   } 

foreach ($array as $item) {

    if ( $item is in database)  // THIS IS WHERE I'M STUCK
         $chk = 'checked';n, the values of the checked boxes are stored as one variable via "implode" and placed into my database.  

In an effort to make the form editable (that is, a user can select/deselect boxes as they wish) , I've been trying to place "checked" inside the input tag for the values that are actually in the database.  

But, I can't figure out how to check to see if that particular item is in the database... I've pasted the code below and indicated where I'm having a problem.

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');

   $query = &quote;SELECT * FROM qtable WHERE id='$did'&quote;;
   $result = @mysql_query ($query);
 
   while($row=mysql_fetch_array($result)) {
   $item=$row&#1111;'items']; 
   $brd=$row&#1111;'brand'];
   $st=$row&#1111;'store'];
   } 

foreach ($arrayvariable via "implode" and placed into my database.  

In an effort to make the form editable (that is, a user can select/deselect boxes as they wish) , I've been trying to place "checked" inside the input tag for the values that are actually in the database.  

But, I can't figure out how to check to see if that particular item is in the database... I've pasted the code below and indicated where I'm having a problem.

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');

   $query = &quote;SELECT * FROM qtable WHERE id='$did'&quote;;
   $result = @mysql_query ($query);
 
   while($row=mysql_fetch_array($result)) {
   $item=$row&#1111;'items']; 
   $brd=$row&#1111;'brand'];
   $st=$row&#1111;'store'];
   } 

foreach ($array as $item) {

    if ( $item is in databas are stored as one variable via "implode" and placed into my database.  

In an effort to make the form editable (that is, a user can select/deselect boxes as they wish) , I've been trying to place "checked" inside the input tag for the values that are actually in the database.  

But, I can't figure out how to check to see if that particular item is in the database... I've pasted the code below and indicated where I'm having a problem.

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');

   $query = "S
I have a form that has a number of checkboxes.  Upon initial submission, the values of the checked boxes are stored as one variable via "implode" and placed into my database.  

In an effort to make the form editable (that is, a user can select/deselect boxes as they wish) , I've been trying to place "checked" inside the input tag for the values that are actually in the database.  

But, I can't figure out how to check to see if that particular item is in the database... I've pasted the code below and indicated where I'm having a problem.

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');

   $query = &quote;SELECT * FROM qtable WHERE id='$did'&quote;;
   $result = @mysql_query ($query);
 
   while($row=mysql_fetch_array($result)) {
   $item=$row&#1111;'items']; 
   $brd=$row&#1111;'brand'];
   $st=$row&#1111;'store'];
   } 

foreach ($array as $item) {

    if ( $item is in database)  // THIS IS WHERE I'M STUCK
         $chk = 'checked';
    else
         $chk = '';
    echo &quote;&lt;input type='checkbox' name='$item' value='1' $chk&gt; $item&amp
I have a form that has a number of checkboxes.  Upon initial submission, the values of the checked boxes are stored as one variable via "implode" and placed into my database.  

In an effort to make the form editable (that is, a user can select/deselect boxes as they wish) , I've been trying to place "checked" inside the input tag for the values that are actually in the database.  

But, I can't figure out how to check to see if that particular item is in the database... I've pasted the code below and indicated where I'm having a problem.

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');

   $query = "SELECT * FROM qtable WHERE id='$did'";
   $result = @mysql_query ($query);
 
   while($row=mysql_fetch_array($result)) {
   $item=$row['items']; 
   $brd=$row['brand'];
   $st=$row['store'];
   } 

foreach ($array as $item) {

    if ( $item is in database)  // THIS IS WHERE I'M STUCK
         $chk = 'checked';
    else
         $chk = '';
    echo "<input type='checkbox' name='$item' value='1' $chk> $item<br>";
}
, 'Bread', 'Lettuce' , 'Cookies');

$query = "SELECT * FROM qtable WHERE id='$did'";
$result = @mysql_query ($query);

while($row=mysql_fetch_array($result)) {
$item=$row['items'];
$brd=$row['brand'];
$st=$row['store'];
}

foreach ($array as $item) {

if ( $item is in database) // THIS IS WHERE I'M STUCK
$chk = 'checked';
else
$chk = '';
echo "<input type='checkbox' name='$item' value='1' $chk> $item<br>";
}

w['brand'];
$st=$row['store'];
}

foreach ($array as $item) {

if ( $item is in database) // THIS IS WHERE I'M STUCK
$chk = 'checked';
else
$chk = '';
echo "<input type='checkbox' name='$item' value='1' $chk> $item<br>";
}

on, the values of the checked boxes are stored as one variable via "implode" and placed into my database.

In an effort to make the form editable (that is, a user can select/deselect boxes as they wish) , I've been trying to place "checked" inside the input tag for the values that are actually in the database.

But, I can't figure out how to check to see if that particular item is in the database... I've pasted the code below and indicated where I'm having a problem.

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');

   $query = "SELECT * FROM qtable WHERE id='$did'";
   $result = @mysql_query ($query);
 
   while($row=mysql_fetch_arrhecked boxes are stored as one variable via "implode" and placed into my database.  

In an effort to make the form editable (that is, a user can select/deselect boxes as they wish) , I've been trying to place "checked" inside the input tag for the values that are actually in the database.  

But, I can't figure out how to check to see if that particular item is in the database... I've pasted the code below and indicated where I'm having a problem.

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');

   $query = &quote;SELECT * FROM qtable WHERE id='$did'&quote;;
   $result = @mysql_query ($query);
 
   while($row=mysql_fetchckboxes.  Upon initial submission, the values of the checked boxes are stored as one variable via "implode" and placed into my database.  

In an effort to make the form editable (that is, a user can select/deselect boxes as they wish) , I've been trying to place "checked" inside the input tag for the values that are actually in the database.  

But, I can't figure out how to check to see if that particular item is in the database... I've pasted the code below and indicated where I'm having a problem.

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');

   $query = "SELECT * FROM qtable WHERE id='$did'";
   $result = @mysql_query ($query);
 
   while($row=mysql_fetch_array($result)) {
   $item=$row['items']; 
   $brd=$row['brand'];
   $st=$row['store'];
   } 

foreach ($array as $item) {

    if ( $item is in database)  // THIS IS WHERE I'M STUCK
         $chk = 'checked';
    else
         $chk = '';
    echo "<input type='checkbox' name='$itert to make the form editable (that is, a user can select/deselect boxes as they wish) , I've been trying to place "checked" inside the input tag for the values that are actually in the database.  

But, I can't figure out how to check to see if that particular item is in the database... I've pasted the code below and indicated where I'm having a problem.

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');

   $query = &quote;SELECT * FROM qtable WHERE id='$did'&quote;;
   $result = @mysql_query ($query);
 
   while($row=mysql_fetch_array($result)) {
   $item=$row&#1111;'items']; 
   $brd=$row&#1111;'brand'];
   $st=$row&#1111;'store'];
   } 

foreach ($array as $item) {

    if ( $item is in database)  // THIS IS WHERE I'M STUCK
         $chk = 'checked';
    else
         $chk = '';
    echo &quote;&lt;input type='checkbox' name='$item' value='1' $chk&a are actually in the database.  

But, I can't figure out how to check to see if that particular item is in the database... I've pasted the code below and indicated where I'm having a problem.

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');

   $query = "SELECT * FROM qtable WHERE id='$did'";
   $result = @mysql_query ($query);
 
   while($row=mysql_fetch_array($result)) {
   $item=$row['items']; 
   $brd=$row['brand'];
   $st=$row['store'];
   } 

foreach ($array as $item) m that has a number of checkboxes.  Upon initial submission, the values of the checked boxes are stored as one variable via "implode" and placed into my database.  

In an effort to make the form editable (that is, a user can select/deselect boxes as they wish) , I've been trying to place "checked" inside the input tag for the values that are actually in the database.  

But, I can't figure out how to check to see if that particular item is in the database... I've pasted the code below and indicated where I'm having a problem.

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');

   $query = "SELECT * FROM qtable WHERE id='$did'";
   $result = @mysql_query ($query);
 
   while($row=mysql_fetch_array($result)) {
   $item=$row['items']; 
   $brd=$row['brand'];
   $st=$row['store'];
   } 

foreach ($array as $item) {

    if ( $item is in database)  // THIS IS WHERE I'M STUCK
         $chk = 'checked';
    else
         $chk = '';
    echo "<input type='checkbox' name='$item' value='1' $chk> $item<br>";
}
lect boxes as they wish) , I've been trying to place "checked" inside the input tag for the values that are actually in the database.

But, I can't figure out how to check to see if that particular item is in the database... I've pasted the code below and indicated where I'm having a problem.

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');

   $query = &quote;SELECT * FROM qtable WHERE id='$did'&quote;;
   $result = @mysql_query ($query);
 
   while($row=mysql_fetch_array($result)) {
   $item=$row&#1111;'items']; 
   $brd=$row&#1111;'brand'];
   $st=$row&#1111;'store'];
   } 

foreach ($array as $item) {

    if ( $item is in database)  // THIS IS WHERE I'M STUCK
         $chk = 'checked';
    else
         $chk = '';
    echo &quote;&lt;input type='checkbox' name='$item' value='1' $chk&gt; $item&lt;br&gt;&quote;;
}abase.  

But, I can't figure out how to check to see if that particular item is in the database... I've pasted the code below and indicated where I'm having a problem.

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');

   $query = "SELECT * FROM qtable WHERE id='$did'";
   $result = @mysql_query ($query);
 
   while($row=mysql_fetch_array($result)) {
   $item=$row['items']; 
   $brd=$row['brand'];
   $st=$row['store'];
   } 

foreach ($array as $item) {

    if ( $item is in database)  // THIS IS WHERE I'M STUCK
         $chk = 'checked';
    else
         $chk = '';
    echo "<input type='checkbox' name='$item' value='1' $chk> $item<br>";
}
l_fetch_array($result)) {
$item=$row['items'];
$brd=$row['brand'];
$st=$row['store'];
}

foreach ($array as $item) {

if ( $item is in database) // THIS IS WHERE I'M STUCK
$chk = 'checked';
else
$chk = '';
echo "<input type='checkbox' name='$item' value='1' $chk> $item<br>";
}

he form editable (that is, a user can select/deselect boxes as they wish) , I've been trying to place "checked" inside the input tag for the values that are actually in the database.

But, I can't figure out how to check to see if that particular item is in the database... I've pasted the code below and indicated where I'm having a problem.

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');

   $query = &quote;SELECT * FROM qtable WHERE id='$did'&quote;;
   $result = @mysql_query ($query);
 
   while($row=mysql_fetch_array($result)) {
   $item=$row&#1111;'items']; 
   $brd=$row&#1111;'brand'];
   $st=$row&#1111;'store'];
   } 

foreach ($array as $item) {

    if ( $item is in database)  // THIS IS WHERE I'M STUCK
         $chk = 'checked';
 I've been trying to place "checked" inside the input tag for the values that are actually in the database.  

But, I can't figure out how to check to see if that particular item is in the database... I've pasted the code below and indicated where I'm having a problem.

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');

   $query = "SELECT * FROM qtable WHERE id='$did'";
   $result = @mysql_query ($query);
 
   while($row=mysql_fetch_array($result)) {
   $item=$row['items']; 
   $brd=$row['brand'];
   $st=$row['store'];
   } 

foreach ($array as $item) {

   

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');

   $query = "SELECT * FROM qtable WHERE id='$did'";
   $result = @mysql_query ($query);
 
   while($row=mysql_fetch_array($result)) {
   $item=$row['items']; 
   $brd=$row['brand'];
   $st=$row['store'];
   } 

foreach ($array as $item) {

    if ( $item is in database)  // THIS IS WHERE I'M STUCK
         $chk = 'checked';
    else
         $chk = '';
    echo "<input type='checkbox' name='$item' value='1' $chk> $item<br>";
}

Posted: Sat Jul 16, 2005 1:08 pm
by Burrito
for starters, you are resetting $item with each iteration of your while loop. Proably would be best to create an array and then add a new item to the array on each iteration.

then you can use array_search to see if the value of your foreach loop is in the array..

ex:

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');
 
   $query = "SELECT * FROM qtable WHERE id='$did'";
   $result = @mysql_query ($query);
   
   $item = array();
   while($row=mysql_fetch_array($result)) {
   $item[]=$row['items']; //this is now an array
   $brd=$row['brand'];
   $st=$row['store'];
   } 
 
foreach ($array as $items) {
 
    if ( array_search($items,$item))  
         $chk = 'checked';
    else
         $chk = '';
    echo "<input type='checkbox' name='$items' value='1' $chk> $items<br>";
}
teration of your while loop. Proably would be best to create an array and then add a new item to the array on each iteration.

then you can use array_search to see if the value of your foreach loop is in the array..

ex:

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');
 
   $query = &quote;SELECT * FROM qtable WHERE id='$did'&quote;;
   $result = @mysql_query ($query);
   
   $item = array();
   while($row=mysql_fetch_array($result)) {
   $item&#1111;]=$row&#1111;'items']; //this is now an array
   $brd=$row&#1111;'brand'];
   $st=$row&#1111;'store'];
   } 
 
foreach ($array as $items) {
 
    if ( array_search($items,$item))  
         $chk = 'checked';uld be best to create an array and then add a new item to the array on each iteration.

then you can use array_search to see if the value of your foreach loop is in the array..

ex:

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');
 
   $query = "SELECT * FROM qtable WHERE id='$did'";
   $result = @mysql_query ($query);
   
   $item = array();
   while($row=mysql_fetch_array($result)) {
   $item&#1111;]=$row&#1111;'items']; //this is now an array
   $brd=$row&#1111;'brand'];
   $st=$row&#1111;'store'];
   } 
m to the array on each iteration.

then you can use array_search to see if the value of your foreach loop is in the array..

ex:

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');
 
   $query = &quote;SELECT * FROM qtable WHERE id='$did'&quote;;
   $result = @mysql_query ($query);
   
   $item = array();
   while($row=mysql_fetch_array($result)) {
   $item&#1111;]=$row&#1111;'items']; //this is now an array
   $brd=$row&#1111;'brand'];
   $st=$row&#1111;'store'];
   } 
 
foreach ($array as $items) {
 
    if d then add a new item to the array on each iteration.

then you can use array_search to see if the value of your foreach loop is in the array..

ex:

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');
 
   $query = "SELECT * FROM qtable WHERE id='$did'";
   $result = @mysql_query ($query);
   
   $item = array();
   while($row=mysql_fetch_array($result)) {
   $item[]=$row['items']; //this is now an array
   $brd=$row['brand'];
   $st=$row['store'];
   } 
 
foreach are resetting $item with each iteration of your while loop.  Proably would be best to create an array and then add a new item to the array on each iteration.

then you can use array_search to see if the value of your foreach loop is in the array..

ex:

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');
 
   $query = &quote;SELECT * FROM qtable WHERE id='$did'&quote;;
   $result = @mysql_query ($query);
   
   $item = array();
   while($row=mysql_fetch_array($result)) {
   $item&#1111;]=$row&#1111;'items']; //this is now an array
   $brd=$row&#1111;'brand'];
   $st=$row&#1111;'store'];
   } 
 
foreach ($array as $items) {
 
    if ( array_search($items,$item))  
         $chk = 'checked';
    else
         $chk = '';
    echo &quote;&lt;input type='checkbox' name='$items' value='1' $chk&gt; $items&aare resetting $item with each iteration of your while loop.  Proably would be best to create an array and then add a new item to the array on each iteration.

then you can use array_search to see if the value of your foreach loop is in the array..

ex:

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');
 
   $query = "SELECT * FROM qtable WHERE id='$did'";
   $result = @mysql_query ($query);
   
   $item = array();
   while($row=mysql_fetch_array($result)) {
   $item[]=$row['items']; //this is now an array
   $brd=$row['brand'];
   $st=$row['store'];
   } 
 
foreach ($array as $items) {
 
    if ( array_search($items,$item))  
         $chk = 'checked';
    else
         $chk = '';
    echo "<input type='checkbox' name='$items' value='1' $chk> $items<br>";
}
111;'brand'];
$st=$row['store'];
}

foreach ($array as $items) {

if ( array_search($items,$item))
$chk = 'checked';
else
$chk = '';
echo "<input type='checkbox' name='$items' value='1' $chk> $items<br>";
}
name='$items' value='1' $chk> $items<br>";
}
ould be best to create an array and then add a new item to the array on each iteration.

then you can use array_search to see if the value of your foreach loop is in the array..

ex:

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');
 
   $query = "SELECT * FROM qtable WHERE id='$did'";
   $result = @mysql_query ($query);
   
   $item = array();
   while($row=mysql_fetch_array($result)) {
   $item[]=$row['items']; //this is now an array
   $brd=$row['brand'];
   $st=$row['store'];
   } 
 
foreach ($array as $items) {
 
    if ( array_search($items,$item))  
         $chk = 'checked';
    else
         $chk =an array and then add a new item to the array on each iteration.

then you can use array_search to see if the value of your foreach loop is in the array..

ex:

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');
 
   $query = "SELECT * FROM qtable WHERE id='$did'";
   $result = @mysql_query ($query);
   
   $item = array();
   while($row=mysql_fetch_array($resul of your while loop.  Proably would be best to create an array and then add a new item to the array on each iteration.

then you can use array_search to see if the value of your foreach loop is in the array..

ex:

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');
 
   $query = "SELECT * FROM qtable WHERE id='$did'";
   $result = @mysql_query ($query);
   
   $item = array();
   while($row=mysql_fetch_array($result)) {
   $item[]=$row['items']; //this is now an array
   $brd=$row['brand'];
   $st=$row['store'];
   } 
 
foreach ($array as $items) {
 
    if ( array_search($items,$item))  
         $chk = 'checked';
    else
         $chk = '';
    echo "<input type='checkbox' name='$items' value='1' $chk> $items<br>";
}
to see if the value of your foreach loop is in the array..

ex:

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');
 
   $query = "SELECT * FROM qtable WHERE id='$did'";
   $result = @mysql_query ($query);
   
   $item = array();
   while($row=mysql_fetch_array($result)) {
   $item&#1111;]=$row&#1111;'items']; //this is now an array
   $brd=$row&#1111;'brand'];
   $st=$row&#1111;'store'];
   } 
 
foreach ($array as $items) {
 
    if ( array_search($items,$item))  
         $chk = 'checked';
    else
         $chk = '';
    echo &quote;&lt;input type='checkbox' name='$items' value='1' $chk&ry = "SELECT * FROM qtable WHERE id='$did'";
   $result = @mysql_query ($query);
   
   $item = array();
   while($row=mysql_fetch_array($result)) {
   $item[]=$row['items']; //this is now an array
   $brd=$row['brand'];
   $st=$row['store'];
   } 
 
foreach ($array as $items) {
 
    if ( array_search($items,$item))  
         $chk = 'checked';
    else
         $chk = '';
    echo "<input type='checkbox' name='$items' value='1' $chk> $items<br>&quot $item with each iteration of your while loop.  Proably would be best to create an array and then add a new item to the array on each iteration.

then you can use array_search to see if the value of your foreach loop is in the array..

ex:

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');
 
   $query = "SELECT * FROM qtable WHERE id='$did'";
   $result = @mysql_query ($query);
   
   $item = array();
   while($row=mysql_fetch_array($result)) {
   $item[]=$row['items']; //this is now an array
   $brd=$row['brand'];
   $st=$row['store'];
   } 
 
foreach ($array as $items) {
 
    if ( array_search($items,$item))  
         $chk = 'checked';
    else
         $chk = '';
    echo "<input type='checkbox' name='$items' value='1' $chk> $items<br>";
}
ex:

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');
 
   $query = "SELECT * FROM qtable WHERE id='$did'";
   $result = @mysql_query ($query);
   
   $item = array();
   while($row=mysql_fetch_array($result)) {
   $item[]=$row['items']; //this is now an array
   $brd=$row['brand'];
   $st=$row['store'];
   } 
 
foreach ($array as $items) {
 
    if ( array_search($items,$item))  
         $chk = 'checked';
    else
         $chk = '';
    echo "<input type='checkbox' name='$items' value='1' $chk> $items<br>";
 FROM qtable WHERE id='$did'";
   $result = @mysql_query ($query);
   
   $item = array();
   while($row=mysql_fetch_array($result)) {
   $item[]=$row['items']; //this is now an array
   $brd=$row['brand'];
   $st=$row['store'];
   } 
 
foreach ($array as $items) {
 
    if ( array_search($items,$item))  
         $chk = 'checked';
    else
         $chk = '';
    echo "<input type='checkbox' name='$items' value='1' $chk> $items<br>";
}
$chk = '';
echo "<input type='checkbox' name='$items' value='1' $chk> $items<br>";
}
e value of your foreach loop is in the array..

ex:

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');
 
   $query = "SELECT * FROM qtable WHERE id='$did'";
   $result = @mysql_query ($query);
   
   $item = array();
   while($row=mysql_fetch_array($result)) {
   $item[]=$row['items']; //this is now an array
   $brd=$row['brand'];
   $st=$row['store'];
   } 
 
foreach ($array as $items) {
 
    if ( array_search($items,$item))  
         $chk = 'checked';

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');
 
   $query = "SELECT * FROM qtable WHERE id='$did'";
   $result = @mysql_query ($query);
   
   $item = array();
   while($row=mysql_fetch_array($result)) {
   $item[]=$row['items']; //this is now an array
   $brd=$row['brand'];
   $st=$row['store'];
   } 
 
foreach ($array as $items) {
 
    if ( array_search($items,$item))  
         $chk = 'checked';
    else
         $chk = '';
    echo "<input type='checkbox' name='$items' value='1' $chk> $items<br>";
}

Posted: Sun Jul 17, 2005 6:03 am
by phpScott
Almost it think big B.

I think you meant to suggest a explode()

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');
 
   $query = "SELECT * FROM qtable WHERE id='$did'";
   $result = @mysql_query ($query);
   
   $item = array();
   while($row=mysql_fetch_array($result)) {
   $item =explode("whatEverYouUsedToSeperateTheData" ,$row['items']); //this is now an array
   $brd=$row['brand'];
   $st=$row['store'];
   } 
 
foreach ($array as $items) {
 
    if ( array_search($items,$item))  
         $chk = 'checked';
    else
         $chk = '';
    echo "<input type='checkbox' name='$items' value='1' $chk> $items<br>";
}
ggest a explode()

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');
 
   $query = "SELECT * FROM qtable WHERE id='$did'";
   $result = @mysql_query ($query);
   
   $item = array();
   while($row=mysql_fetch_array($result)) {
   $item =explode(&quote;whatEverYouUsedToSeperateTheData&quote; ,$row&#1111;'items']); //this is now an array
   $brd=$row&#1111;'brand'];
   $st=$row&#1111;'store'];
   } 
 
foreach ($array as $items) {
 
    if ( array_search($items,$item))  
         $chk = 'checked';
$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');
 
   $query = "SELECT * FROM qtable WHERE id='$did'&quote;;
   $result = @mysql_query ($query);
   
   $item = array();
   while($row=mysql_fetch_array($result)) {
   $item =explode(&quote;whatEverYouUsedToSeperateTheData" ,$row['items']); //this is now an array
   $brd=$row&#1111;'brand'];
   $st=$row&#1111;'store'];
   } 
'Cookies');
 
   $query = "SELECT * FROM qtable WHERE id='$did'";
   $result = @mysql_query ($query);
   
   $item = array();
   while($row=mysql_fetch_array($result)) {
   $item =explode("whatEverYouUsedToSeperateTheData&quote; ,$row&#1111;'items']); //this is now an array
   $brd=$row&#1111;'brand'];
   $st=$row&#1111;'store'];
   } 
 
foreach ($array as $items) {
 
    if Bread', 'Lettuce' , 'Cookies');
 
   $query = "SELECT * FROM qtable WHERE id='$did'";
   $result = @mysql_query ($query);
   
   $item = array();
   while($row=mysql_fetch_array($result)) {
   $item =explode("whatEverYouUsedToSeperateTheData" ,$row['items']); //this is now an array
   $brd=$row['brand'];
   $st=$row['store'];
   } 
 
foreach ($array as $items) {
 
    if ( array_search($items,$item))  
         $chk = 'checked';
    else
         $chk = '';
    echo "&ag B.

I think you meant to suggest a explode()

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');
 
   $query = &quote;SELECT * FROM qtable WHERE id='$did'&quote;;
   $result = @mysql_query ($query);
   
   $item = array();
   while($row=mysql_fetch_array($result)) {
   $item =explode(&quote;whatEverYouUsedToSeperateTheData&quote; ,$row&#1111;'items']); //this is now an array
   $brd=$row&#1111;'brand'];
   $st=$row&#1111;'store'];
   } 
 
foreach ($array as $items) {
 
    if ( array_search($items,$item))  
         $chk = 'checked';
    else
         $chk = '';
    echo &quote;&lt;input type='checkbox' name='$items' value='1' $chk&gt; $items&ag B.

I think you meant to suggest a explode()

Code: Select all

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');
 
   $query = "SELECT * FROM qtable WHERE id='$did'";
   $result = @mysql_query ($query);
   
   $item = array();
   while($row=mysql_fetch_array($result)) {
   $item =explode("whatEverYouUsedToSeperateTheData" ,$row['items']); //this is now an array
   $brd=$row['brand'];
   $st=$row['store'];
   } 
 
foreach ($array as $items) {
 
    if ( array_search($items,$item))  
         $chk = 'checked';
    else
         $chk = '';
    echo "<input type='checkbox' name='$items' value='1' $chk> $items<br>";
}
d';
else
$chk = '';
echo "<input type='checkbox' name='$items' value='1' $chk> $items<br>";
}

$array = array('Milk', 'Eggs', 'Bread', 'Lettuce' , 'Cookies');

$query = "SELECT * FROM qtable WHERE id='$did'";
$result = @mysql_query ($query);

$item = array();
while($row=mysql_fetch_array($result)) {
$item =explode("whatEverYouUsedToSeperateTheData" ,$row['items']); //this is now an array
$brd=$row['brand'];
$st=$row['store'];
}

foreach ($array as $items) {

if ( array_search($items,$item))
$chk = 'checked';
else
$chk = '';
echo "<input type='checkbox' name='$items' value='1' $chk> $items<br>";
}

Posted: Sun Jul 17, 2005 7:38 am
by Burrito
naw, I meant it the way I had it. Exploding it will try to make it create a new array for each iteration of the loop whereas the way I had it will only add a new element to the array. He doesn't have the whole string built to explode it which is why I did it the way I did. He's looping over query results and just adding to the array with each iteration of the loop...

Posted: Sun Jul 17, 2005 3:16 pm
by phpScott
the reason I modified your code was because he stats
Upon initial submission, the values of the checked boxes are stored as one variable via "implode" and placed into my database.
therefore an explode(or some method) is needed to seperate the values back out.

Or maybe I'm missing something.

Posted: Sun Jul 17, 2005 3:23 pm
by Chris Corbyn
he/she :P