PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Otherwise, if the first iteration returns false the echo will try to display an unset $selected.
But more importantly than that little nitpick, I'm still not entirely sure that the correct data is being returned. I think you should find out exactly what that query is returning before getting too bogged down in the display side of things (though aceconcept's code should do it nicely if the data IS correct).
$result = mysql_query ("SELECT * FROM intradept, intrastaff WHERE intrastaff.id = '$id' ORDER BY
dept");
if (mysql_num_rows($result) > 0)
{
while ($row = mysql_fetch_object($result)) {
if(stristr($row->dept, $row->OtherDept))
{
$selected='select="selected"';
}
echo '<option class="bodytext" value="'.$row->dept.'" '.$selected.'>'.$row->dept.'</option>';
$selected="";
}}
?>
</select>
I've fixed the error, but this isn't highlighting anything, and the 'id' entry I am looking for has three entries in OtherDept that should be highlighting in this list.
So close I'm clenches my fists.....
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
$result = mysql_query ("SELECT * FROM intradept, intrastaff WHERE intrastaff.id = '$id' ORDER BY
dept");
if (mysql_num_rows($result) > 0)
{
while ($row = mysql_fetch_array($result)) {
if(stristr($row['dept'], $row['OtherDept'])===TRUE)
{
$selected='selected="selected"';
}
echo '<option class="bodytext" value="'.$row->dept.'" '.$selected.'>'.$row->dept.'</option>';
$selected="";
}}
?>
</select>
I'm getting an empty list of nothing now.
I think I can see that you've used ['asdf'] as you are using "array". I did try it with $row->asdf but it didn't like it.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
I was just wondering if this would work, as the stristr might be the wrong way around.
As I am looking in intrastaff.OtherDept for the content of intradept.dept.
However, this too only renders a full list from intradept.dept with nothing selected.
$result = mysql_query ("SELECT * FROM intradept, intrastaff WHERE intrastaff.id = '$id' ORDER BY dept");
if (mysql_num_rows($result) > 0)
{
while ($row = mysql_fetch_array($result))
{
if(stristr($row['dept'], $row['OtherDept'])===TRUE)
{
$selected='selected="selected"';
}
echo '<option class="bodytext" value="'.$row["dept"].'"'.$selected.'>'.$row["dept"].'</option>';
$selected="";
}
}
?>
</select>
This is highlighting "Accident". There are three other 'dept' in the field that should be highlighted, so I am now even closer.
Any idea why it's only highlighting that one? fyi The field is written like so:
Company Commercial, Finance, Accident
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.