0

我有 2 个文件fourm.php 和viewfourm.php

首先是fourm.php

<?php

$host="mysql13.000webhost.com"; // Host name 
$username="a2670376_Users"; // Mysql username 
$password="PASS"; // Mysql password 
$db_name="a2670376_Pass"; // Database name 
$tbl_name="fourm"; // Table name 

  // Connect to server and select database.
 mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
 mysql_select_db("$db_name")or die("cannot select DB");

  // select record from mysql 
  $sql="SELECT * FROM $tbl_name";
  $result=mysql_query($sql);
 ?>
<table>
<tr>
<td align="center"><strong>Post Number</strong></td>
<td align="center"><strong>UserName</strong></td>
<td align="center"><strong>Topic</strong></td>
<td align="center"><strong>Date</strong></td>
<td align="center"><strong>View</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><? echo $rows['fourmid']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><? echo $rows['username']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><? echo $rows['fourmname']; ?   >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><? echo $rows['date']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><a href="viewfourm.php?id=<? echo $rows['fourmid']; ?>">View Topic</a></td>
<?php
 // close while loop 
 }
 ?>

</tr>
</table>
<?php
// close connection; 
mysql_close();
?>
<hr width='67%' color='#29001F' size='3'/>
</center>

现在查看fourm.php

 <?php

 $host="mysql13.000webhost.com"; // Host name 
 $username="a2670376_Users"; // Mysql username 
 $password="PASS"; // Mysql password 
 $db_name="a2670376_Pass"; // Database name 
 $tbl_name="fourm"; // Table name 

   // Connect to server and select database.
   mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
   mysql_select_db("$db_name")or die("cannot select DB");

    // select record from mysql 
   $sql="SELECT * FROM $tbl_name";
   $result=mysql_query($sql);
   ?>
  <table>
  <tr>
  <td align="center"><strong>Post Number</strong></td>
 <td align="center"><strong>UserName</strong></td>
 <td align="center"><strong>Topic</strong></td>
 <td align="center"><strong>Date</strong></td>
 <td align="center"><strong>View</strong></td>
 </tr>
 <?php
 while($rows=mysql_fetch_array($result)){
 ?>
 <tr>
 <td><? echo $rows['fourmid']; ? >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
 <td><? echo $rows['username']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><? echo $rows['fourmname']; ?   >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><? echo $rows['date']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><a href="fourm.php">back/a></td>
<?php
 // close while loop 
 }
 ?>

</tr>
</table>
<?php
// close connection; 
mysql_close();
?>
<hr width='67%' color='#29001F' size='3'/>
</center>

现在在forum.php上,当我从MySql数据库中选择什么“论坛”时,我想查看它会加载我想修复的所有论坛我知道为什么它这样做它的原因是它与第一个脚本相同,只是修改了一点我做了我能做的。我正在 MySql 数据库中选择论坛的 thruefourmid 标签,这就是“>查看主题”的含义,它应该加载带有所选 id 的论坛

4

2 回答 2

0

在 viewfourm.php$sql="SELECT * FROM $tbl_name";像这样修改你的 sql 查询

$fourmid= $_POST['fourmid']; //if passing using get method use $_GET['fourmid']; $sql = "SELECT * FROM $tbl_name WHERE四中= '$fourmid'";

您还必须将fourmid 从fourm.php 传递给viewfourm.php

编辑

做一个这样的链接

<td> <a href="viewfourm.php?fourmid=<? echo $rows['fourmid']; ?>"> <? echo $rows['fourmname']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </a> </td>

于 2012-11-23T11:43:07.037 回答
0

在 form.php 中获取值

a href="viewfourm.php?id=<? echo $rows['fourmid']; ?>">View Topic</a>

//viewform.php

$fourmid= $_REQUEST[' id '];.

$sql = "SELECT * FROM $tbl_name WHEREfourmid='$fourmid'";

试试看..

于 2012-11-23T12:33:02.320 回答