所以,我试图让一个 SELECT CONCAT 查询运行,返回查询结果并基本上将它们显示在 .php 网页上。例如,如果我手动将以下 SQL 代码放入 PHPMyAdmin:
SELECT CONCAT(m.Name, ' ', p.Model, ' - ', p.StorageSize, ' - ', o.Name, ' - ', p.Price)
FROM phones p
JOIN manufacturer m
ON p.ManufacturerID = m.ManufacturerID
JOIN operatingsystem o
ON p.OSID = o.OSID
PHPMyAdmin 运行它并显示“Apple iPhone 5 - 16GB - iOS - 499.99。但是,我试图让它显示在 .php 页面上而不是仅仅通过 PHPMyAdmin 并且无法让它工作。我猜我需要使用某种 echo 命令,但是当我使用例如 echo $result 时,它要么在网页上不显示任何内容,要么有时在“资源 id #3”上显示。我的整个 PHP 代码如下:
<html>
<head>
<LINK rel="stylesheet" href="style.css">
<title>Phones | Mobiles Four You</title>
</head>
<body>
<div id="container">
<div id"header"><img src="images/logo.png" alt="Logo"/></div>
<div id="navbar">
<ul>
<li><a id=”nav-home” class=”first” href="index.php">Home</a></li>
<li><a id=”nav-phones” href="phones.php?sort=Make">Phones</a></li>
<li><a id=”nav-search” href="search.php">Search</a></li>
<li><a id=”nav-login” href="login.php">Login</a></li>
<li><a id=”nav-contact” class=”last” href="contact.php">Contact</a></li>
</ul>
</div>
<div id="content">
<h1>Mobile Phones</h1>
</div>
<?php
$con = mysql_connect("b*********", "*****", "*****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("bg29li", $con);
$query = ("SELECT CONCAT(m.Name, ' ', p.Model, ' - ', p.StorageSize, ' - ', o.Name, ' - ', p.Price)
FROM phones p
JOIN manufacturer m
ON p.ManufacturerID = m.ManufacturerID
JOIN operatingsystem o
ON p.OSID = o.OSID");
mysql_close($con);
?>
</body>
</html>
任何帮助将不胜感激