doupo5178 2016-04-13 10:06
浏览 12

匹配表中的ID并返回不同的列

A user can enter a location via an edit form once they are registered with my site. The drop down menus for the locations is populated by an array so that the value is set as a number and the text is set as the location name so that is easy to complete.

The corresponding number is then stored in the user's profiles table as their location so that I can display it on their profile, search results and anywhere it is needed.

I obviously don't want to display the number - but rather the corresponding location name.

I have a table (frmLocations) that lists out the locations and assigns an ID To them, the ID is the same that is quoted in my array that populates the form field.

I can retrieve and loop out the location value but want to be able to match the number up with the ID from the frmLocations table and echo out the location_city column instead of the number.

It is complicated because I think I need to reference two separate tables to complete the query.

My frmLocations table is made up of id, location_city, location_county, location_country.

The field in my profiles table that stores the data for location is profiles_city.

An example of an array entry;

$location_city_frm = array( 
    25=>'Maidenhead',
    489=>'Manchester',
    493=>'Oldham',
    502=>'Salford');

My loop for displaying the location in the profile page;

<?php foreach($locations as $location): ?>  
                        <?php if(!empty($location['location_city'])){ ?>
                        <div><strong>City</strong> <?php echo $location['location_city'] ?></div>
                        <?php } ?>
                        <?php endforeach ?> 

Any help would be appreciated.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 树莓派5怎么用camera module 3啊
    • ¥20 java在应用程序里获取不到扬声器设备
    • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
    • ¥15 Attention is all you need 的代码运行
    • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
    • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
    • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
    • ¥80 部署运行web自动化项目
    • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
    • ¥30 VMware 云桌面水印如何添加