为什么我的变量在PHP函数中不能作为参数使用
在我的文档顶部,我使用$\u GET创建了一个名为$selectedID的变量来获取所选用户的id(稍后我会将其切换为加密字符串),因此url看起来有点像这个概要文件。php?id=4。然后,我有一个函数,它在数据库中循环查找与$selectedID变量编号相同的所有博客文章,该变量作为函数的第二个参数输入 问题在于,我的函数$selectedId中的第二个参数应该用作在数据库中循环时过滤的数字,但似乎变量没有正确插入到我的函数中,因此循环工作不正常 这是我显示信息的主页为什么我的变量在PHP函数中不能作为参数使用,php,mysql,function,loops,parameters,Php,Mysql,Function,Loops,Parameters,在我的文档顶部,我使用$\u GET创建了一个名为$selectedID的变量来获取所选用户的id(稍后我会将其切换为加密字符串),因此url看起来有点像这个概要文件。php?id=4。然后,我有一个函数,它在数据库中循环查找与$selectedID变量编号相同的所有博客文章,该变量作为函数的第二个参数输入 问题在于,我的函数$selectedId中的第二个参数应该用作在数据库中循环时过滤的数字,但似乎变量没有正确插入到我的函数中,因此循环工作不正常 这是我显示信息的主页 <div id=
<div id="blogFeed">
<ul>
<!-- Exicute the fucntion from the functions.inc.php which grabs all the feed articles from the database -->
<?php
$_result = display_blogs_profile($connect, $selectedId);
// Count how many rows are in the database
$limit = count($_result);
// Loop through all the articles(rows) from the database
for($i = 0; $i < $limit; $i++){
// Define varibles for each column
$id = $_result[$i][6];
$title = $_result[$i][0];
$date = $_result[$i][1];
$article = $_result[$i][2];
$photo = $_result[$i][3];
$icon = $_result[$i][4];
$author = $_result[$i][5];
$findAuthor = $_result[$i][7];
$feedRadius = "50px";
$iconPhoto = "newsRed.png";
$photo = $_result[$i][3];
$feedRadius = "0px";
$contentLink = "Read More";
$realignIcon = 'margin-right: -195px;';
// Only show the first 10 articles the stop building the html
if((string)$employeeID != $findAuthor){
continue;
}else{
?>
<li>
<div class="eventBoxImage" style="background: url('images/<?php echo $photo ?>'); background-size: cover; background-position: center; border-radius: 50px"></div>
<div class="eventContentContainer">
<h1><?php echo $title; ?></h1>
<h4>Posted By: <?php echo $author; ?></h4>
<h5><?php echo $date ?></h5>
<p><?php echo $article ?></p>
<h6><a href="blog.php?id=<?php echo $id; ?>"><?php echo $contentLink ?></a></h6>
<span style="background: url('images/<?php echo $iconPhoto ?>') no-repeat; <?php echo $realignIcon; ?> background-size: 45px;"><a href="#"></a></span>
</div>
</li>
<?php }}?> <!-- Close php loop -->
</ul>
</div>
<div id="blogPostContainer">
<h1 class="blog">Create Blog Post</h1>
<form class="blog" action="includes/insert.php" method="post">
<input name="blogTitle" type="text" placeholder="Enter The Blog Title" required/>
<input name="blogArticle" type="textbox" placeholder="Enter Your Blog Post" required/>
<input name="blogSubmit" type="submit" value="Submit" />
</form>
</div>
<div id="profileSearch">
<div id="searchBar">
<form id="search" action="index.php" method="POST">
<div id="searchIcon"></div>
<input type="search" name="search" placeholder="Search Through <?php echo $firstName ?>'s Posts" onkeyup="searchQ();" />
<input type="hidden" name="editId" id="editId" value="<?php echo $employeeID ?>" />
<div id="userResults">
</div>
</form>
</div>
</div>
</div>
这是真的
“似乎未正确插入变量”
那是因为它从未被设定。试试这个:
$selectedID = $_GET['id'];
在检查if(isset($\u GET['id'])之后
if(isset($_GET['id'])){
$selectedID = $_GET['id'];
....
这是真的
“似乎未正确插入变量”
那是因为它从未被设定。试试这个:
$selectedID = $_GET['id'];
在检查if(isset($\u GET['id'])之后
if(isset($_GET['id'])){
$selectedID = $_GET['id'];
....
明白了!谢谢你的帮助!if Get语句和if$employeeID!=$Findautor语句将打破或继续循环,无论发生什么,除非是出于我自己的原因。我只需要拿$employeeID!=$芬达托尔声明:)明白了!谢谢你的帮助!if Get语句和if$employeeID!=$Findautor语句将打破或继续循环,无论发生什么,除非是出于我自己的原因。我只需要拿$employeeID!=$findAuthor陈述:)你的问题是什么?如何不起作用?你是否验证了$selectID
甚至通过echo
被传递到函数中?如果$selectedID=$\u GET['id']
那么你的If{}
将是真的,因此它将永远不会到达显示博客的配置文件($connect,$selectedID>)
在您的else{}
中。反之,如果调用了else{}
,则$selectedID
将为null
,这将导致显示博客配置文件($connect,$selectedID)
失败,因为这意味着$\u获取['id']
未设置。@Rizier123:调试成本会很高…你的问题是什么?如何不工作?你是否验证了$selectID
是否被传递到函数中,甚至带有回音?如果$selectedID=$\u get['id']
,那么你的如果{}
是真的,因此,它永远不会到达您的else{}
中的display\u blogs\u配置文件($connect,$selectedId)
。反之,如果调用了else{}
,则$selectedID
将为null
,这将导致显示博客配置文件($connect,$selectedID)
失败,因为这意味着$\u GET['id']
未设置。@Rizier123:调试成本会很高。。。