试图从数据库中选择某个类别

时间:2014-01-21 20:12:18

标签: php sql

我是一个真正的新手,当谈到sql但我试图拿起我的朋友网站的碎片......除了左手导航到某些类别,它似乎都工作正常。 这是网站:http://tyresinwigan.co.uk/new/

各个制造商应直接指向每个制造商,但他们似乎列出了所有制造商的结果。

以下是 search.php 的代码:

                <?php
require_once('const.php');
$link = dbConnect();

$manufacturer_id = 0;
$name = '';
if (isset($_GET['make']) && is_numeric($_GET['make'])) {
$manufacturer_id = (int) $_GET['make'];
}

$query = "SELECT manufacturer_name FROM manufacturer_tbl WHERE manufacturer_id =     $manufacturer_id";
$result = false;
$result = @mysql_query($query, $link);
if (($result) && (@mysql_num_rows($result) > 0)) {
$row = @mysql_fetch_array($result, MYSQL_ASSOC);
$name = stripslashes($row['manufacturer_name']);
}

$query = "SELECT *, 
      v.vehicle_id AS vehicle_id_alias 
 FROM vehicle_tbl AS v
 LEFT JOIN image_tbl AS i ON v.vehicle_id = i.vehicle_id 
 GROUP BY v.vehicle_id 
 HAVING v.manufacturer_id = $manufacturer_id";

$offers = false;
$offers = @mysql_query($query, $link);
$items = 0;
if ($offers) $items = mysql_num_rows($offers);

function nextOffer() {
global $offers;
global $items;
$items --;
if ($offers && ($row = mysql_fetch_array($offers))) {
    if (! isset($row['image_name'])) { // no image
        $image = 'images/noimagesml.jpg';
    } else {
        $image = 'images/vehicles/sml/'.stripslashes($row['image_name']);
    }
    $title = stripslashes($row['manufacturer_name']).' '.stripslashes($row    ['vehicle_model']);
    $price = number_format((float) $row['vehicle_price_pcm'], 2);
    $id = (int) $row['vehicle_id_alias'];
    echo '<table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td class="contenthead"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                          <tr>
                            <td width="11" height="40" align="left" valign="top"><img src="images/featre_left_hd.gif" width="11" height="23"></td>
                            <td width="100%" align="left" valign="middle" class="contenthead">'.$title.'</td>
                            <td width="11" height="40" align="right" valign="top"><img src="images/featre_rght_hd.gif" width="11" height="23"></td>
                          </tr>
                        </table></td>
                      </tr>
                      <tr>
                        <td class="contentpane"><table width="100%"  border="0" cellspacing="5" cellpadding="0">
                          <tr>
                            <td align="center" valign="middle"><img src="'.$image.'" width="100"     height="58" class="bordered" alt="'.$title.'"></td>
                          </tr>
                          <tr>
                            <td align="center" valign="top" class="princing">from just &pound'.$price.' pcm</td>
                          </tr>
                          <tr>
                            <td align="right" valign="middle"><a href="cardeal.php?vehicle='.$id.'"><img src="images/more_butt.gif" width="54" height="20" border="0"></a></td>
                          </tr>
                        </table></td>
                      </tr>
                    </table>';
} else {
    echo '&nbsp;';
}
}

?>

2 个答案:

答案 0 :(得分:0)

您正在查看错误的查询。问题不在左侧菜单中,而是在结果页面上进行查询。您需要查看那个,并确保其格式正确。

答案 1 :(得分:0)

变化:

$query = "SELECT * FROM vehicle_tbl LEFT JOIN image_tbl ON vehicle_tbl.vehicle_id =         image_tbl.vehicle_id  
      WHERE vehicle_tbl.manufacturer_id = $manufacturer_id
      GROUP BY vehicle_tbl.vehicle_id";

为:

$query = "SELECT * FROM vehicle_tbl LEFT JOIN image_tbl ON vehicle_tbl.vehicle_id =         image_tbl.vehicle_id  
      GROUP BY vehicle_tbl.vehicle_id
      HAVING vehicle_tbl.manufacturer_id = $manufacturer_id";