显示准确的结果 [英] displaying accurate results

查看:208
本文介绍了显示准确的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的移动网站创建网站目录(此处

I'm creating a web site directory for my mobile site (FOUND HERE)

我想出了如何从我的表promo_cat列表显示从我的mysql表到我的主页的列表。

I have figured out how to display listings from my mysql table to my home page from my tables promo_cat list.

遇到麻烦的事情是这样的:

The thing im having trouble with is this:

一旦点击了它的一个catagories我的list.php页面。

once clicking on one of the catagories it leads me to my list.php page.

如何让此网页显示与点击类别而非其他类别相关的结果?

How do I get this page to display results related to the category clicked and not others?

:点击免费时出现此页: http://www.xclo .mobi / xclo2 / list.php?id =免费。其中显示所有结果。它应该只显示具有promo_cat字段为FREE的结果,并且不应显示任何其他结果,因为它目前。

For example:when clicking on "FREE" brings up this page: http://www.xclo.mobi/xclo2/list.php?id=FREE. Which displays all results. it should only display results that have a promo_cat field as "FREE" and should not display any other results as it does currently.

我的list.php代码

<?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 as $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 * FROM mobi");
      $query->execute();
return $query->fetchAll();
              }

public function fetch_data($promo_title) {
   global $pdo;

 $query = $pdo->prepare("SELECT * FROM mobi WHERE promo_title = ?");
  $query->bindValue(1, $promo_title);
   $query->execute();

return $query->fetch(); 

}

}

?>


推荐答案

根据您提供的代码, / p>

Based on the code you provided, try this:

<?php foreach ($articles as $article) { 
   if ($article['promo_cat'] === 'FREE') { ?>

   // Keep the rest of the code

   //instead of <?php } ?> - put...
   <?php } } ?>

请记住,这很乱。但是 foreach 语句(我想象)正在用于打印所有帖子。所以,在打印出一个帖子之前,你只需检查promo_title是否是免费的,GIFT等。如果不是,那么它不打印该项目。

Keep in mind, this is messy. But the foreach statement (I imagine) is being used to print out all posts. So, before printing out a post, you just check to see if the promo_title is FREE, GIFT, etc. If it's not, then it doesn't print that item.

您可以通过传递一个$ _GET变量(您显然正在做,但代码从不使用此变量)与当前促销标题和改变条件行以表示

You can make this more dynamic by passing in a $_GET variable (which you apparently are doing, but the code is never using this variable) with the current promo title and altering the conditional line to say

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

希望有所帮助!

这篇关于显示准确的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆