Page 1 of 1

While loops in a variable?

Posted: Mon Oct 09, 2006 4:54 pm
by ab0x
OK, so I have a form that changes based on URL parameters. To do this I put the entire form in its own variable. I looks like this at the moment:

Code: Select all

$displayForm = '<form action="'.$formAction.'" method="post" name="editforum" id="editforum">
	<h3>Forum category</h3>
	<p><select name="category_id">
	
	</select></p>
	<h3>Forum name</h3>
	<p>What would you like the forum to be called?</p>
	<p><input name="forum_name" type="text" id="forum_name" value="'.$row_editForum['forum_name'].'" size="30" maxlength="40"></p>
	<h3>Forum description</h3>
	<p>A brief description of the forum</p>
	<p><input name="forum_description" type="text" id="forum_description" value="'.$row_editForum['forum_description'].'" size="30" maxlength="255"></p>
	<h3>Forum position</h3>
	<p>Choose the position of the Forum (e.g. 1, 2, 3)</p>
	<p><input name="forum_position" type="text" value="'.$row_editForum['forum_position'].'" id="forum_position" size="3" maxlength="3"></p>
	<input type="hidden" name="editforum" value="editforum">
	<p><input type="submit" name="Submit" value="Submit" class="submit" /></p>
	</form>';
The selector (id="category_name") needs to have a list of the categories. Basically I need this code to somehow work in there:

Code: Select all

while($r = mysql_fetch_array($result))
	   {
		  echo "<option value=\"". $r['id'] ."\">". $r['title'] ."</option> \n";
	   }
	?>
How do i do this?

Re: While loops in a variable?

Posted: Mon Oct 09, 2006 4:58 pm
by Luke

Code: Select all

$displayForm = '<form action="'.$formAction.'" method="post" name="editforum" id="editforum">
	<h3>Forum category</h3>
	<p><select name="category_id">';

while($r = mysql_fetch_array($result))
	   {
		  $displayForm .= "<option value=\"". $r['id'] ."\">". $r['title'] ."</option> \n";
	   }	

$displayForm .= '</select></p>
	<h3>Forum name</h3>
	<p>What would you like the forum to be called?</p>
	<p><input name="forum_name" type="text" id="forum_name" value="'.$row_editForum['forum_name'].'" size="30" maxlength="40"></p>
	<h3>Forum description</h3>
	<p>A brief description of the forum</p>
	<p><input name="forum_description" type="text" id="forum_description" value="'.$row_editForum['forum_description'].'" size="30" maxlength="255"></p>
	<h3>Forum position</h3>
	<p>Choose the position of the Forum (e.g. 1, 2, 3)</p>
	<p><input name="forum_position" type="text" value="'.$row_editForum['forum_position'].'" id="forum_position" size="3" maxlength="3"></p>
	<input type="hidden" name="editforum" value="editforum">
	<p><input type="submit" name="Submit" value="Submit" class="submit" /></p>
	</form>';