select * from channel_list,其中ch ="。$ ch。不起作用

时间:2015-01-28 19:45:01

标签: php mysql select

我想选择channel1

我的表看起来像这样

ch_id      ch      ch_name
1          ch1     channel 1
2          ch2     channel 2
3          ch3     channel 3
4          ch4     channel 4

我尝试使用url

选择channel1
exemple.com/channel.php?ch=ch1

当我使用这个

<?php
include('dbconfig.php');
$ch = $_GET['ch'];
$qry="select * from channel_list where ch=".$ch.
$row = mysql_fetch_array(mysql_query($qry));
 ?>

它告诉我这个错误

  

警告:mysql_fetch_array()要求参数1为资源,第5行/home/.../public_html/channel.php中给出布尔值

先谢谢

1 个答案:

答案 0 :(得分:2)

更好地使用mysqli :)这样可行。 Official docs

<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

/* check connection */
if ($mysqli->connect_errno) {
    printf("Connect failed: %s\n", $mysqli->connect_error);
    exit();
}

$query = "SELECT Name, CountryCode FROM City ORDER by ID LIMIT 3";
$result = $mysqli->query($query);

/* numeric array */
$row = $result->fetch_array(MYSQLI_NUM);
printf ("%s (%s)\n", $row[0], $row[1]);

/* associative array */
$row = $result->fetch_array(MYSQLI_ASSOC);
printf ("%s (%s)\n", $row["Name"], $row["CountryCode"]);

/* associative and numeric array */
$row = $result->fetch_array(MYSQLI_BOTH);
printf ("%s (%s)\n", $row[0], $row["CountryCode"]);

/* free result set */
$result->free();

/* close connection */
$mysqli->close();
?>