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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

MySQL display query

  • 25-12-2015 2:16am
    #1
    Moderators, Entertainment Moderators, Science, Health & Environment Moderators Posts: 14,522 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, Registered Users 2 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