damianb123
asked on
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:
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
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>";?>
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
ASKER
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
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
Mmmhh, that's strange... Can I see the full code?
ASKER
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>";
?> <input id="submit" name="submit" type="submit" value="Search" />
</div>
</form>
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>";
?> <input id="submit" name="submit" type="submit" value="Search" />
</div>
</form>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks so much.... it does indeed work :-) Amazing what a second pair of eyes looking can find.
Thanks my friend.
Thanks my friend.
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.
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 :-)
- 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>
<input id="submit" name="submit" type="submit" value="Search" />
</form>
</div>
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 :-)
Open in new window