如何使用PHP显示数据库表(仅显示具有相同car_models的表,例如BMW) [英] How to display database table using PHP (only show table with same car_models eg. BMW )
问题描述
我有一个名为汽车的数据库表
有五列
1. id < br $>
2. car_model
3. car_price
4. car_millage
5. seller_type
i不知道如何过滤我的数据库表只显示一个车型。
我尝试过:
//我在database.php中的函数
函数fetch_referrals()
{
$ sql = sprintf(select * from cars);
$ rs = mysqli_query($ this-> link,$ sql);
if(mysqli_num_rows($ rs)!= 0)
返回$ rs;
返回false;
}
//我的dashboard.php页面
<?php
$ rs = $ obj- > fetch_referrals();
$ i = 0;
if($ rs)
{while($ row = mysqli_fetch_assoc($ rs))
{$ i ++;?>
?>
}
汽车模型 | 汽车价格 | Car Millage | 卖方类型 |
---|---|---|---|
<?php if($ row ['car_model'] ==BMW)echo $行[ 'car_model']; ?> | <?php if($ row ['car_price'] ==BMW)echo $ row ['car_price']; ?> | <?php if($ row ['car_millage'] ==BMW)echo $ row ['car_millage']; ?> | <?php if($ row ['seller_type'] ==BMW)echo $ row ['seller_type']; ?> |
<?php if(!$ rs){?>
<?php}?>
sql = sprintf(select * from cars);
rs = mysqli_query(
this- >连杆,
i have database table called "cars"
with five columns
1. id
2. car_model
3. car_price
4. car_millage
5. seller_type
i don't know how to filter my database table to display one car model only.
What I have tried:
//my function in database.php
function fetch_referrals()
{
$sql=sprintf("select * from cars");
$rs = mysqli_query($this->link,$sql);
if(mysqli_num_rows($rs)!=0)
return $rs;
return false;
}
//my dashboard.php page
<?php
$rs=$obj->fetch_referrals();
$i=0;
if($rs)
{ while($row=mysqli_fetch_assoc($rs))
{ $i++;?>
?>
}
Car Model | Car Price | Car Millage | Seller Type |
---|---|---|---|
<?php if ($row['car_model']=="BMW") echo $row['car_model']; ?> | <?php if ($row['car_price']=="BMW") echo $row['car_price']; ?> | <?php if ($row['car_millage']=="BMW") echo $row['car_millage']; ?> | <?php if ($row['seller_type']=="BMW") echo $row['seller_type']; ?> |
<?php if(!$rs){?>
<?php }?>
sql=sprintf("select * from cars");
rs = mysqli_query(
this->link,
这篇关于如何使用PHP显示数据库表(仅显示具有相同car_models的表,例如BMW)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!