Passing function returns between scripts
Posted: Thu Aug 05, 2010 10:38 am
Hi guys,
I have created a function for counting the rows in a mysql table as follows:
That works fine. But what I want to do is use that function in a different php file as follows:
But that doesnt work. Why?
I know that I dont need to use my_count() in the first file, it was just to test it
I have created a function for counting the rows in a mysql table as follows:
Code: Select all
<?php
include 'connect.php';
function my_count($table)
{
echo $table;
$query = "SELECT COUNT(*) FROM $table";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result))
{
$count = $row['COUNT(*)'];
}
echo $count;
return $count;
}
echo my_count(sectors);
?>
Code: Select all
<?php
include 'connect.php';
include 'count.php';
$count = my_count(sectors);
echo $count;
?>
I know that I dont need to use my_count() in the first file, it was just to test it