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 all! We have been experiencing an issue on site where threads have been missing the latest postings. The platform host Vanilla are working on this issue. A workaround that has been used by some is to navigate back from 1 to 10+ pages to re-sync the thread and this will then show the latest posts. Thanks, Mike.
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

Show value in cell as text

  • 08-09-2014 8:53pm
    #1
    Registered Users, Registered Users 2 Posts: 1,096 ✭✭✭


    Hi,

    Just wondering if someone can help me out as I am having a brain freeze at the moment. I'm fairly new into PHP & MySQL, but have hit a roadblock here with what I have no doubt has a simple solution.

    I have a table which has a number of columns, one which is county. Each county (due to a jQuery form element) is in-putted as a number, taken from another table which has a list of counties matched with a id. When displaying the output of a row, I need to show that county as the name of that county rather than the number/id. Is there a straightforward way to do that? I have been messing around with either an if statement or an array, but I'm not sure exactly what the solution is.

    Any ideas appreciated!


Comments

  • Registered Users, Registered Users 2 Posts: 67 ✭✭The Gibmiester


    The county name should be returned in the SQL result set. You may need to do an SQL JOIN on the counties table then update the PHP to output the correct column in the result set. Can you post the SQL statement that returns the data and the PHP that prints it out?


  • Registered Users, Registered Users 2 Posts: 1,096 ✭✭✭ImDave


    Thanks for the reply.

    So the main query to return the row which has the county as an id/number is as follows:

    [PHP]$query="SELECT * FROM `offices` WHERE (`id` = '$id') AND (`active` = 'Yes') LIMIT 0, 1 ";[/PHP]

    That will return a value of say 15 which in the counties table corresponds to Dublin. What I need to do is match the returned value of 15 from the offices table with the value of 15 in the counties table.

    Thanks!


  • Registered Users, Registered Users 2 Posts: 67 ✭✭The Gibmiester


    So assuming you have a table called 'counties' and the county id column in the office table is called 'county', the following code should return a result set with a combination of the appropriate office row and county row.

    [PHP]$query="SELECT * FROM offices o, counties c WHERE (o.id = '$id') AND o.county = c.id AND (`o.active` = 'Yes') LIMIT 0, 1 ";[/PHP]

    I gave the table aliases for handiness. Also, for optimisation, you should only specify the columns you need rather than SELECT *.


  • Registered Users, Registered Users 2 Posts: 1,096 ✭✭✭ImDave


    Cheers! That worked very well. Thanks for your help.


  • Registered Users, Registered Users 2 Posts: 2,781 ✭✭✭amen


    Don't use Select *
    Only return the columns you need.


  • Advertisement
Advertisement