470,849 Members | 1,095 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

Checkbox and relational table

Hello,

I've a question regarding the checkbox.
I've a formular with a list of clients per work experience. I can have
several clients for a experience. So I have a table for "experience", one
for "client" and a relational table "rel_experience-client".
To retrieve the list of clients per work experience I use the query :
SELECT *
FROM experience, client, rel_experience_client
WHERE experience_ref=experience.id AND client_ref=client.id AND
experience_ref=12345
ORDER BY libelle


How can I retrive this information and add a checkbox on each client if they
are on the experience?
With the solution below, I can't find the ... solution!

Thx a lot for your help,
Regards, Dom
<?php require_once('../../../Connections/metadeco_connect.php'); ?>
<?php
mysql_select_db($database_metadeco_connect, $metadeco_connect);
$query_rs1experience = "SELECT * FROM experience";
$rs1experience = mysql_query($query_rs1experience, $metadeco_connect) or
die(mysql_error());
$row_rs1experience = mysql_fetch_assoc($rs1experience);
$totalRows_rs1experience = mysql_num_rows($rs1experience);

mysql_select_db($database_metadeco_connect, $metadeco_connect);
$query_rs4_rel_experience_client = "SELECT * FROM experience, client,
rel_experience_client WHERE experience_ref=experience.id AND
client_ref=client.id AND experience_ref=12345 ORDER BY libelle";
$rs4_rel_experience_client = mysql_query($query_rs4_rel_experience_client,
$metadeco_connect) or die(mysql_error());
$row_rs4_rel_experience_client =
mysql_fetch_assoc($rs4_rel_experience_client);
$totalRows_rs4_rel_experience_client =
mysql_num_rows($rs4_rel_experience_client);

mysql_select_db($database_metadeco_connect, $metadeco_connect);
$query_rs7client = "SELECT * FROM client ORDER BY libelle ASC";
$rs7client = mysql_query($query_rs7client, $metadeco_connect) or
die(mysql_error());
$row_rs7client = mysql_fetch_assoc($rs7client);
$totalRows_rs7client = mysql_num_rows($rs7client);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body><form name="form1" method="post" action="">

<?php
if ($totalRows_rs7client>0) {
$nested_query_rs7client = str_replace("12345", $row_rs7client['id'],
$query_rs7client);
mysql_select_db($database_metadeco_connect);
$rs7client = mysql_query($nested_query_rs7client, $metadeco_connect) or
die(mysql_error());
$row_rs7client = mysql_fetch_assoc($rs7client);
$totalRows_rs7client = mysql_num_rows($rs7client);
$nested_sw = false;
if (isset($row_rs7client) && is_array($row_rs7client)) {
do { //Nested repeat
?>
<input <?php if
(!(strcmp($row_rs1experience['id'],$row_rs7client['id']))) {echo "checked";}
?> name="checkbox_client" type="checkbox" id="checkbox_client" value="<?php
echo $row_rs7client['id']; ?>">
<?php echo $row_rs7client['libelle']; ?><br>
<?php
} while ($row_rs7client = mysql_fetch_assoc($rs7client)); //Nested
move next
}
}
?>
<br>

<input type="submit" name="Submit" value="Submit">

</form>
</body>
</html>
<?php
mysql_free_result($rs1experience);
mysql_free_result($rs4_rel_experience_client);
mysql_free_result($rs7client);
?>
Jul 17 '05 #1
1 1639
Dominique Javet wrote:
I've a question regarding the checkbox.
I've a formular with a list of clients per work experience. I can have
several clients for a experience. So I have a table for "experience", one
for "client" and a relational table "rel_experience-client".
To retrieve the list of clients per work experience I use the query :
SELECT *
FROM experience, client, rel_experience_client
WHERE experience_ref=experience.id AND client_ref=client.id AND
experience_ref=12345
ORDER BY libelle


How can I retrive this information and add a checkbox on each client if they
are on the experience?
With the solution below, I can't find the ... solution!
<?php require_once('../../../Connections/metadeco_connect.php'); ?> .... $query_rs7client = "SELECT * FROM client ORDER BY libelle ASC";
$rs7client = mysql_query($query_rs7client, $metadeco_connect) or die(mysql_error()); .... if ($totalRows_rs7client>0) {
$nested_query_rs7client = str_replace("12345", $row_rs7client['id'], $query_rs7client);


There's no "12345" in $query_rs7client
That last statement will always do:
$nested_query_rs7client = $query_rs7client;
Instead of (or besides) doing a mysql_query($sql, $connection) do a
print($sql) to check what your script is doing.

(snip rest of code)
I think you should first get your data right (check with print_r());
then put it into HTML with checkbox and whatnot.

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by claudel | last post: by
3 posts views Thread by Mikey | last post: by
49 posts views Thread by Mike MacSween | last post: by
1 post views Thread by Tim Fierro | last post: by
3 posts views Thread by Robert Abi Saab | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.