0

Hi. I'm not sure if this is possible or not, but I need to be able to SELECT * FROM all the tables in the database. Is this possible?

Thanks!

Edited by calebcook: n/a

3
Contributors
2
Replies
7
Views
6 Years
Discussion Span
Last Post by oab2003
0

I would use following steps:
1. Put Tables in array

mysql_connect($server, $login, $password);
$res = mysql_query("SHOW TABLES FROM $db");
$tables = array();
while($row = mysql_fetch_array($res, MYSQL_NUM)) {
    $tables[] = "$row[0]";
}

2. Loop the array and query each table.
Now it is up to you to test my "workable" theory!
Also for (1) you can use mysql_list_table

0

Yes it is possible. You retrieve all the tables in the database with mysql_list_tables($database)function where $database is the variable holing the database name.You then retrieve the actual table names with mysql_tablename() function and store them in an array. You then put the Select * from array name in a loop. For example-

$query1=mysql_list_tables($database);
	$num=mysql_numrows($query1);
		
	
	$s=0;
	while($s<$num)
	{
	$num1=mysql_tablename($query1,$s);
	$table_directory[]=$num1;
	$s++;
	}
	
			
	for($k=0;$k<count($table_directory);$k++)
	{
	
	
		$qy2=mysql_query("SELECT  * FROM"." ".$table_directory[$k]);
		
	}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.