好吧,我有一个搜索表单,其中有很多字段,例如... Html Dropdown选中的字段和许多Checkbox字段。
所以我想根据表单从 mysql数据库多表中搜索数据。在这种形式我只能选择下拉框或我可以选择所有复选框,或者我可以选择几个复选框。
这样我就可以使用以下sql查询来获取数据。它只显示1个表格数据。我需要从多个表中获取数据。什么是sql查询应该是什么样的?
$search = mysql_query("SELECT * FROM tutor_signup_form WHERE gender = '$gender' OR feerange <= '$budget' ");
$num = mysql_num_rows($search);
包含列名称的数据库表:
tutor_signup_form (id, gender, feerange, name, fname, lname)
tutor_signup_edu_olevel (id, o_psd, o_diploma, o_degree)
tutor_signup_edu_alevel (id, a_psd, a_diploma, a_degree)
tutor_signup_edu_diploma (id, d_psd, d_diploma, d_degree)
tutor_signup_edu_degree (id, dig_psd, dig_diploma, dig_degree)
感谢您的建议或帮助!
更新
// search gender
$query = mysql_query("SELECT DISTINCT tutor_signup_form . *, tutor_signup_edu_psle . *, tutor_signup_edu_olevel . *, tutor_signup_edu_alevel . *, tutor_signup_edu_diploma . *, tutor_signup_edu_degree . *, tutor_signup_edu_masters . *, tutor_signup_edu_psd . *, tutor_signup_level_primary . *, tutor_signup_level_olevel . *, tutor_signup_level_alevel . *, tutor_signup_level_int . *, tutor_signup_level_uni . *, tutor_signup_level_music . *, tutor_signup_level_lang . *, tutor_signup_level_com . *, tutor_signup_pre_central . *, tutor_signup_pre_east . *, tutor_signup_pre_west . *, tutor_signup_pre_south . *, tutor_signup_pre_north . *, tutor_signup_pre_ne . *, tutor_signup_pre_nw . * FROM tutor_signup_form
INNER JOIN tutor_signup_edu_psle ON tutor_signup_form.tutor_id = tutor_signup_form.tutor_id
INNER JOIN tutor_signup_edu_olevel ON tutor_signup_form.tutor_id = tutor_signup_edu_olevel.tutor_id
INNER JOIN tutor_signup_edu_alevel ON tutor_signup_form.tutor_id = tutor_signup_edu_alevel.tutor_id
INNER JOIN tutor_signup_edu_diploma ON tutor_signup_form.tutor_id = tutor_signup_edu_diploma.tutor_id
INNER JOIN tutor_signup_edu_degree ON tutor_signup_form.tutor_id = tutor_signup_edu_degree.tutor_id
INNER JOIN tutor_signup_edu_masters ON tutor_signup_form.tutor_id = tutor_signup_edu_masters.tutor_id
INNER JOIN tutor_signup_edu_psd ON tutor_signup_form.tutor_id = tutor_signup_edu_psd.tutor_id
INNER JOIN tutor_signup_level_primary ON tutor_signup_form.tutor_id = tutor_signup_level_primary.tutor_id
INNER JOIN tutor_signup_level_olevel ON tutor_signup_form.tutor_id = tutor_signup_level_olevel.tutor_id
INNER JOIN tutor_signup_level_alevel ON tutor_signup_form.tutor_id = tutor_signup_level_alevel.tutor_id
INNER JOIN tutor_signup_level_int ON tutor_signup_form.tutor_id = tutor_signup_level_int.tutor_id
INNER JOIN tutor_signup_level_uni ON tutor_signup_form.tutor_id = tutor_signup_level_uni.tutor_id
INNER JOIN tutor_signup_level_music ON tutor_signup_form.tutor_id = tutor_signup_level_music.tutor_id
INNER JOIN tutor_signup_level_lang ON tutor_signup_form.tutor_id = tutor_signup_level_lang.tutor_id
INNER JOIN tutor_signup_level_com ON tutor_signup_form.tutor_id = tutor_signup_level_com.tutor_id
INNER JOIN tutor_signup_pre_central ON tutor_signup_form.tutor_id = tutor_signup_pre_central.tutor_id
INNER JOIN tutor_signup_pre_east ON tutor_signup_form.tutor_id = tutor_signup_pre_east.tutor_id
INNER JOIN tutor_signup_pre_west ON tutor_signup_form.tutor_id = tutor_signup_pre_west.tutor_id
INNER JOIN tutor_signup_pre_south ON tutor_signup_form.tutor_id = tutor_signup_pre_south.tutor_id
INNER JOIN tutor_signup_pre_north ON tutor_signup_form.tutor_id = tutor_signup_pre_north.tutor_id
INNER JOIN tutor_signup_pre_ne ON tutor_signup_form.tutor_id = tutor_signup_pre_ne.tutor_id
INNER JOIN tutor_signup_pre_nw ON tutor_signup_form.tutor_id = tutor_signup_pre_nw.tutor_id
WHERE tutor_signup_form.feerange <= '$budget' ");
答案 0 :(得分:0)
请查看MYSQL JOIN。
举个例子:
$query="select A.gender,B.o_psd from tutor_signup_form as A,tutor_signup_edu_olevel as B where A.id=B.id"; //just an example condition