将php数组放入html代码中
我使用一个名为smarty的模板php系统很容易做到这一点。我目前无法使用smarty,所以我必须手动操作,但我已经完全忘记了如何以及什么是可能的将php数组放入html代码中,php,Php,我使用一个名为smarty的模板php系统很容易做到这一点。我目前无法使用smarty,所以我必须手动操作,但我已经完全忘记了如何以及什么是可能的 <? foreach ($searchresults as $row) { ?> <tr class="tableRows"> <td><img style="cursor: pointer
<? foreach ($searchresults as $row) { ?>
<tr class="tableRows">
<td><img style="cursor: pointer;" src="img/expand.png" id="1" alt="hidden" onclick="changeSign()" /></td>
<td><a href="#"><? echo $row[0]; ?></a></td>
<td><? echo $row[1]; ?></td>
<td><? echo $row[2]; ?></td>
<td><? echo $row[3]; ?></td>
<td><? echo $row[4]; ?></td>
<td><input type="button" value="Delete" class="deleteBtn" /></td>
</tr>
<? } ?>
</table>
</fieldset>
<?php } ?>
将
echo$row[i]
而不是$row[i]
仅放置您没有对变量执行任何操作。您需要输出它:
<td><?= $row[1] ?></td>
等等。您需要
回送变量
差不多
<? foreach ($searchresults as $row) { ?>
<tr class="tableRows">
<td><img style="cursor: pointer;" src="img/expand.png" id="1" alt="hidden" onclick="changeSign()" /></td>
<td><a href="#"><? echo $row[0]; ?></a></td>
<td><? echo $row[1]; ?></td>
<td><? echo $row[2]; ?></td>
<td><? echo $row[3]; ?></td>
<td><? echo $row[4]; ?></td>
<td><input type="button" value="Delete" class="deleteBtn" /></td>
</tr>
<? } ?>
etc在$row[1]之前尝试echo
所以你的答案是:
<? foreach ($searchresults as $row) { ?>
<tr class="tableRows">
<td><img style="cursor: pointer;" src="img/expand.png" id="1" alt="hidden" onclick="changeSign()" /></td>
<td><a href="#"><?php echo $row[0]; ?></a></td>
<td><?php echo $row[1]; ?></td>
<td><?php echo $row[2]; ?></td>
<td><?php echo $row[3]; ?></td>
<td><?php echo $row[4]; ?></td>
<td><input type="button" value="Delete" class="deleteBtn" /></td>
</tr>
<? } ?>
必须使用echo
显示任何变量或文本。或使用
echo”“;打印(行);回声“代码>用于显示整个阵列试试这个,希望它能工作
<?php
foreach ($searchresults as $row)
{ ?>
<tr class="tableRows">
<td><img style="cursor: pointer;" src="img/expand.png" id="1" alt="hidden" onclick="changeSign()" /></td>
<td><a href="#"><?php echo $row[0]; ?></a></td>
<td><?php echo $row[1]; ?></td>
<td><?php echo $row[2]; ?></td>
<td><?php echo $row[3]; ?></td>
<td><?php echo $row[4]; ?></td>
<td><input type="button" value="Delete" class="deleteBtn" /></td>
</tr>
<?php } ?>
在$row[1]之前尝试echo“这不起作用。”这是无用的诊断信息。它是怎么工作的?我添加了echo,我忘了,我有它,但正在尝试其他东西,它仍然没有回声。请尝试打印($searchresults)以检查您的数组是否为空。我刚刚发布了var_dump吐出的内容…我还打印了\r,并进行了填充谢谢:)这可以解决一些我需要自己解决的问题,但这太完美了,谢谢。
<?php
foreach ($searchresults as $row)
{ ?>
<tr class="tableRows">
<td><img style="cursor: pointer;" src="img/expand.png" id="1" alt="hidden" onclick="changeSign()" /></td>
<td><a href="#"><?php echo $row[0]; ?></a></td>
<td><?php echo $row[1]; ?></td>
<td><?php echo $row[2]; ?></td>
<td><?php echo $row[3]; ?></td>
<td><?php echo $row[4]; ?></td>
<td><input type="button" value="Delete" class="deleteBtn" /></td>
</tr>
<?php } ?>