简体   繁体   English

从另一个mysql表中选择

[英]Select from another mysql table

I would ask for any help, because Im desperate :D. 我会寻求任何帮助,因为我拼命:D。 I need help with my school project, where I have to save data from form. 我的学校项目需要帮助,我必须从表单中保存数据。 There´s one select, where should be dropdown with datas from another connected table. 有一个选择,应该在其中下拉列表,其中包含来自另一个已连接表的数据。

here is screenshot of my relations: 这是我的关系的屏幕截图:

在此输入图像描述

 <?php $con = mysql_connect("localhost","root",""); $db = mysql_select_db("cznovis",$con); $get=mysql_query("SELECT id FROM listky); $option = ''; while($row = mysql_fetch_assoc($get)) { $option .= '<option value = "'.$row['id'].'">'.$row['id'].'</option>'; } ?> <form action="odeslat.php" method="POST"> <select name="typ"> <?php echo $option; ?> </select> <input type="submit" name="odeslat" value="ODESLAT"> </form> 

i would appreciate any help 我将不胜感激任何帮助

Simple usein join should be enough. 简单的使用join就足够了。 Your query shoul by like this: 您的查询应该像这样:

select * from clenstvi as cl join listky as li on cl.typ=listky.id;

you can use left outer join in your query 您可以在查询中使用左外部联接

select * from table1 left outer join table2 on table1.id = table2.id;

and then concatenate those two columns in your select 然后将您选择的这两列连接起来

$row['data1'].$row['data2'];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM