我有一个数据库,它有很多列,我必须创建一个链接来查看更多的列。
打印当前数据库的示例。
第1行|c1|c2|c3|…|c(n-m)|"查看更多"
第2行|c1|c2|c3|…|c(n-m)|"查看更多"
这是我的代码:
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 cluase 中的row_id
SLECT .... WHERE primary_key=$_GET['row_id'].
但是,如果您要使用ajax,您必须将其转移到帖子或获取函数。并通过传递行的id(或该行的索引)来使用相同的技术。