Welcome to WebmasterWorld Guest from 34.204.194.190

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Function Calls from within an HTML Table

This is annoying for me, but simple for most...

     
3:13 pm on Jul 25, 2004 (gmt 0)

New User

10+ Year Member

joined:June 5, 2004
posts:10
votes: 0


Hi again all...

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.

4:22 pm on July 25, 2004 (gmt 0)

Junior Member

10+ Year Member

joined:July 29, 2003
posts:72
votes: 0


Try -

<td colspan="2"><name="favline" id="favline"/> <?php displayvalues(favline,$FavLine,DBLine,Line);?> </td>

Robin

4:36 pm on July 25, 2004 (gmt 0)

New User

10+ Year Member

joined:June 5, 2004
posts:10
votes: 0


I thought you had something there for a minute. I noticed I missed the ";" at the end, but that wasn't it either. I didn't need the <?php and?> as the entire section is inside of the php handles.

Back to square one...

4:47 pm on July 25, 2004 (gmt 0)

Senior Member from CA 

WebmasterWorld Senior Member encyclo is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 31, 2003
posts:9074
votes: 6


You can't just place raw HTML markup inside a PHP code block - you will either need to close the code block before the <tr> and use another block for the function in the HTML, or you need to echo the entire HTML block.

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!)

12:15 am on July 27, 2004 (gmt 0)

New User

10+ Year Member

joined:June 5, 2004
posts:10
votes: 0


OK, I'm fairly new to this so now I'm a bit confused. Currently, the page has HTML code inside the PHP handles and I currently populate a text box with a variable out of the DB through the query.

<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?

12:29 am on July 27, 2004 (gmt 0)

Senior Member

WebmasterWorld Senior Member ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Apr 25, 2002
posts:8637
votes: 283


A little hard to tell, but I'm guessing that you are basically using a big long string that includes html and php. PHP will od some string substitution, so some variables may work, but you can't have a function in a quoted string.

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>
?>

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members