Lets suppose following Database table:

id (primary key)
name
address
number

Now lets say i make following function:

function get_member($var1, $var2, $table) {
// where var1 and var2 are info needed to pull from DB
$query = mysql_query("SELECT * FROM $table WHERE id='$var1' AND search='$var2'")
or die("Mysql error:".mysql_error());
$queried = mysql_fetch_array($query);
$name = $queried['1'];
$address = $queried['2'];
return $name;
return $address;

}

Now i have tried setting name and address to global.. ofc var1 and var2 + table would be global, however, then i do this:

get_member('2', '300', 'member_table');
// now, i do for exampled want to display the name...
echo $name;
// however, no matter what i do, this will not work... echoing out the name in the function works fine.

I'm sure it's something simple he he... i tried to look about on here, but didn't find anything useful.

Thanks in advance 😉

    This is a php question, not database. But I see two obvious problems.

    First, you have two return statements, the function will return when it hits the first, so the second can never be executed.

    Second, you aren't saving the value returned by the function.

    Read up a bit on php functions, what you probably want is to store the name and address in an array and return that to the caller.

    function get_member($var1, $var2, $table) {
    // where var1 and var2 are info needed to pull from DB
    $query = mysql_query("SELECT * FROM $table WHERE id='$var1' AND search='$var2'")
    or die("Mysql error:".mysql_error());
    return mysql_fetch_array($query);
    
    ...
    
    $res = get_member(...)
    

      So... does that mean your issue is resolved? If so, don't forget to mark this thread resolved.

        Write a Reply...