Returning from a function

So I used to always write my code spaghetti style and started using functions to organize things a little bit easier. The only problem I’ve come into is if I want to use a function to connect to a database then select some data, how do I return that information to the original page? It’s probably something simple that I’m missing. Halp?

if you are using mysql.. php and mysql are tightly coupled..

simple commands like

$result = mysql_query("query"); <– to query the database

$row = mysql_fetch_row($result); <– pulls the data
$rows = mysql_fetch_assoc($result) <– pulls data and makes it an assoc array and you can access the data by column names

echo $row[0] to access your return data

or for multiple rows

while($rows = mysql_fetch_assoc($result)){
echo $rows[‘id’]; //echos out the id column
}

hope that helps

sorry, that’s not what I’m looking for. I have a page that calls function getInfo(); then getInfo performs a function, then I want to return the results of that function to the page.

The function should have a return results line in it.. then you just call the function where you need it, or place it into a variable and use it

Eg (from:

<?php
function add($x,$y)
{
$total=$x+$y;
return $total;
}

echo "1 + 16 = " . add(1,16);
?>

Or at the end just do:

$finalresults = add(1,16);

And use $finalresults wherever you want..

Or am I misunderstanding

That’s exactly what I’m looking for, now how about if I’m returning an array? Would I do $finalresults[] = getInfo(); ?

oh……………………

yeh just make sure you return an array type

Son of a bitch. No wonder why it wouldn’t work. I didn’t give my inputs a name! Fuuuuuu