2014-10-27 113 views
0

我有一个数据库,有很多列,我必须创建一个链接来查看更多。PHP/MySQL如何从新窗口显示数据库行?

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

row 1 | c1 | c2 | c3 | ... | c(n-m)| '查看更多'

row 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行的其余数据?)

我打算将链接传递给一个唯一的值,然后再次搜索在那个新的页面中,只是打印它。但是,再次,“我该怎么做?”。

回答

0

您可以传递一个价值$ _GET:

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

,然后在view_more.php你用在了哪里是ROW_ID cluase

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

但是,如果你要使用AJAX你必须把它移到一个帖子或get功能。 并通过传递该行的id(或该行的index)来使用相同的技术。

+0

谢谢你!我会稍后再尝试 – 2014-10-27 09:37:39