Hello guys
I have a small problem and please help to resolve this.
I have associated categories in the database. During the edit, i need, that
categories which were checked when first somebody added his/her info that categories to be selected...
In my picture is described what i want to do.
http://img18.imageshack.us/img18/3104/capqy.jpg
Thanks for advice...
And here is my code
PHP Code:<?php
include ("db.php");
if (isset($_GET['id'])) {$id = $_GET['id'];}
if (!isset($id))
{
$result = mysql_query("SELECT id, name, sur FROM info");
$myrow = mysql_fetch_array($result);
do
{
printf ("<p style='float:left; margin-left:6px;'> <a href='edit.php?id=%s'>%s</a> |</p>",$myrow["id"],$myrow["name"]);
}
while ($myrow = mysql_fetch_array($result));
}
else
{
$result2 = mysql_query("SELECT * FROM info WHERE id=$id");
$myrow2 = mysql_fetch_array($result2);
$sql = "SELECT cat_id, cat_name FROM category";
$res = mysql_query($sql) or die(mysql_error());
$checkboxes = '';
while (list($id, $cat) = mysql_fetch_row($res)) {
$checkboxes .= "<input type='checkbox' name='category[]' value='$id' /> $cat<br />";
}
print <<<HERE
<form method = 'post' action = 'update.php' >
Name: <input type='text' name='name' value="$myrow2[name]" size='50' /><br />
Surname: <input type='text' name='sur' value="$myrow2[sur]" size='50' /><br />
Categories:<br />
$checkboxes
<input type='submit' name='btnSubmit' value='Submit' />
</form>
HERE;
}
?>


Reply With Quote
Bookmarks