Results 1 to 2 of 2

Thread: Outputting Specific Data from a Table in MySQL

  1. #1
    Join Date
    Oct 2013

    Outputting Specific Data from a Table in MySQL

    Hi All,

    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";
    <span class="body_text">
    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:-

    Record_Number Field Value
    1 Field_1 Value_1
    2 Field_2 Value_2
    3 Field_3 Value_3
    4 Field_4 Value_4
    5 Field_5 Value_5

    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.

  2. #2
    Join Date
    Jul 2013
    Voorheesville NY USA
    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:

    ini_set('display_errors', '1');

    at the top of ALL php code while you develop it!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center