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!

Recommended Answers

All 2 Replies

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

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]);
		
	}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.