Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Oct 2009
    Posts
    438
    Thanks
    9
    Thanked 7 Times in 7 Posts

    Select and Selected

    All,
    I have the following code:
    PHP 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.

  • #2
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    What does your output look like in view source?
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #3
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,493
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    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']){

  • #4
    Regular Coder
    Join Date
    Oct 2009
    Posts
    438
    Thanks
    9
    Thanked 7 Times in 7 Posts
    That was it. Sorry for bothering you with stupid spelling errors.

  • #5
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Nice spot mlseim! Your eyesight is impeccable
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •