Add static text to top of select box populated from database

Hi,
     I have a select dropdown box which gets populated from a field in my database, this is the code which populates it:

<?php
echo "<select name='DoctorID' size='1' style='font-family: Arial; font-size: 20pt; border:solid 1px #000000; border-width: 1px>";
   
   while ($list = mysql_fetch_assoc($result)) {
echo "<option value='test'>test</option>";	
	$doctors = array_filter( explode(",", $list['Doctors']), 'strlen' );
      
      foreach($doctors as $docs) {
         echo "<option value='$docs'>$docs</option>";
      } // end foreach Doctors

   } // end while 
echo "</select>";?>

Open in new window


This works fine, but I want to add a static line of text at the top, something along the lines of:

--- Click to select your doctor ---

How can I achieve this?

Thanks
damianb123Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Marco GasiFreelancerCommented:
A simplest thing: add the option before to enter the loop:
<?php
echo "<select name='DoctorID' size='1' style='font-family: Arial; font-size: 20pt; border:solid 1px #000000; border-width: 1px>";
   echo "<option>--- Click to select your doctor ---</option>";	
   while ($list = mysql_fetch_assoc($result)) {
echo "<option value='test'>test</option>";	
	$doctors = array_filter( explode(",", $list['Doctors']), 'strlen' );
      
      foreach($doctors as $docs) {
         echo "<option value='$docs'>$docs</option>";
      } // end foreach Doctors

   } // end while 
echo "</select>";?>
                                  

Open in new window

0
damianb123Author Commented:
Hi Marco,
      That's what i thought too, but for some reason that line just fails to show, only the looped contents appear, as if that new line wasn't present :-\

Damian
0
Marco GasiFreelancerCommented:
Mmmhh, that's strange... Can I see the full code?
0
Acronis Data Cloud 7.8 Enhances Cyber Protection

A closer look at five essential enhancements that benefit end-users and help MSPs take their cloud data protection business further.

damianb123Author Commented:
Sure, he goes:

$sql = "SELECT * FROM gpw_maindata ORDER BY Doctors ASC";
$result = mysql_query($sql) or die(mysql_error()); 

<div align="center">
<form method="get" action="http://mydomain.co.uk/gpw-results.php">
<?php
echo "<select name='DoctorID' size='1' style='font-family: Arial; font-size: 20pt; border:solid 1px #000000; border-width: 1px>";
   echo "<option value='Please Select Doctor'>--- Click to select your doctor ---</option>";
   while ($list = mysql_fetch_assoc($result)) {

	$doctors = array_filter( explode(",", $list['Doctors']), 'strlen' );
       // echo "<option value='test'>test</option>";	      
      foreach($doctors as $docs) {
         echo "<option value='$docs'>$docs</option>";
      } // end foreach Doctors

   } // end while 
echo "</select>";
?>&nbsp;&nbsp;&nbsp;&nbsp;<input id="submit" name="submit" type="submit" value="Search" />

</div>

</form>

Open in new window

0
Marco GasiFreelancerCommented:
I don't see anything wrong. What happens if you comment out the loop?
$sql = "SELECT * FROM gpw_maindata ORDER BY Doctors ASC";
$result = mysql_query($sql) or die(mysql_error()); 

<div align="center">
<form method="get" action="http://mydomain.co.uk/gpw-results.php">
<?php
echo "<select name='DoctorID' size='1' style='font-family: Arial; font-size: 20pt; border:solid 1px #000000; border-width: 1px>";
   echo "<option value='Please Select Doctor'>--- Click to select your doctor ---</option>";
   while ($list = mysql_fetch_assoc($result)) {

//	$doctors = array_filter( explode(",", $list['Doctors']), 'strlen' );
       // echo "<option value='test'>test</option>";	      
      foreach($doctors as $docs) {
   //      echo "<option value='$docs'>$docs</option>";
      } // end foreach Doctors

   } // end while 
echo "</select>";
?>&nbsp;&nbsp;&nbsp;&nbsp;<input id="submit" name="submit" type="submit" value="Search" />

</div>

</form>
                                          

Open in new window

0
Marco GasiFreelancerCommented:
Found! You miss a single quote to close the (deprecated) inline style. Put a single quote after

border-width: 1px

And it will work
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
damianb123Author Commented:
Thanks so much.... it does indeed work :-)  Amazing what a second pair of eyes looking can find.

Thanks my friend.
0
Marco GasiFreelancerCommented:
Anyway, let me say that:

 - you're still using MySql. It's franly ununderstandable the way many still ignore the official Php site reccomandations. MySql extension is deprecated and it will cease to work soon. Migrate now to mysqli or PDO: it's not so difficult as you could think: move, go on.

 - your problem shows perfectly one of the reasons to never use inline styles: you can forget a damned quote and become crazy before to understand why your code doesn't work :-) This should never happened if you had an external css file.

- use better the alternance between php and html.
<?php
$sql = "SELECT * FROM gpw_maindata ORDER BY Doctors ASC";
$result = mysql_query($sql) or die(mysql_error()); 
?>
<div align="center">
<form method="get" action="http://mydomain.co.uk/gpw-results.php">
<select name='DoctorID' size='1' style='font-family: Arial; font-size: 20pt; border:solid 1px #000000; border-width: 1px'>
  <option value='Please Select Doctor'>--- Click to select your doctor ---</option>
<?php
   while ($list = mysql_fetch_assoc($result)) {

		$doctors = array_filter( explode(",", $list['Doctors']), 'strlen' );
      foreach($doctors as $docs) {
         echo "<option value='$docs'>$docs</option>";
      } // end foreach Doctors
   } // end while 
?>
 </select>
&nbsp;&nbsp;&nbsp;&nbsp;<input id="submit" name="submit" type="submit" value="Search" />
</form>
</div>

Open in new window


Please not that this way I noticed another error: you were closing the div open after the form before to close the form.

- <div align="center"> Are you preparing HTML6? This attribute doesn't exist. As minimum, you should U(but you don't should do it) write <div style="text-align='center'">

Good luck for your project and forgive me for my tricks :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.