dongyao2001 2015-05-07 17:50
浏览 12
已采纳

按品牌或标题组织帖子,不包括id

I have a menu, and in this menu there is an option to select posts which have a certain brand name in the database. When clicked no the brand name in the menu I want the user to be directed to the page which has posts with only that brand name in the database.

This is my button url:

        <a href="brands.php?brand=ALange&Söhne">A. Lange & Söhne</a>

This is my sql call:

if($_GET){
$id1 = $_GET['id'];
        $id1 = (int) $id1;
$sql = "SELECT posts.id AS postid, 
        category.id AS catid,
        category.catname,
        posts.id,
        posts.cat_id,
        posts.brand,
        posts.auction,
        posts.likes,
        posts.image,
        posts.title,
        posts.textbody,
        posts.author,
        posts.postdate
        FROM posts INNER JOIN category ON category.id= posts.cat_id WHERE         (posts.brand ='$brand')";
//"SELECT * FROM posts WHERE id='$id1' ORDER BY postdate DESC LIMIT 1";
$query = mysqli_query($db_conx, $sql);
$statusnumrows = mysqli_num_rows($query);
//get set above for ID
} 
else if(!$_GET){
$sql = "SELECT posts.id AS postid, 
        category.id AS catid,
        category.catname,
        posts.id,
        posts.cat_id,
        posts.brand,
        posts.auction,
        posts.likes,
        posts.image,
        posts.title,
        posts.textbody,
        posts.author,
        posts.postdate
        FROM posts INNER JOIN category ON category.id= posts.cat_id WHERE       (posts.brand ='$brand') ORDER BY postdate DESC";

It doesnt seem to be working. how can I get the user to go to a list of posts with only one chosen brand. Right now it displays the two posts I have where the BRAND section is left black in the database.

  • 写回答

2条回答 默认 最新

  • doudiandi6967 2015-05-07 18:22
    关注

    Just from looking at this, it looks like you are not grabbing the GET data. You are sending the query string "?brand=ALange&Söhne" but your GET is looking for "id" instead.

    What happens if you change your PHP to:

    $brand = $_GET['brand'];
    

    Not sure if you have anything else passed via GET, though. Hope that helps you out.

    --Charles

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法