我看到的另一件事,但我认为如果你这样做了:
尝试:
MySQL:
/**
* Connect and define your connection var
*/
$connection = mysql_connect("localhost","root","");
/**
* Select your database
*/
mysql_select_db("mydatabase",$connection);
/**
* Check if exists "id" in $_GET
*/
if( array_key_exists( "id" , $_GET ) )
{
$id = mysql_real_escape_string( $_GET [ "id" ],$connection );
/**
* Remember use LIMIT
*/
$source = mysql_query("SELECT `name` FROM `article` WHERE `id` = '$id' LIMIT 1",$connection);
/**
* if you need print only name
*/
if( mysql_num_rows( $source ) )
{
// print only name
echo mysql_result( $source );
}
/**
* but if you need retrive array
*/
$row = mysql_fetch_assoc( $source );
echo $row["name"];
}
MySQLi:
/**
* Connect and define your connection var
*/
$connection = mysqli_connect("localhost","root","");
/**
* Check if is connected[ http://us2.php.net/manual/en/mysqli.connect-errno.php ]
*/
if( mysqli_connect_errno() == 0 )
{
/**
* Select your database
*/
mysqli_select_db( $connection , "mydatabase" );
/**
* Check if exists "id" in $_GET
*/
if( array_key_exists( "id" , $_GET ) )
{
$id = mysqli_real_escape_string($connection,$_GET [ "id" ]);
/**
* Remember use LIMIT
*/
$source = mysqli_query($connection,"SELECT `name` FROM `article` WHERE `id` = '$id' LIMIT 1");
/**
* if you need print only name
*/
if( mysqli_num_rows( $source ) )
{
// print only name
$row = mysqli_fetch_array( $source );
echo $row[0];
}
/**
* but if you need retrive array
*/
$row = mysqli_fetch_assoc( $source );
echo $row["name"];
}
}
并且,请阅读MySQL 上的LIMIT
祝你好运!