Php 从表中隐藏列
我有这个带有复选框的表,我的想法是能够删除选中复选框的行 在Charaf jra的帮助下,我能够Php 从表中隐藏列,php,html,Php,Html,我有这个带有复选框的表,我的想法是能够删除选中复选框的行 在Charaf jra的帮助下,我能够发布行的uniqID,这样我就可以在DELETE.php页面上使用mysql查询来删除它 我现在的问题是为了通过优胜劣汰,我不得不把它放在桌子上,这看起来不太好。我的意思是,我不想把身份证号码显示在桌子上。我一直在读关于如何隐藏它的书,但我读到的解释都不适用于我的情况 以下是我的代码更新: if ($arch = $pdo->prepare("SELECT name, age, uniqID F
发布
行的uniqID,这样我就可以在DELETE.php页面上使用mysql查询来删除它
我现在的问题是为了通过优胜劣汰,我不得不把它放在桌子上,这看起来不太好。我的意思是,我不想把身份证号码显示在桌子上。我一直在读关于如何隐藏它的书,但我读到的解释都不适用于我的情况
以下是我的代码更新:
if ($arch = $pdo->prepare("SELECT name, age, uniqID FROM table WHERE id = ?")) {
$arch ->execute(array($id));
$data = $arch->fetchAll();
echo '<div class="coolTable" ><form method="post" action="delete.php"><table><tr><td>Name</td><td>Age</td><td>Check</td></tr>';
foreach ($data as $row){
echo '<tr>';
foreach ($row as $col){
$col=nl2br($col);
echo '<td>'.$col.'</td>';
}
echo '<td><input type="checkbox" name="checkbox[]" value="'.$col.'" id="checkbox"></td>'; //this captures the column ID so I can pass it through the `POST`
echo '</tr>';
}
echo '</table><input type="submit" value="Delete Selected"/></form></div>';
}
if($arch=$pdo->prepare(“从id=?”的表中选择名称、年龄、uniqID”){
$arch->execute(数组($id));
$data=$arch->fetchAll();
回显“姓名检查”;
foreach($行数据){
回声';
foreach(行作为$col){
$col=nl2br($col);
回显“.$col.”;
}
echo“”;//这将捕获列ID,以便我可以通过“POST”传递它`
回声';
}
回声';
}
这很好用。唯一的大问题是我不想让人看到uniqID。有谁能告诉我,如果($arch=$pdo->prepare(“SELECT name,age,uniqID from table WHERE id=?”),如何从表中隐藏它,并且仍然能够通过POST
?if($arch=$pdo->prepare){
if ($arch = $pdo->prepare("SELECT name, age, uniqID FROM table WHERE id = ?")) {
$arch ->execute(array($id));
$data = $arch->fetchAll();
echo '<div class="coolTable" ><form method="post" action="delete.php"><table><tr><td>Name</td><td>Age</td><td>Check</td></tr>';
foreach ($data as $row){
echo '<tr>';
echo '<td>'.nl2br($row['name']).'</td>';
echo '<td>'.nl2br($row['age']).'</td>';
echo '<td><input type="checkbox" name="checkbox[]" value="'.nl2br($row['uniqID']).'" id="checkbox"></td>'; //this captures the column ID so I can pass it through the `POST`
echo '</tr>';
}
echo '</table><input type="submit" value="Delete Selected"/></form></div>';
}
$arch->execute(数组($id));
$data=$arch->fetchAll();
回显“姓名检查”;
foreach($行数据){
回声';
回显'.nl2br($row['name'])。';
回显'.nl2br($row['age'])。';
echo“”;//这将捕获列ID,以便我可以通过“POST”传递它`
回声';
}
回声';
}
PHP数组可以用作字典(如果您见过python或ruby)。PDO返回一个成对键值数组,其中键是列的名称,值是列的值。因此,您可以通过
迭代(foreach)
迭代(索引-如果知道元素在数组中的位置,则直接访问)
键(直接访问而不知道元素在数组中的位置)
假设您希望循环每行中的列,而不是像alkis建议的那样手动回显它们,则将结果作为关联数组获取,然后取消设置$row['uniqID']
if ($arch = $pdo->prepare("SELECT name, age, uniqID FROM table WHERE id = ?")) {
$arch ->execute(array($id));
$data = $arch->fetch(PDO::FETCH_ASSOC);
echo '<div class="coolTable" ><form method="post" action="delete.php"><table><tr><td>Name</td><td>Age</td><td>Check</td></tr>';
foreach ($data as $row){
if ( isset($row['uniqID']) ) {
unset($row['uniqID']);
}
echo '<tr>';
foreach ($row as $col){
$col = nl2br($col);
echo '<td>'.$col.'</td>';
}
echo '<td><input type="checkbox" name="checkbox[]" value="'.$col.'" id="checkbox"></td>'; //this captures the column ID so I can pass it through the `POST`
echo '</tr>';
}
echo '</table><input type="submit" value="Delete Selected"/></form></div>';
}
if($arch=$pdo->prepare(“从id=?”的表中选择名称、年龄、uniqID”){
$arch->execute(数组($id));
$data=$arch->fetch(PDO::fetch_ASSOC);
回显“姓名检查”;
foreach($行数据){
如果(isset($row['uniqID'])){
未设置($row['uniqID']);
}
回声';
foreach(行作为$col){
$col=nl2br($col);
回显“.$col.”;
}
echo“”;//这将捕获列ID,以便我可以通过“POST”传递它`
回声';
}
回声';
}
一个隐藏的字段是否有效:记住我正在处理的是一个foreach
循环,所以如果我添加此代码,我将隐藏该情况下的每个$colIn,你到底想实现什么?您是否只想隐藏部分ID,所有ID,其中一个ID?如果答案不是“全部”,则需要添加一个或两个If
语句(取决于您实际想要的内容)。$col不仅表示uniqID,还表示name
和age
列,这就是我的观点。我只想隐藏整个uniqID列。你建议我把你说的代码放在哪里,只隐藏uniqID列?