[英]PHP/MySQL How to show a database row from a new window?
I have a database that has so many columns that I have to create a link to view more of it. 我的数据库有很多列,因此我必须创建一个链接才能查看更多内容。
Example of how I print my current database. 我如何打印当前数据库的示例。
row 1 |
第1行| c1 |
c1 | c2 |
c2 | c3 |
c3 | ... |
... | c(nm) |
c(纳米)| 'View More'
'查看更多'
row 2 |
第2行| c1 |
c1 | c2 |
c2 | c3 |
c3 | ... |
... | c(nm) |
c(纳米)| 'View More'
'查看更多'
And here's my code: 这是我的代码:
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
}
Now how do I actually print out the rest of the data of the specific row? 现在,我如何实际打印出特定行的其余数据? (When I click on the 'View More' of row 1, how do I show the rest of the data from row 1?)
(当我单击第1行的“查看更多”时,如何显示第1行的其余数据?)
I was planning on passing that one unique value with the link and just searching for that again in that new page and just printing it. 我打算通过链接传递该唯一值,然后在新页面中再次搜索该值并打印出来。 But again, "how do i do that?".
但是,再次,“我该怎么做?”。
You can pass that value in $_GET: 您可以在$ _GET中传递该值:
$pk = $row['primary_key'];
echo "<a href='view_more.php?row_id=$pk' target='_blank'>View More</a>";
and then in view_more.php you use that row_id in the where cluase 然后在view_more.php中,在where线索中使用该row_id
SLECT .... WHERE primary_key=$_GET['row_id'].
But if you're going to use ajax you have to move this to a post or get funciton. 但是,如果您要使用ajax,则必须将其移至帖子或获取功能 。 and use the same technique by passing the id of the row (or the index of that row).
并通过传递该行的ID(或该行的索引 )来使用相同的技术。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.