按品牌或标题组织帖子,不包括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.

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

Since you aren't setting $brand = $_GET['brand'] it's actually just doing this in your sql query WHERE (posts.brand = '') make sure you set the variable if you want it to work.