Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Banned
    Join Date
    Sep 2011
    Posts
    140
    Thanks
    17
    Thanked 0 Times in 0 Posts

    echoing a MySQL field

    How can I echo a field from a MySQL database in PHP?

    +----+---------------+------------+---------+-------+-------+-------+--------+----------+
    | id | primarycolour | pricerange | country | sizes | sizem | sizel | sizexl | category |
    +----+---------------+------------+---------+-------+-------+-------+--------+----------+
    | 1 | Black | 1 | Italy | 2 | 1 | 1 | 3 | Belts |
    | 2 | Blue | 2 | USA | 1 | 0 | 0 | 2 | Belts |
    +----+---------------+------------+---------+-------+-------+-------+--------+----------+
    For example, how would I echo the country field for id 2?

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,294
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5
    PHP Code:
    $Query "select country from <tablename> where id='2'";

    $Result mysql_query($Query);

    $Row mysql_fetch_array($Result);

    print 
    $Row['country']; 
    You could also use mysql_result to simplify things but its been a while since I've used that and frankly I can't remember how to.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    Democrazy (09-11-2011)

  • #3
    Banned
    Join Date
    Sep 2011
    Posts
    140
    Thanks
    17
    Thanked 0 Times in 0 Posts
    Hey tangoforce, the code worked so I'd like to publicly thank you.

    Thank you.


  •  

    Posting Permissions

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