returning html from function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
taldos
Forum Commoner
Posts: 39
Joined: Mon Aug 23, 2004 8:47 am
Location: Philadelphia

returning html from function

Post by taldos »

K, heres the scenario.

I am trying to develop a ranking system which is driven by a drop down menu. This is for the back end administrative control, to allow the admin to rank users. Ther persons name is displayed along with their current rank, and there is to be a drop down menu which allows the admin to select the rank.

Since the user base will be expanding I want to dynamically create the html code for the drop down menu to allow the admin to rank the growing number of users.

I have the following code in my functions file:

Code: Select all

function ranking_menu($id, $num_rows)
{
	return
	(
		"<select name=".$id." size='1'>"
		for($i=1; $i<=$num_rows; $i++)
		&#123;
			"<option value=".$i.">".$i."</option>"
		&#125;
		"</select>"
	);
&#125;
And I call the function as follows.

Code: Select all

while ($row = mysql_fetch_array($result)) 
&#123;
    $t->set_var(array("DROP_MENU" => ranking_menu($row&#1111;'id'], $num_rows)));
	&#125;
The $num_rows if the number of rows selected from the DB.

when I run the script I get an error from the function itself. I am fairly certain that it is something simple such as adding "." for the proper text concatenation but I am stumped,

any help appreciated.

Best,

Ed.
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

try it like

Code: Select all

<?php
function ranking_menu($id, $num_rows)
{
    $output = "<select name=".$id." size='1'>";
    for($i=1; $i<=$num_rows; $i++)
    {
       $output.= "<option value=".$i.">".$i."</option>";
    }
     $output.= "</select>";
     return $output;
} 

?>
taldos
Forum Commoner
Posts: 39
Joined: Mon Aug 23, 2004 8:47 am
Location: Philadelphia

Post by taldos »

Thank a lot, that seems works. Would have never though of just that. Still don't know why the it didn't work, but if ain't broke don't fix it. Thanks again.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it didn't work because your code had illegal calls in the return.
Post Reply