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
Charles256
DevNet Resident
Posts: 1375 Joined: Fri Sep 16, 2005 9:06 pm
Post
by Charles256 » Sun Sep 18, 2005 10:36 pm
Code: Select all
function stategen($o,$test)
{
?>
<option value='
<?php
echo ("$o");
?>
'
<?php
if ("$test"=="$o")
{
echo ('selected');
}
?>
>
<?php
echo ("$o $test");
?>
</option>
<br />
<?php
}
that's the function...
heres the other parts of the code...
Code: Select all
$State=$_POST['State'];
stategen("Alabama","$State");
State is actually defined above the function and obviously the function is called after the function is defined:-D however, even though both test and o will both read, say arkansas it will not put the attribute selected into the option. any ideas?
Last edited by
Charles256 on Tue Sep 20, 2005 11:37 am, edited 1 time in total.
Charles256
DevNet Resident
Posts: 1375 Joined: Fri Sep 16, 2005 9:06 pm
Post
by Charles256 » Sun Sep 18, 2005 11:18 pm
i know i didn't state it but if it isn't clear enough just let me know, I'll try to explain again.
wyred
Forum Commoner
Posts: 86 Joined: Mon Dec 20, 2004 1:59 am
Location: Singapore
Post
by wyred » Sun Sep 18, 2005 11:18 pm
I suggest you write your stategen() this way...
Code: Select all
function stategen($o,$test) {
$result = "<option value='$o'";
if ($test==$o) $result .= ' selected';
$result .= ">$o $test</option><br />";
echo $result;
}
Charles256
DevNet Resident
Posts: 1375 Joined: Fri Sep 16, 2005 9:06 pm
Post
by Charles256 » Sun Sep 18, 2005 11:31 pm
that worked.. i don't know what the difference is. i mean, yours is WAY more efficient but the functionality should be the same..thanks
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Sun Sep 18, 2005 11:58 pm
I don't think you can break out of PHP mode in functions
Charles256
DevNet Resident
Posts: 1375 Joined: Fri Sep 16, 2005 9:06 pm
Post
by Charles256 » Mon Sep 19, 2005 12:01 am
sure you can. i have a function that works successfully that breaks out of PHP. I'd post hte code but I'm assuming we can just take my word on that;)
ryanlwh
Forum Commoner
Posts: 84 Joined: Wed Sep 14, 2005 1:29 pm
Post
by ryanlwh » Mon Sep 19, 2005 2:31 pm
i think it's "$test"=="$o" versus $test==$o.
and i have broken out of php mode in functions (and functions in a class) so many times that I can guarantee it works
Charles256
DevNet Resident
Posts: 1375 Joined: Fri Sep 16, 2005 9:06 pm
Post
by Charles256 » Mon Sep 19, 2005 4:36 pm
Code: Select all
foreach ($_POST as $key=>$value)
{
if ($key!='Register')
{
if ($value=='')
{
$varname="form_" .$key;
$$varname="<font color='RED'>Please enter something here.</font>";
$Error=1;
}
}
}
That's the loop... here's the form that's posted, or at least the part that should coincide with $key!='Register'
Code: Select all
<input type="submit" name="Register" value="Register">
and on the other page when it determines when to display the form looks like...
Code: Select all
if ($Error==1 || !(isset($Error)))
{
include('form.php');
}
Now obviously I submitted a blank form but the $Error=1 part didn't get executed because the form isn't displayed after it is submitted. any ideas?