Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何仅回显我的$行的索引_Php_Html_Arrays_Row - Fatal编程技术网

Php 如何仅回显我的$行的索引

Php 如何仅回显我的$行的索引,php,html,arrays,row,Php,Html,Arrays,Row,嗨,我有一个$row2,我只需要回显第一个索引,但是我的语法有问题$第2行有5个值,我只需要回显第一个值 <select class="input form-control" id="Intervention1" name="Intervention1" required> <?php $diag = " SELECT walkindetails.IntID, intervention.IntName FROM walkindetails INNER JOIN in

嗨,我有一个$row2,我只需要回显第一个索引,但是我的语法有问题$第2行有5个值,我只需要回显第一个值

<select class="input form-control" id="Intervention1" name="Intervention1" required>

<?php
    $diag = " SELECT walkindetails.IntID, intervention.IntName FROM walkindetails  INNER JOIN intervention on walkindetails.IntID = intervention.IntID  WHERE TID = '{$row['TID']}'";
    $diagarray = mysqli_query($conn, $diag);
    $intarray = array();
    if ($conn->error) {
        die("Query failed: " . $conn->error);
    }
    while($row2 = mysqli_fetch_array($diagarray)) {
        echo "   <option value=". $row2['IntName'] ." style='display: none;'>". $row2['IntName'] . "</option>";     
    }
?>
</select>

您现在有两种可能性:

限制PHP输出:

<select class="input form-control" id="Intervention1" name="Intervention1" required>

<?php
$diag = " SELECT walkindetails.IntID, intervention.IntName FROM walkindetails  INNER JOIN intervention on walkindetails.IntID = intervention.IntID  WHERE TID = '{$row['TID']}'";
$diagarray = mysqli_query($conn, $diag);
$intarray = array();
if ($conn->error) {
    die("Query failed: " . $conn->error);
}
$row2 = mysqli_fetch_array($diagarray);
echo "   <option value=". $row2['IntName'] ." style='display: none;'>". $row2['IntName'] . "</option>";    
?>
<?php
$diag = " SELECT walkindetails.IntID, intervention.IntName FROM walkindetails  INNER JOIN intervention on walkindetails.IntID = intervention.IntID  WHERE TID = '{$row['TID']}' LIMIT 1";
$diagarray = mysqli_query($conn, $diag);
$intarray = array();
if ($conn->error) {
    die("Query failed: " . $conn->error);
}
while($row2 = mysqli_fetch_array($diagarray)) {
    ?>
    <?php echo "   <option value=". $row2['IntName'] ." style='display: none;'>". $row2['IntName'] . "</option>";     ?>
    <?php
}
?>
现在查询只输出一个数据集


<?php
$myVar = 1; // temporary variable for inner if statement
while($row2 = mysqli_fetch_array($diagarray)) {
    if($myVar) {
        echo "<option value=". $row2['IntName'] ." style='display: none;'>". $row2['IntName'] . "</option>";
    }    
    $myVar = 0; // if will never evaluate to true again
 }
?> 

没有限制输出那么漂亮,但是只有当if语句的计算结果为true时才会回显。这只是第一次出现。

既然你似乎知道“我的语法有问题”,你能告诉我们什么吗?您会说:“$row2有5个值,我只需要回显第一个值。”。我们可以看到它有两个“值”,所以也许你的意思是它有五行,你只想回显第一行?你可以根据下面的答案更新你的代码,或者只添加
break在echo和您完成后:)请您的答案解释为什么这段代码回答了这个问题。