Forum Moderators: coopster
I know this can be done, and I obviously have something simple wrong here, but I am trying to call a function to populate a dropdown box on a form. This is an edit page and the dropdown may already have a value from the DB in some cases. So the function will address that. Problem here is , that for some reason I can't even get the function to call. The table code for this particular area is as follows:
<?php
Some code...
<tr>
<td colspan="2"><label for="favline">Favorite Line:</label></td>
<td colspan="2"><name="favline" id="favline"/> displayvalues(favline,$FavLine,DBLine,Line) </td>
</tr>
...More code...
?>
This is the function being called...
function displayvalues($dropdownname,$dropdownvalue,$tablename,$columnname)
{
db_connect();
$result = mysql_query("Select * from " . $tablename . mysql_error());
if (!$result)
{
die('Invalid formation of select query in displayvalues(): ' . mysql_error());
}
echo "<select name=" . $dropdownname . ">";
while ($row = mysql_fetch_array($result, MYSQL_BOTH))
{
if ($row[0] == $dropdownvalue)
{
echo "<option value=" . $row[1] . " SELECTED>" . $row[1] . "</option>";
}
else
{
echo "<option value=" . $row[1] . ">" . $row[1] . "</option>";
}
}
echo "</select>";
mysql_free_result($result);
mysql_close();
}
?>
When this displays on the page, it actually just prints the call to the function...
Favorite Line: displayvalues(favline,$FavLine,CruiseLine,Line)
So, any help or pointers would be greatly appreciated.
Something like:
<?php
Some code...
<tr>
echo "<td colspan=\"2\"><label for=\"favline\">Favorite Line:</label></td>\n";
echo "<td colspan=\"2\"><name=\"favline\" id=\"favline\"/>".displayvalues(favline,$FavLine,DBLine,Line)."</td>\n";
echo "</tr>\n";
...More code...
?>
(Note: above sample done fast, not tested!)
<tr>
<td colspan="2"><label for="favline">Favorite Line:</label></td>
<td colspan="2"><input type="text" name="favline" id="favline" size="15" value="' . $row['FavLine'] . '" /></td>
</tr>
This works, but when I remove the "input type" and try to call the function, it fails. I guess my better question is why does it work this way yet the function call doesn't work?
Good:
<?
echo '<html><body><h1>' . get_page_title($page_id) . '</h1></body></html>';
?>
Good:
<html><body><h1>
<? echo get_page_title($page_id);?>
</h1></body></html>
Bad:
<?
'<html><body><h1>' . get_page_title($page_id) . '</h1></body></html>';
?>
Bad:
<?
<html><body><h1>
echo get_page_title($page_id)
</h1></body></html>
?>