在循环中获取$ _GET值

时间:2016-06-08 16:55:55

标签: php

我无法看到这段代码的问题看起来很简单,我有一个基本的网页:

<?php

include('includes/db_connection.php');
include('includes/functions.php');
include('includes/arrays.php');

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Payday Dreams</title>
<link href='http://fonts.googleapis.com/css?family=Nunito:400,300,700' rel='stylesheet' type='text/css'>
<link href="templates/css/main.css" rel="stylesheet" type="text/css" />
<link href="templates/css/bootstrap_v3.css" rel="stylesheet" type="text/css" />
<style type="text/css">
body{background:url(templates/images/bg_sub.png) repeat-x;}
</style>
<script type="text/javascript" src="templates/js/jquery.js"></script>
<script type="text/javascript" src="templates/js/bootstrap.js"></script>
<script type="text/javascript" src="templates/js/json2.js"></script>
<script type="text/javascript" src="templates/js/common.js"></script>
<script type="text/javascript" src="templates/js/ajax.js"></script>
</head>
<body style="background:#cfe4ee;">
<div style="height:100px; background:#000;">
<div style="width:971px; margin:0 auto; color:#ffffff; font-size:13px;">
<div style="text-align:center; padding-top:10px; font-size:16px; font-weight:bold; font-family:Arial"> <img src="templates/images/small_lock.png" alt="" style="vertical-align:middle" />&nbsp;Unlock this page to continue! 
<br />
<p class="link_ins">TEST</p>
<div id="_ostatus" style="color:#ffffff;  font-size:14px; font-weight:normal">&nbsp;</div>
</div>
</div>
</div>
<div id="linklocker_wrapper">
<div id="contents" style="margin-top:100px;">
<div class="jumbotron"> 
<div id="offersSection2" style="height:250px; width:570px; margin:25px auto" >

<!-- offer box -->
<div class="offerp_box3" >
<div class="mid" style="height:220px">
<div id="_offers">
<table class="table table-hover table-bordered table-condensed" style="width:530px; background:#ffffff; border:1px solid #cccccc;">
<?php
  // get offers from the database
  $rows = DB::getInstance()->select('SELECT * FROM `offers` ORDER BY RAND() LIMIT 5');   
?>
<?php foreach ($rows as $row) { ?>
<?php
 print_r($_GET);
 $p = $_GET['p'];
 echo $p;
?>
    <tr >
        <td class="offerDiv" title="<?php echo $row['offer_title']; ?>" style="height:30px; vertical-align:middle">
        <div><img src="templates/images/chk.png" alt="" />&nbsp;&nbsp;<a href="click.php?c=<?php echo $row['offer_title_id']; ?>&l=&p=<?php echo $p; ?>" target="_blank"><?php echo $row['offer_title']; ?></a></div>
        </td>
    </tr>
<?php } ?>
</table>
</div>
</div>
</div>

<div id="dform" style="display:none; width:90%; text-align:center">
</form>
</div>
</div>
</div>

网址是这样的:http://www.site.co.uk/page.php?l=1p=7我想要做的是获取$ _GET [&#39; p&#39;]的值,并在foreach循环中使用它,当我尝试在循环中打印出它的空白但在进入循环之前显示正常,我绞尽脑汁我无法想到获得该价值的另一种方式,任何帮助都将受到赞赏

2 个答案:

答案 0 :(得分:1)

您的网址是否正确?令人信服的是,您要做的是:http://www.site.co.uk/page.php?l=1&p=7请注意网址中的&amp; 。你有:http://www.site.co.uk/page.php?l=1p=7。这是故意的吗?

答案 1 :(得分:1)

在您的网址中,两个查询字符串参数需要用&amp;分隔。它无法识别p是什么。

http://www.site.co.uk/page.php?l=1&p=7