我有一张表(表A),有6列(天,les1,les2,les3,les4,les5)
+-----------------------------------------------------+
| days | les1 | les2 | les3 | les4 | les5 |
-------------------------------------------------------
| sat | 2 | 5 | 9 | 10 | 30 |
| mon | 50 | 2 | 2 | 4 | 5 |
| Fri | 6 | 1 | 2 | 8 | 4 |
| wed | 8 | 0 | 3 | 6 | 3 |
-------------------------------------------------------
在另一个表(表B)中我有3列(id,TName,LName)
___________________________
| id | TName | LName |
----------------------------
| 1 | M.N | les1 |
| 2 | T.G | les5 |
| 3 | Z.GH | les2 |
| 4 | J.H | les4 |
----------------------------
我需要从表A中找到一些带有PHP代码的值,类似于以下代码:
$les = mysql_query("SELECT * FROM `table_B` WHERE `id` = '3' ");
$les_f = mysql_fetch_array($les);
$lesson = $les_f['LName']; //so the $lesson value = 'les2'
$list = mysql_query("SELECT * FROM `table_A` WHERE $lesson = '0' ");
$showresult = mysql_fetch_array($list);
$result = $showresult['days']; // it should show me 'wed' from tableA in days column
请帮助编写此代码...
答案 0 :(得分:1)
我建议您改进数据库设计。将表A的列减少到day, number, les
,将表B减少到id, TName, LId
表A应如下所示:
+---------------------------+
| day | number | les |
----------------------------
| sat | 2 | 1 |
| sat | 5 | 2 |
| sat | 9 | 3 |
| sat | 10 | 4 |
| sat | 30 | 5 |
| | | |
| mon | 50 | 1 |
| mon | 2 | 2 |
| mon | 2 | 3 |
| mon | 8 | 4 |
| mon | 5 | 5 |
| ... | ... | ... |
----------------------------
表B应如下所示:
| id | TName | LId |
----------------------------
| 1 | M.N | 1 |
| 2 | T.G | 5 |
| 3 | Z.GH | 2 |
| 4 | J.H | 4 |
----------------------------
然后,您可以使用单个SQL查询获取数据:
SELECT * FROM table_b b
JOIN table_a a
ON b.les = a.LId
WHERE a.number = 0
答案 1 :(得分:0)
Vector
改变:
self.webView.allowsInlineMediaPlayback = YES;
self.webView.mediaPlaybackRequiresUserAction = NO;
TO:
$les = mysql_query("SELECT * FROM `table_B` WHERE `id` = '3' ");
$les_f = mysql_fetch_array($les);
$lesson = $les_f['LName']; //so the $lesson value = 'les2'
$list = mysql_query("SELECT * FROM `table_A` WHERE $lesson = '0' ");
$showresult = mysql_fetch_array($list);
$result = $showresult['days'];
是这个问题的解决方案
答案 2 :(得分:-1)
尝试以下代码获取结果
$les = mysql_query("SELECT * FROM `table_B` WHERE `id` = '3' ");
while($row = mysql_fetch_assoc($les)) {
$lesson = $row['LName']; //so the $lesson value = 'les2'
$list = mysql_query("SELECT * FROM `table_A` WHERE $lesson = '0' ");
while($showresult = mysql_fetch_assoc($list)) {
echo $result = $showresult['days']; // it should show me 'wed' from tableA in days column
}
}
由于