Jump to content

Recommended Posts

Here is my problem, I need this function to be part of a string of outputs.

$output = "Html" //etc

$output .= "select";

$output .= attending($total_people);

However, it only returns 1 of the 9 supposed values for the select box.

 

<?php
function attending($var) {
$hour = range(1,9);
foreach ($hour as $h) { 
	if($var == $h) { $selected = "selected"; }
	else { $selected = ""; }
	return "<option {$selected} value=\"{$h}\"> {$h} </option>";
}
}	
?>

 

If I use "echo" instead of "return" it does give me all 9 outputs, but then I cannot make the form dynimically through the $output variable.

 

Any help is appreciated.

 

Thank you.

Thank you!

 

That did the trick - quick question though.

Why does doing $html = (no .= ) cause it to break?

 

More over, why does declaring $html before that loop cause it to break too?

 

 

I had to declare $html up with the $hour array, and leave as is to make PHP happy.

 

Just trying to understand what PHP is doing here.

 

Thanks again.

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.