SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Jul 2013
    Location
    South of the equator, then turn left
    Posts
    361
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question about retrieving individual records from table

    Hi everyone,

    I have a column in my table which includes a number of cities. I might have 10 rows with the name 'London' and 5 rows with the name 'New York'. How can I print out all of the cities without the same names repeating themselves? So, one row for each individual city.


    PHP Code:
    <?php
    require (MYSQL);
    $q "SELECT city FROM messages";
        
    $r = @mysqli_query($dbc$q);   
        
    $num mysqli_num_rows($r);
        if (
    $num 0) { 
     while (
    $row mysqli_fetch_array($rMYSQLI_ASSOC)) { 

    print
    '<p>'.$row['city'] . '</p>';
     }
        }

    ?>


    Thank you in advance!

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,251
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    Code:
    SELECT DISTINCT city FROM messages
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Addict
    Join Date
    Jul 2013
    Location
    South of the equator, then turn left
    Posts
    361
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Rudy,

    brilliant! Thank you.

    Regards


Bookmarks

Posting Permissions

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