gpt4 book ai didi

PHP/MySQL 如何从新窗口显示数据库行?

转载 作者:行者123 更新时间:2023-11-29 23:30:57 25 4
gpt4 key购买 nike

我的数据库有很多列,我必须创建一个链接才能查看更多列。

如何打印当前数据库的示例。

row 1 | c1 | c2 | c3 | ... | c(n-m) | 'View More'

row 2 | c1 | c2 | c3 | ... | c(n-m) | 'View More'

这是我的代码:

while($row = $result->fetch_array()){   //creates a loop to loop through results

echo "<tr><td>"; //start a row and cell tag in HTML

for($i=0;$i<12;$i++){ //Creates a loop to print the results

if($i == 1){ //concatenates the names
echo $row[$search_value[$i + 1]] . " " . $row[$search_value[$i + 2]] . " " . $row[$search_value[$i]] . "</td><td>";
$i = $i + 2; //skips the next two since its already printed
} else if($i == 5){ //concatenates the addresses
echo $row[$search_value[$i]] . ", " . $row[$search_value[$i + 1]] . ", " . $row[$search_value[$i + 2]] . "</td><td>";
$i = $i + 2; //skips the next two since its already printed
} else {
echo $row[$search_value[$i]] . "</td><td>"; //prints the specified value and the end and start of a table cell
}
}

echo "<a href='view_more.php' target='_blank'>View More</a>";
echo "</tr></td>"; //ends a row and cell tag in HTML

}

现在我如何实际打印出特定行的其余数据? (当我点击第 1 行的“查看更多”时,如何显示第 1 行的其余数据?)

我计划通过链接传递一个唯一值,然后在新页面中再次搜索该值并打印它。但再次,“我该怎么做?”。

最佳答案

您可以在 $_GET 中传递该值:

 $pk = $row['primary_key'];
echo "<a href='view_more.php?row_id=$pk' target='_blank'>View More</a>";

然后在 view_more.php 中使用 where 子句中的 row_id

 SLECT .... WHERE primary_key=$_GET['row_id'].

但是如果您要使用ajax,则必须将其移至帖子或get功能。并通过传递行的 id(或该行的 index)来使用相同的技术。

关于PHP/MySQL 如何从新窗口显示数据库行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26581631/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com