我有一个名为blogtable
的表,其中我有两个字段。一个是title
,另一个是content
。我以链接的形式检索了唯一的title
行,并将其保存在名为result.php的文件中。
<?php
mysql_connect("localhost","root","");
mysql_select_db("test");
$data = mysql_query("select title from blogtable");
while($col = mysql_fetch_field($data))
{
echo $col->name;
}
while($row = mysql_fetch_row($data))
{
for($i = 0; $i < count($row); $i++)
{
echo"<br/>";
echo "<a href='"".$row[$i]."'">".$row[$i]."</a>";
echo "<br/>";
}
}
?>
我想通过使用URL操作来检索特定的title
和content
。我试过了,但我不知道如何传递文件URL。我写了下面的代码,文件名是parse.php。
<?php
$a = $_GET['title'];
mysql_connect("localhost","root","");
mysql_select_db("test");
$sqlstmt=select * from blogtable where title=$a;
mysql_query($sqlstmt);
?>
我不知道如何解析results.php URL和动态检索数据。
在results.php文件中而不是:
echo "<a href='"".$row[$i]."'">".$row[$i]."</a>";
使用:
echo "<a href='"parse.php?title=".$row[$i]."'">".$row[$i]."</a>";
在你的"parse.php"中使用$_GET['title']
。
这是最简单的方法之一。
在"parse.php"中你需要修改:
$sqlstmt=select * from blogtable where title=$a;
:
$sqlstmt = "select * from blogtable where title='".$a."'";
然后你可以操作你的细节,从数据库中获取它。
一个建议:
使用mysqli或PDO代替mysql