MySQL & PHP- Show Tables In Database

Image frame
MySQL & PHP- Show Tables In Database
Maruf
Nov 14th, 2008
Maruf scribbled this post.

Someone asked me the other day how to display the existing tables in their database with a PHP script. The query itself is pretty simple, but people seem to get confused about the PHP side of it. Then again, once you look at the code, you might be surprised how easy it really is…

Printing tables with PHP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?
$showtablequery = "
	SHOW TABLES
	FROM
	[database]
	";
 
$showtablequery_result	= mysql_query($showtablequery);
while($showtablerow = mysql_fetch_array($showtablequery_result))
{
	echo $showtablerow[0]."<br />";
}
 
?>

That query will show ALL tables, but you can use a LIKE function in the query as well, to get particular tables only.

Printing particular tables with PHP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?
$showtablequery = "
	SHOW TABLES
	FROM
	[database]
	LIKE
	'%brightcherry%'
	";
 
$showtablequery_result	= mysql_query($showtablequery);
while($showtablerow = mysql_fetch_array($showtablequery_result))
{
	echo $showtablerow[0]."<br />";
}
 
?>

That query will pull out all tables with the word ‘brightcherry’ in.

Filed away: MySQL & PHP

feel free to leave a scribble

Name:
Email:
gravatar
What an image next to your comments?
visit gravatar.com
Message:
want a website, do ya?

latest projects

Image frame
Taylor El-Hage Photography
view site- Taylor El-Hage Photography
Image frame
Property Investment Project
view site- Property Investment Project

latest scribbles

latest comments

Kalinda Gravatar frame
Kalinda said
Doesn’t look like it. I’ve looked at the site in...
Maruf Gravatar frame
Maruf said
Hey Kalinda, Hmm..I looked at your site in I.E7 and everything...
chiwan Gravatar frame
chiwan said
thanks maruf! hmmm… i guess i used the wrong term. i...

blog categories

Get a free quote