私が見る別のことですが、あなたがした場合:
- MySQL サーバーに接続できましたか?
- 使用するデータベースを選択しましたか?
- PHPのmysql_result関数を知っていますか? と
- MySQLのLIMITを知っていますか?
試す:
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"];
}
MySQL:
/**
* 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について読んでください。
幸運を!