作为一个PHP教练我自己教,但遇到了一个小问题,可以请求帮助。
我目前正在对tbl_products进行查询以获取信息,如下所示:
$mysql_hostname = "localhost";
$mysql_user = "hidden";
$mysql_password = "hidden";
$mysql_database = "hidden";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Oops some thing went wrong");
mysql_select_db($mysql_database, $bd) or die("Oops some thing went wrong");// we are now connected to database
$result = mysql_query("SELECT * FROM tbl_products ORDER BY bankIds"); // selecting data through mysql_query()
while($data = mysql_fetch_array($result))
{
echo ''.$data['bankIds'].'|'.strip_tags($data['sku']).'|'.strip_tags($data['productTitle']).'|'.strip_tags($data['productTitle']).'|'.strip_tags($data['prodDesc']).'|'.strip_tags($data['seed']).',http://cdn.shopify.com/s/files/1/0709/2915/files/'.strip_tags($data['productImg']).'<br/>';
}
工作正常,但现在我想通过对名为&#34; tbl_seedBank&#34;的表进行另一次查询(如果需要)来显示[&#39; bankIds&#39;]的名称。
目前&#34; $ data [&#39; bankIds&#39;]&#34;将回显id号码,我希望能够从id中获取bankTitle并将其回显而不是id号...
希望这会让sencse大声笑
非常感谢你花时间阅读我的问题。 ~Rory
答案 0 :(得分:1)
你可以使用内部加入.. 尝试执行以下查询
$result = mysql_query("SELECT a.bankIds,a.sku,a.productTitle,a.productTitle,a.prodDesc,a.seed ,a.productImg,b.bankTitle FROM tbl_products a JOIN tbl_seedBank b ON a.bankIds=b.id ORDER BY bankIds");
答案 1 :(得分:0)
如果我理解正确,您需要在查询中加入
SELECT * FROM tbl_products ORDER BY bankIds INNER JOIN tbl_seedBank ON tbl_seedBank = bankIds