Preventing functions from executing at the end
Moderator: General Moderators
Preventing functions from executing at the end
My problem is that I'm using a function and when the php is converted to html the html generated by the function appears an extra time at the end where I gave the function definition. How can I prevent this from happening?
Code: Select all
<?php
$link = @mysql_connect('localhost', 'root', 'password') or
die("Could not connect to MySQL");
$db = @mysql_select_db('temp1',$link) or
die("Could not select database");
$query = "SELECT * FROM table1";
$result = @mysql_query($query,$link) or
die("Could not submit query");
$numrows = @mysql_num_rows($result);
for ($i=0; $i<$numrows; $i++) {
$jones = mysql_fetch_array($result);
echo ("Location: "."$jones[location]");
dropmenu();
?><?php
}
function dropmenu()
{
?>
<form action="#" method="post">
<SELECT NAME="State" SIZE="1">
<OPTION VALUE="1">ACTIVE</OPTION>
<OPTION VALUE="2">BROKEN</OPTION>
<OPTION VALUE="3"">PLANNED</OPTION>
</SELECT>
<input type="submit" value="crazy stuff"/>
</form>
<?php
}
dropmenu();
?>why even have it in a function?
If you do need it in a function for some reason
?>
If you do need it in a function for some reason
Code: Select all
<?php
$link = @mysql_connect('localhost', 'root', 'password') or
die("Could not connect to MySQL");
$db = @mysql_select_db('temp1',$link) or
die("Could not select database");
$query = "SELECT * FROM table1";
$result = @mysql_query($query,$link) or
die("Could not submit query");
$numrows = @mysql_num_rows($result);
for ($i=0; $i<$numrows; $i++) {
$jones = mysql_fetch_array($result);
echo ("Location: "."$jones[location]");
dropmenu();
?><?php
}
function dropmenu()
{
echo '
<form action="#" method="post">
<SELECT NAME="State" SIZE="1">
<OPTION VALUE="1">ACTIVE</OPTION>
<OPTION VALUE="2">BROKEN</OPTION>
<OPTION VALUE="3"">PLANNED</OPTION>
</SELECT>
<input type="submit" value="crazy stuff"/>
</form>';
}
dropmenu();