我的问题是我需要根据以前的MYSQL SELECT从MYSQL表中选择字段。在我通过if和else if语句执行此操作之前,它只能是两件事之一,但现在我添加了第三条,所以这不再适用。这就是我想要的效果:
$call = "SELECT * FROM blog_posts WHERE id = $_GET[id] LIMIT 1";
$latest = mysql_query($call);
$result = mysql_fetch_array($latest);
$post_cat = $result['category'];
$sql="SELECT title, post_thumb, id FROM blog_posts WHERE category = $post_cat AND id <> $_GET[id] ORDER BY id DESC LIMIT 6";
提前致谢。
答案 0 :(得分:0)
$sql="SELECT `title`, `post_thumb`, `id` FROM `blog_posts` WHERE category = '".$post_cat."' AND `id` = '".$_GET[id]."' ORDER BY `id` DESC LIMIT 6";
将表/列放在反引号中,并将PHP变量括在连接引号中。目前,您的查询要求MySQL在类别列中找到$post_cat
的值。不是PHP变量$post_cat
,显式字符串$_post_cat
。