mysql快速命令和内存不足错误加上如何使用EXPLAIN

I have two questions, I am new to PHP and MySQL

first i want to know how to run EXPLAIN in query and see its results, when i use

$SQL = mysql_query("EXPLAIN SELECT id,name FROM table_name")

and i use

print_r($SQL)

it only gives me the resource id number value. I want to know that how it explain my query

i need and working example that shows me how to see the explains or how to print explains result on page to read.

And second question is that,

My single PHP page has more than 25 queries and all queries from different tables, and in some queries i have used inner joins, home page is set to display informations from many tables, and some tables are not used as joins,

The problem on this page is its displays the error message that "MySQL client ran out of memory".

So this problem is because of too many sql queries or only that my queries are not optimized very well.

Any suggestions..?

Edit

sorry i was forgot to mention that, is quick a solution for mysql client ran out of memory. Than how i can use it in PHP/MySQL queries?

For the Explain statement, try running it from a query window or the command line.

As for the error you're having, it means that mysql does not have enough memory to store the entire query result. Here's some more information.