Outputting Specific Data from a Table in MySQL
Firstly, I'm quite new to PHP having only dived in some three weeks ago but loving it as a new thing to learn! I have a specific problem that I cannot seem to find a solution for via Google. I'm running a test page that will form the basis of a final product for a local recreational club that runs competitions and wants to display the results online on their website.
I've created a MySQL database and called it 'results' and imported as a CSV a sample of competition results. My code to connect to the database works as the page displays the "Database Connection Established" message.
Here is the connection code
//Connects to the competition results database
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/_includes/param_action.php";
echo "Database Connection Established";
so the file 'param_action.php' makes the connection to the database by requiring an additional file called 'param.php' which itself contains the username, password, etc credentials to make the connection.
The database contains a table called 'z_any_year_results' and the table structure looks like this:-
I understand how to select the specific table using
mysql_select_db("results") or die(mysql_error());
$data = mysql_query("SELECT * FROM z_any_year_results")
but I need to echo a specific record from the table in a specific section of the web page. So for example, in one section of the page I need to output Field_1 and Value_1. But in another section I need to output Field_4 and Value_4. So I guess my problem is how to extract a specific piece of data from a table to the exclusion of all other records in the table. I cannot find anything on the web that is written in a way to help novices like myself to understand.
Can anyone point me in the right direction on how to achieve this?
Many thanks in advance.
1 - select_db selects the DataBase, not a table. A db holds multiple tables associated in some way usually.
2 - stop using MySQL_* functions. If you have not read up on these in the official PHP manual, it's about time you acquainted yourself with it. These are all deprecated, so if you are just now learning, you're wasting your time with this set of functions. Explore the PDO or mysqlI functions.
3 - your dilemma is best solved by becoming familiar with basic sql syntax, specifically the 'Where' clause.
Books and manuals are an invaluable resource to intelligent people who wish to learn this stuff the right way. PHP has a very complete manual hosted online at :
I use this link All The Time - you will find it invaluable.
PS - If you're posting here you should be using:
error_reporting(E_ALL | E_NOTICE);
at the top of ALL php code while you develop it!
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)