Page 1 of 1

returning html from function

Posted: Sun Aug 29, 2004 4:08 pm
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.

Posted: Sun Aug 29, 2004 4:28 pm
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;
} 

?>

Posted: Sun Aug 29, 2004 4:36 pm
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.

Posted: Sun Aug 29, 2004 4:54 pm
by feyd
it didn't work because your code had illegal calls in the return.