如何使PHP功能在另一页上工作

时间:2017-05-25 11:58:30

标签: php ajax

我有包含新闻的index.php,我想点击readmore按钮重定向到readmore.php页面,并从数据库中显示该新闻的news_desc

index.php:

           <div class="content_container">  
      <h3> <?php echo $rowNews['newstitle'];?></h3> 
      <p><?php echo $rowNews['news_bio'];?></p>
              <img src="<?php echo $rowNews['news_image'];?>" alt="Smiley face" height="191" width="140">
       <div class="button_small">
                   <a href="readmore.php">Read more</a>
      </div><!--close button_small-->
    </div><!--close content_container-->

        <?php 
      }
      } 
        ?>

readmore.php:     

    <p id = "fullNewsP"  style="font-size:25px">news_desc here</p>      

    </div><!--close content_container-->

2 个答案:

答案 0 :(得分:0)

index.php

<a href="readmore.php?q=<?php echo $rowNews['newstitle'];?>">Read more</a>

readmore.php

$selectNews = "SELECT * FROM news where newstitle = ".$_GET['q'];

答案 1 :(得分:0)

您的更多按钮应该发送新闻文章的ID。

<a href="readmore.php?=<?php echo $dbid; ?>">Read more</a>

然后在readmore.php页面上:

$db_id = (int)$_GET['id'];

然后从数据库中提取所有数据并根据需要显示它。这是它最简单的形式。在实施之前检查所有安全设置和内容,但它会给你一个好主意。