Forum Moderators: coopster

Message Too Old, No Replies

Php Mysql query to display data

shortest query for mysql

         

Animated

3:27 am on May 27, 2007 (gmt 0)

10+ Year Member



is there a query command for Php thats very short and simply displays the tables in a database, i know some like mysq_fetch_array ad so but they usually a couple lines long , i like to know if there is one that just displays the tables plus the content of them with just a 1-2 lines query?

phparion

7:36 am on May 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



First of all there is no query for PHP itself but you use MySQL queries with PHP.

you can use "show tables" to see the tables in a database. however if you want to display tables in a database and their data too then you will need a kinda looping code in php

e.g

$tRes = mysql_query("SHOW TABLES");

$i=0;
while($tRow=mysql_fetch_array($tRes)) {

$dRes = mysql_query("SELECT * FROM ". $tRow[$i]);
while($dRow=mysql_fetch_array($dRes)) {
//print all data
}
$i++;
}

this code is not tested and i just wrote it so use it at your own risk :)

however it WILL give you the concept at least.

Animated

12:34 pm on May 27, 2007 (gmt 0)

10+ Year Member



thanx for the help :) yes i know there is no query just from php alone i use some similar functions as the one you show i just wanted to know if there is a faster way without doing a loop and array.

phparion

6:29 pm on May 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



functions like mysql_query and mysql_fetch_array etc are the medium for php to communicate with mysql and there is no other way, according to my limited knowledge, to fetch data directly from mysql using php unless you use another function like

exec("execute mysql command from shell",$results);

print_r($results);

eelixduppy

4:29 am on May 28, 2007 (gmt 0)



Animated, if you find yourself needing the same code more than one and are finding it rather repetitive, you may want to start looking at making some functions [us.php.net]. They can make the code much easier to read/debug/write/etc... Can't get much shorter than one function call :)

Animated

9:10 am on May 29, 2007 (gmt 0)

10+ Year Member



i use some functions with the scripts i use to query mysql i just wanted to know if i can do it with just 1 query like the sql'show databases' i guess i have to stick with it there is no faster way around