Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

MySQL display query

Options
  • 25-12-2015 3:16am
    #1
    Moderators, Entertainment Moderators, Science, Health & Environment Moderators Posts: 14,355 Mod ✭✭✭✭


    Hi lads,

    Created my first mySQL table today so apologies if this is a stupid question.

    If I have a table with 4 columns, and one column has a three digit number, is it conveniently possible for me to display a certain string whenever that row is called upon?

    For example, if 6/7 rows have id = 201, they display "Cork" instead of 201 when displaying the information on a html page


Comments

  • Registered Users Posts: 227 ✭✭boreder


    So you'd either keep the list of what id's map to what names in another table and join them – or you could hard code them in your scripting language. Which option you choose depends on what you're doing, and how you're doing it.

    For the scripting language way, you'd just put an 'if' or 'switch' statement when iterating through the rows. For example, assuming $result is the returned SQL;
    foreach($result as $row){
        if($row->id == "204"){
            print "Cork";
        }else{
            print "Dublin";
        }
    }
    


Advertisement