Page 4 of 4

Re: MySQL PHP joining tables and querying both for checkbox aray

Posted: Wed Oct 15, 2008 11:08 am
by aceconcepts
Ok sounds good.

Now, you know you can only "higlight" one item from a select list right?

Re: MySQL PHP joining tables and querying both for checkbox aray

Posted: Wed Oct 15, 2008 12:33 pm
by simonmlewis
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.

Re: MySQL PHP joining tables and querying both for checkbox aray

Posted: Wed Oct 15, 2008 2:00 pm
by simonmlewis
Here's a script I made with Dreamweaver to show you how it should look using peoples' names.

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>
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

Re: MySQL PHP joining tables and querying both for checkbox aray

Posted: Wed Oct 15, 2008 4:12 pm
by simonmlewis
I've been working late this evening and worked out quite a bit:

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>
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?

Re: MySQL PHP joining tables and querying both for checkbox aray

Posted: Thu Oct 16, 2008 3:24 am
by simonmlewis
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:

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>
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
:D :D