0

有两个这样的mysql表:

表格1

--id-----config_name --1
-----操作系统--2
-----控制面板--3
-----带宽

表 2

id -- config_id--- config_Option_name --- 价格
1--------1-------------Windows 2008--------20.00
2--- ------1-------------CentOs 5----------------0.00
3-------- 2-- ------------whm/cPanel------------30.00
4--------2-------------Plesk -------------------50.00


现在我想像这样向他们展示:

操作系统
Windows 2008 = 20.00
CentOs 5 = 00.00
控制面板
whm/cPanel= 30.00
Plesk = 50.00

请帮我这样做。

4

3 回答 3

0

试试这个 :

Select config_name, config_Option_name, price 

from table1 
inner join table2 on (table1.id=table2.config_id)
于 2012-12-05T06:19:05.263 回答
0

给你一个想法:

public $dbserver = '';
public $dbusername = '';
public $dbpassword = '';
public $dbname = '';

function openDb() {
    try {
        $db = new PDO('mysql:host=' . $this->dbserver . ';dbname=' . $this->dbname . ';charset=utf8', '' . $this->dbusername . '', '' . $this->dbpassword . '');
    } catch (PDOException $e) {
        die("error, please try again");
    }
    return $db;
}

function getRecords() {
    $query = "select * from table1 inner join table2 on table1.id=table2.config_id";
        $stmt = $this->openDb()->prepare($query);
        $stmt->execute();
        $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
        return $rows;
}

$getAllRows = getRecords();

foreach ($getAllRows as $counter => $row) {
  //this is where you format and output stuff
  echo $row[0] . " and " . $row[1] . " and so on<br>";
 }
于 2012-12-05T06:20:40.203 回答
0

这就是我一直在寻找的东西

$search = "SELECT a,b FROM DB WHERE x LIKE '$var' LIMIT 0 , 30";
$result = mysql_query($search, $connection);
if($result){
while ($row = mysql_fetch_array($result)){
echo $row["a"]." ".$row["b"]." ";
$search2 = "SELECT a,b FROM DB WHERE x = '".$row['a']."' LIMIT 0 , 100";
$result2 = mysql_query($search2, $connection);
if($result2){
while ($row2 = mysql_fetch_array($result2)) {
echo $row2["a"]." ".$row2["b"]." ";
}
} else {
echo "主题搜索失败。



} else {
echo "主题搜索失败。";
回声 mysql_error();
}

于 2012-12-10T05:19:41.023 回答