The problem iss that, despite your assertion, $table doesn't have anything assigned to it - not until after you've assigned that string to $sql.
So at the time you assign "SELECT from $table" to $sql, $table is empty. So $sql ends up being equal to "SELECT from ". And MySQL doesn't like that.
In fcat, there are two reasons why your code won't work. First reason is the one I've described above - you're assigning things to variables in the wrong order - and the second reason is that the $table inside the function is actually a different varaible from the $table outside the function.
As for solving it:
function do_it($sql,$condi){
if ($condi == 1){
$table = "users";
mysql_query(sprintf($sql, $table));
//and the rest to display it...
}
else{
$table = "pages";
mysql_query(sprintf($sql, $table));
//and the rest to display it...
}
}
//-------8<--------
include "func.php";
$sql = "SELECT * FROM %s";
do_it($sql,1);
May be the shortest-distance solution, but I'm wondering if something a bit more fundamental in your approach might have to be reviewed.