Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

MySQL display query

  • 25-12-2015 03:16AM
    #1
    Moderators, Science, Health & Environment Moderators Posts: 14,761 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