<?
function clothes()
{
echo '<form action="">
<select>
<option>SELECT</option>';
$result=mysql_query($qry);
while($row=mysql_fetch_array($result))
{
// long code of 20 lines;
}
echo '</select></form>';
}
?>
If i put the “$qry” inside the function then i dont get mysql_fetch_array error but only one query works (means i get result for either men or women based on qry inserted in function).
If i dont put “$qry” inside function then i get mysql_fetch_array error.
$_REQUEST is already global, so you can just utilize that within your function. Or similar to how you passed $qry, you can pass $one, $two, and $three into your function as well.
<?
$one = $_REQUEST['one'];
$two = $_REQUEST['two'];
$three = $_REQUEST['three'];
clothes($qry, $one, $two, $three);
function clothes($qry, $one, $two, $three)
{
echo '<form action="">
<select>
<option>SELECT</option>';
$result=mysql_query($qry);
while($row=mysql_fetch_array($result))
{
echo $one; // echoes one fine
echo $two; // echoes two fine
echo $three; // echoes three fine
// long code of 20 lines;
}
echo '</select></form>';
}
?>
No, the only automatic globals are the super-globals $_REQUST, $_POST, $_GET, $_SESSION, $_COOKIE, $_SERVER, etc. Everything else, is not a global, and only has local scope.
Actually i had a variable on top of my product page that is called from the database
$name = $row['name'];
and when i called “$name” inside the function on product page, it echoed the value absolutely fine.
If i will call this function on any other page then i think “$name” will echo nothing. i havent tried yet.
Thats why i asked if variable from database is also global or not.
vineet
You’re going to have to show me that code so I can see if it fits the description or not, as I’m not 100% certain I understand the code layout you ran to be able to answer why it would have echo’d $name.
You passed the variable to the function, so that is why the function has access. Otherwise, it would not have had access to it, so passing it was the right decision.