TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Display mysql tables (http://www.talkphp.com/absolute-beginners/5292-display-mysql-tables.html)

unitechy 02-28-2010 06:37 PM

Display mysql tables
 
Hello ninja programmers,

I have a database called "database" with tables:
table1
table2
table3
table4
table5

Now I want to display say only table1,2,3 in my sidebar. Say like in wordpress dashboard, where it displays post, categories, etc.
But I dont want to display all of the tables. How do I achieve that?

Thanks for your help.

delayedinsanity 02-28-2010 06:57 PM

Interesting naming conventions. I would have reversed it, and called my database "table" and my tables "database#", but I'm cRAzEe.

How far have you gotten? If you're running this in WordPress, you can instantiate a new WPDB object to handle the database connection. After that it's just a matter of your query and method of displaying the results.

delayedinsanity 02-28-2010 07:39 PM

Quote:

Originally Posted by unitechy
My project is not related to wordpress, Wordpress was supposed to be an example. AFAIK
Code:

SHOW TABLES FROM `database_name`
displays the tables? But can I use WHERE clause in it? If yes how?

I hope you don't mind me cross posting this back into the forums, but it's useful for others to see the problem and possible solutions.

You can use a WHERE clause in a show tables statement, however you may be more interested in LIKE, ie
mysql Code:
SHOW TABLES FROM `database` LIKE 'table%'

However this will just display a list of the table names, and with your naming conventions, will actually list all of them. You may want to consider using the information_schema database for this;
mysql Code:
USE information_schema;
SELECT TABLE_NAME FROM `tables` WHERE SUBSTR(TABLE_NAME, -1) < 4;

unitechy 02-28-2010 07:42 PM

Brilliant. Much thanks :)


All times are GMT. The time now is 11:41 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0