0

假设我有一个名为“people”的数据库表,在“names”列下,有“Bill”、“Karen”和“Ted”。

在我的 php 文件中,我只想使用一个模板并使用这些行,每个名称都有一个单独的页面(例如“myfile.php?name=Bill”)。据我了解,我必须使用 GET,但我仍然对此感到困惑和缺乏经验,那么我将如何在这里实现我的目标?

4

1 回答 1

0

If you want to make a page based of a name in the get variable use this. This basicly takes the name and takes it to the database and selects all field pretaining to that name, then you echo out the varibles and place them where you want a such.

<?php
$name = $_GET["name"];//gets name value from your url that you supplied in your post
$con=mysqli_connect("127.0.0.1","db-username","db-pass","db-name");
mysqli_real_escape_string($con,$name);
$sql = mysqli_fetch_assoc(mysqli_query($con,"SELECT * FROM people WHERE names='$name'"));
$id = $sql['id'];//id would be a field in the people table
$age = $sql['age'];//age would be a field in the people table

echo '<h1>'.$name.'</h1>';
echo '<p>'. $id .'<br/>'. $ age .'</p>';

?>
于 2013-06-23T05:12:58.517 回答