'从外部获取变量时, [英] Getting variable in a loop from outside while 'function'
问题描述
我有一个while循环将用户ID分配给一个变量。该变量是一个数组。当我在这样的链接中将变量赋值给另一个变量时:它会在点击时返回正确的ID,但只有当链接处于while循环时也是如此。如何(有可能)将链接放置在while循环之外并获取变量所保存的相同ID数据?
此代码有效:
while($ row = mysqli_fetch_array($ sql)){
$ variable = $ row ['user_id'];
echo< a href ='index.php?var = $ variable'>< / a>;
}
这种情况下不会出现这种情况:
PHP:
while($ row = mysqli_fetch_array($ sql)){
$ variable []。= $ row ['user_id'];
}
HTML:
<$ ($ i = 0; $ i <100; $ i ++); p $ p>
< a href ='index.php?var = $ variable [$ i]'>< / a>
感谢您的评论..
while($ row = mysqli_fetch_array($ sql)){
$ variable []。= $ row ['user_id']; //错误
$ variable [] = $ row ['user_id']; //正确
}
foreach($ variable as $ value){
echo< a href ='index.php?var = $ value'>< / A>中; //确保使用双引号
}
I have a while loop that assigns user ID's to a variable. The variable is an array. When I assign the variable to another in a link like this: it returns proper ID's on the click but only when the link is in a while loop as well. How ( is it possible ) to place the link outside the while loop and get the same ID data the variable holds ?
This code works:
while ( $row = mysqli_fetch_array($sql)) {
$variable = $row['user_id'];
echo "<a href='index.php?var=$variable'></a>";
}
This one doesn't in this case:
PHP:
while ( $row = mysqli_fetch_array($sql)) {
$variable[] .= $row['user_id'];
}
HTML:
for ($i = 0 ; $i <100 ; $i++ );
<a href='index.php?var=$variable[$i]'></a>
Thanks for comments..
while ( $row = mysqli_fetch_array($sql)) {
$variable[] .= $row['user_id']; //Wrong
$variable[] = $row['user_id']; //Correct
}
foreach($variable as $value) {
echo "<a href='index.php?var=$value'></a>"; // Be sure to use double quotes
}
这篇关于'从外部获取变量时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!