php - displaying accurate results -


i'm creating web site directory mobile site (found here)

i have figured out how display listings mysql table home page tables promo_cat list.

the thing im having trouble this:

once clicking on 1 of catagories leads me list.php page.

how page display results related category clicked , not others?

for example:when clicking on "free" brings page: http://www.xclo.mobi/xclo2/list.php?id=free. displays results. should display results have promo_cat field "free" , should not display other results currently.

my list.php code:

<?php  include_once('include/connection.php'); include_once('include/article.php');  $article = new article; $articles = $article->fetch_all();  ?>  <html>  <head> <title>xclo mobi</title> <link rel="stylesheet" href="other.css" /> </head>  <body> <?php include_once('header.html'); ?>   <div class="container"> <a href="index.php" id="logo">category = ???</a>  <ol>     <?php foreach ($articles $article) { ?>  <div class="border"> <a href="single.php?id=<?php echo $article['promo_title']; ?>" style="text-decoration: none"> <img src="<?php echo $article['promo_image']; ?>" border="0" class="img" align="left"><br />   <a href="<?php echo $data['promo_link']; ?>" target="_blank"><img alt="" title="" src="go.png" height="50" width="50" align="right" /></a>            <font class="title"><em><center><?php echo $article['promo_title']; ?></center></em></font>  <br /><br />  <font class="content"><em><center><?php echo $article['promo_content']; ?></center></em></font>  </div><br/><br />            </a>   <?php } ?> </ol> </div> </body>  </html> 

/include/article.php

<?php  class article { public function fetch_all(){     global $pdo;       $query = $pdo->prepare("select * mobi");       $query->execute(); return $query->fetchall();               }  public function fetch_data($promo_title) {    global $pdo;   $query = $pdo->prepare("select * mobi promo_title = ?");   $query->bindvalue(1, $promo_title);    $query->execute();  return $query->fetch();   }  }  ?> 

based on code provided, try this:

<?php foreach ($articles $article) {     if ($article['promo_cat'] === 'free') { ?>     // keep rest of code     //instead of <?php } ?> - put...    <?php } } ?> 

keep in mind, messy. foreach statement (i imagine) being used print out posts. so, before printing out post, check see if promo_title free, gift, etc. if it's not, doesn't print item.

you can make more dynamic passing in $_get variable (which apparently doing, code never using variable) current promo title , altering conditional line

if ($article['promo_cat'] === $_get['id'])

hope helps!


Comments