Jump to content

Jessica

Staff Alumni
  • Posts

    8,968
  • Joined

  • Last visited

  • Days Won

    41

Posts posted by Jessica

  1. For one thing, you should use && not "and".

     

    Your code is very hard to read the way you have it, plus it's invalid HTML. Let's clean it up. You kind of have your use of quotes backwards too. In PHP "" is a interpolated string, and '' is not. Use '' when you don't have variables inside the string.

    <?php
    $value = $row_list['parentID'];
    $text = $row_list['parentOneFirstName'] . '  ' . $row_list['parentOneLastName'];
    if(!empty($row_list['parentTwoFirstName'])){ // If the first name is empty, would the last name ever have a value? If so, add your && in here.
       $text .= ' & '.$row_list['parentTwoFirstName'] . ' ' . $row_list['parentTwoLastName'];
    }
    echo '<option value="' . $value . '">' . $text . '</option>';
    
    You could make it even easier and cleaner by putting the parents names into an array when you get the info from the database, and using implode. It would look something like this.

    <?php
    $value = $row_list['parentID'];
    $text = implode(' & ', $row_list['parents_names']);
    echo '<option value="' . $value . '">' . $text . '</option>';
    
  2. I don't really learn by reading books so I can't. However there is a thread somewhere here with a list of good ones.

    The PHP manual is very useful. Follow their examples, read the comments, read the manual pages about all the basics.

     

    It would look less messy if you don't start/stop PHP all the time.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.