ok so i am messing around with php trying to see what i can do to improve the way i make/do things. right now i am playing around with a query set that automatically makes the variables with the database information in it then to echo it later on when needed.
here is the code that i have all together.
$fields = array("companyname","password");
$select = "users WHERE company_id='$company_id' and master='1'";
$result = mysql_query("SELECT * FROM $select");
while($myrow = mysql_fetch_assoc($result))
{
if($fields != ''){
foreach ($fields as &$value) {
${$value} = $myrow[$value];
}
}
}
echo $companyname;
echo $password;
that works fine but when i create a function with just the $result and while loop in it and within the page i call the function it doesnt seem to let me echo out any of the variables.
Function
function query($fields, $select) {
$result = mysql_query("SELECT * FROM $select");
while($myrow = mysql_fetch_assoc($result))
{
if($fields != ''){
foreach ($fields as &$value) {
${$value} = $myrow[$value];
}
}
}
}
calling the function
$fields = array("companyname","password");
$select = "users WHERE company_id='$company_id' and master='1'";
query($fields, $select);
echo $companyname;
echo $password;
but if i change ${$value} = $myrow[$value]; to echo $myrow[$value]; it gives me my variables
Any thoughts as to why it wont let me?
thanks in advance