Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

editing db with checkboxes 2

Status
Not open for further replies.

dunskii

Programmer
Sep 14, 2001
107
AU
Hi there,

I'm trying to to have an edit page where some data is collect via check boxes.

how do you check the boxes that have previously been checked and storded in the db.

I have a table for the admissions and one for the employees which are joined by bar_admis, this contains the id from both tables

This is how i am trying to do it.

<td><input type=&quot;checkbox&quot; name=&quot;<? echo($myrow[&quot;admissions.admis_id&quot;]); ?>&quot; <? if ($myrow[&quot;bar_admis.bar_id&quot;]) != 0 { echo (&quot;checked&quot;);} ?>><span class=&quot;text&quot;><? echo($myrow[&quot;admissions.admission&quot;]); ?></span></td>

but i keep getting a parse error.

thanks again,

dunskii
 
thanks for that i think i was up a bit late last night,

when i awoke this morning there are no check boxes showing, but there is also no error, do you have any idea what i would be missing

thanks again

dunskii
 
without an example is hard to help you ... give me the code (only for the checks) and the output.
Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Hello!

Here's an example with mysql and checkboxes - it works fine for me, but i am no professional...

Code:
<?php

include &quot;db.inc&quot;; 
/*opens mysql connection, sends query and returns 
link to result*/

function ShowLinkTable($cat=1) {
   ?>
   <form action='links.php' method='post'>
   <table cellspacing=0 cellpadding=0 border=0>
   <tr>
      <td>description</td>
      <td>link</td>
      <td>date</td>
      <td>delete?</td>
   </tr>
   <?
   
   $query= &quot;SELECT cat, link, description, date, link_id&quot;;
   $query.=&quot; FROM links&quot;;
   $query.=&quot; WHERE cat=$cat&quot;;
   $query.=&quot; ORDER BY date DESC&quot;;
      
   $result=DB_SendQuery($query);
   $numrows=mysql_num_rows($result);
      
   for($i=0;$i<$numrows;$i++)   {
      $row=mysql_fetch_array($result);
      echo &quot;\n&quot;;
      echo &quot;<tr>\n&quot;;
      echo &quot;<td>$row[description]</td>\n&quot;;
      echo &quot;<td nowrap><a href='redirect.php?url=&quot;;
      echo &quot;$row[link]&id=$row[link_id]' &quot;;
      echo &quot;target='_blank'>$row[link]</a></td>\n&quot;;
      echo &quot;<td>$row[date]</td>\n&quot;;
      echo &quot;<td>&quot;;
[tt]echo &quot;<input type='checkbox' name='checkbox[]'&quot;;
echo &quot; value='$row[link_id]'>
[/tt]
Code:
</td>\n</tr>\n&quot;;
   }
   echo &quot;</table>\n&quot;;
   echo &quot;<input type='submit' name='del'&quot;;
   echo &quot; value='delete'></form>\n&quot;;
   mysql_close();
}


function DeleteLinks($checkbox) {
[tt]reset ($checkbox);
while (list(, $value) = each ($checkbox)) {
//loop through checkbox-array
$string.=&quot; link_id=&quot;.$value.&quot; OR &quot;;
}
[/tt]
Code:
   $query2=substr($string,0,-3); 
   //removes last OR (which is too much)
   
   $query=&quot;DELETE&quot;;
   $query.=&quot; FROM links&quot;;
   $query.=&quot; WHERE&quot;.$query2;

   $result=DB_SendQuery($query);
   unset($checkbox);
   mysql_close();
}


### Main ###

if (isset($checkbox))  {
   DeleteLinks($checkbox);
   ShowLinkTable();
}
else  {
   if (isset($cat))  {
      ShowLinkTable($cat);
   }
   else  {
      ShowLinkTable();
   }
}

?>

Hope this helps!


cheers

Thomas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top