The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Resource id #31 ? Connecting to database?

I am a complete newbee and i am trying to connect to my sqldatabase.
Previously the connection to sql worked but when i try to connect to sql and my database & echo a confirm i get the following appear on my screen.
Resource id #31

First of all, the function mysql_connect() returns a resource, which is the connection to the database server. And the function mysql_select_db() returns a boolean to check if the database can be used or not to extract, alter or add data to the database.

Secondly, mysql_select_db() selects a database, not a table.
To get data from the database, you'll need to query the database.
For example:

Code PHP:

<?php// This query gets all rows and columns from the table TableName$result=mysql_query('Select * from TableName');?>

The function mysql_query() returns another resource, which contains all the rows and columns returned by the database that meet your query.
To then use the returned results, you'll have to walk through the returned resource:

The function mysql_fetch_array() returns an array with the fieldnames as keys of the array -you can get the values by their corresponding numeric keys too- and the values as of the fields as the value linked to their corresponding array key.
Every time you call mysql_fetch_array($result), you'll get one row from the resource the database returned. If there are no more rows available in the resource, the for-loop will be ended.