...

View Full Version : Select and Selected



treeleaf20
01-12-2010, 05:33 PM
All,
I have the following code:



<?php
$qrypic = "Select * from pictures where picture_id='$picid'";
$resultpic = mysql_query($qrypic);
$resultsetpic = mysql_fetch_array($resultpic);
?>

<select name="job">
<?php
$qryjobs = "Select job_id, name from jobs order by name ASC";
$resultjobs = mysql_query($qryjobs);
while($resultsetjobs = mysql_fetch_array($resultjobs)){
if($resulsetjobs['job_id'] == $resultsetpic['job_id']){
?>
<option value="<?php echo $resultsetjobs['job_id']; ?>" selected><?php echo $resultsetjobs['name']; ?></option>
<?php
}else{
?>
<option value="<?php echo $resultsetjobs['job_id']; ?>"><?php echo $resultsetjobs['name']; ?></option>
<?php
}
}
?>
</select>


It should make the row that matches selected but for some reason it's not working. Can anyone see what I'm doing wrong?

Thanks in advance.

JAY6390
01-12-2010, 05:39 PM
What does your output look like in view source?

mlseim
01-12-2010, 05:40 PM
This is one problem .... see missing red letter ...

if($resultsetjobs['job_id'] == $resultsetpic['job_id']){

But I would also say ... unless there is only one $resultsetpic['job_id'],
it will never be equal. So, check and see what it is by using an echo ...
See what those array variables hold.

echo $resultsetpic['job_id'];
echo $resultsetjobs['job_id']."<br>";
if($resultsetjobs['job_id'] == $resultsetpic['job_id']){

treeleaf20
01-12-2010, 05:42 PM
That was it. Sorry for bothering you with stupid spelling errors.

JAY6390
01-12-2010, 05:44 PM
Nice spot mlseim! Your eyesight is impeccable :p



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum