Ok sounds good.
Now, you know you can only "higlight" one item from a select list right?
MySQL PHP joining tables and querying both for checkbox aray
Moderator: General Moderators
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: MySQL PHP joining tables and querying both for checkbox aray
Nope - our existing Intranet uses a 'multiple' 'select' and when loaded up, it has several highlighted.
And you can highlight more than one manually by holding CTRL down.
And you can highlight more than one manually by holding CTRL down.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: MySQL PHP joining tables and querying both for checkbox aray
Here's a script I made with Dreamweaver to show you how it should look using peoples' names.
Your 'selected' script is meant to assign "selected="selected"" to each one that it finds in the other table.
We are so close to making this work. Thank you for your help today, and I hope you return so we can get it working properly.
Simon
Code: Select all
<select name="select" multiple="multiple">
<option value="bob" selected="selected">bob</option>
<option value="tim">tim</option>
<option value="katie" selected="selected">katie</option>
<option value="mark">mark</option>
</select>We are so close to making this work. Thank you for your help today, and I hope you return so we can get it working properly.
Simon
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: MySQL PHP joining tables and querying both for checkbox aray
I've been working late this evening and worked out quite a bit:
This does produce a multiple entry list box. And it highlights three sections, and based on their position, they are 'Accident', 'Commercial' and 'Finance'.....however, it is not rendering the listed words from 'dept'. It also works with checkboxes, but the same problem - not values or rendered words from dept.
I'm doing something very slightly wrong now.... something *so* slightly it's gonna be a silly mistake.
Can you help?
Code: Select all
<select name="select" multiple="multiple">
<?php
$selected='selected="selected"';
$sqlconn=@mysql_connect("localhost","user","pass");
$rs=@mysql_select_db("dbname",$sqlconn);
$result = mysql_query ("SELECT * FROM intradept, intrastaff WHERE intrastaff.id = '$id' ORDER BY dept");
if (mysql_num_rows($result) == 0) { echo "error"; } else
{
while ($row = mysql_fetch_array($result)) {
if (stripos($row['OtherDept'],$row['dept'])!==false)
{ echo "<option value='$row->dept' selected=\"selected\">$row->dept</option>";}
else
{ echo "<option value='$row->dept'>$row->dept</option>";}
}}
?>
</select>I'm doing something very slightly wrong now.... something *so* slightly it's gonna be a silly mistake.
Can you help?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: MySQL PHP joining tables and querying both for checkbox aray
Hi all
I have finally cracked it, and after all the efforts people have very kindly put in to help me, I thought I would post the result that works:
Now I just have to get it to post to the following page, but I think that's just posting the dept[] value from the SELECT name.
Cheers
Simon

I have finally cracked it, and after all the efforts people have very kindly put in to help me, I thought I would post the result that works:
Code: Select all
<select name="select" multiple="multiple" style="height:100px;" class="bodytext">
<?php
$selected='selected="selected"';
$sqlconn=@mysql_connect("localhost","user","pass");
$rs=@mysql_select_db("dbname",$sqlconn);
$result = mysql_query ("SELECT * FROM intradept, intrastaff WHERE intrastaff.id = '$id' ORDER BY
dept");
if (mysql_num_rows($result) == 0) { echo "error"; } else
{
while ($row = mysql_fetch_array($result)) {
if (stripos($row['OtherDept'],$row['dept'])!==false)
{ echo "<option value='";
echo $row['dept'];
echo " selected='selected'>";
echo $row['dept'];
echo "</option>";
}
else
{
echo "<option value='";
echo $row['dept'];
echo "'>";
echo $row['dept'];
echo "</option>";}
}}
?>
</select>Cheers
Simon
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.