嗨我是一个php和html的begginer我想问我如何把这个表放入我的html候选名单。当我把我的桌子放在那个空间里时,这总是出现(“; foreach($ testaroni as $ x => $ y){echo”“; echo”“。$ y。”“;} echo”“; echo”“ ;?>) 这是我的桌子。 This is the problem (2)
<?php
session_start();
$testaroni = explode("', '" , $_SESSION["data"]);
?>
<?php
echo "<table border = '1'>";
foreach($testaroni as $x=>$y) {
echo "<tr>";
echo "<td>" . $y . "</td>";
}
echo "</tr>";
echo "</table>";
?>
我想把它放在这里。
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.links line {
stroke: #999;
stroke-opacity: 0.6;
}
.nodes circle {
stroke: #fff;
stroke-width: 1.5px;
}
text {
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
font-size: 10px;
}
</style>
<?php
session_start();
$testaroni = explode("', '" , $_SESSION["data"]);
?>
<html>
<head>
<title>Search</title>
</head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<body>
<!-- Sidebar -->
<div class="w3-sidebar w3-blue-grey w3-bar-block " style="width:15%">
<h4 class="w3-bar-item">Sidelist</h4>
<table border = "1">
<?php
foreach($testaroni as $x=>$y) {
echo '<tr>';
echo '<td>' . $y . '</td>';
}
echo '</tr>';
?>
</table>
</div>
</form>
</body>
</html>
答案 0 :(得分:1)
您只需要修改您的爆炸功能,您的代码就可以随心所欲地使用
session_start();
//lets say your $_SESSION["data"] contains
$_SESSION["data"] = 'Value1,Value2,Value3';
//$testaroni = explode("', '" , $_SESSION["data"]);// just use single or double quotes without space
$testaroni = explode("," , $_SESSION["data"]);
答案 1 :(得分:0)
你尝试var_dump($ _SESSION [“data”])你应该检查空的$ _SESSION [“data”]。我试着把
$ testaroni = array(“1”,“2”,“3”); //工作正常
答案 2 :(得分:0)
您可以详细了解我的here
好像我的眼睛失败了我花了一段时间才看到它。
尝试在PHP中使用HTML标记时,不应使用"
您需要使用的是'
。
<table border = "1">
<tr>
<?php
foreach($testaroni as $x=>$y) {
echo '<td>'.$y.'</td>';
}
?>
</tr>
</table>
原因是"
会将其中的任何内容视为字符串,而'
会将其视为字符串。
请参阅here以获得更好的解释。
另外,请按照上面的答案进行会话,因为它也是错误的。
答案 3 :(得分:0)
您的会话变量是CSV字符串。简单地在逗号上爆炸就不会得到你想要的东西。您可以使用var_dump($testaroni);
验证这一点。
使用str_getcsv
。
<?php
// always start with php logic;
// it makes the script much easier to follow and
// if you need to redirect, you haven't put out any output yet.
session_start();
// check the docs for info on this function
$testaroni = str_getcsv($_SESSION['data']);
// then, when everything is calculated, print out your output
?>
<html>
<head>
<title>Search</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<style>
.links line {
stroke: #999;
stroke-opacity: 0.6;
}
.nodes circle {
stroke: #fff;
stroke-width: 1.5px;
}
text {
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
font-size: 10px;
}
</style>
</head>
<body>
<!-- Sidebar -->
<div class="w3-sidebar w3-blue-grey w3-bar-block " style="width:15%">
<h4 class="w3-bar-item">Sidelist</h4>
<table border = "1">
<?php foreach($testaroni as $y): ?>
<tr>
<td><?= $y ?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
</form>
</body>
</html>