I have a list (category) from table "courses". I want when user will choose the catery he wants, he will see the list of news (from table "news") with this category. So what i need is to save the name of category, so i can search in table "news" news with this category. but fuction mysql_query doesnt want to work, i dont know where is the problem here, it shows warning:
mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in list with categories:
$conn = mysql_connect ("localhost", "root", "") or die ("Соединение не установлено!");
mysql_select_db('university');
mysql_query("SET NAMES 'utf8'");
$res = mysql_query("SELECT * FROM courses");
while($course = mysql_fetch_assoc($res)) {?>
<tr>
<td><?=$course['id']?></td>
<td><a href="category_courses_detail.php?id=<?=$course['name']?>"><?=$course['name']?> </td>
</tr><?
}?>
</tbody></table>
list with results (with warning)
<?php
$conn = mysql_connect ("localhost", "root", "") or die ("Соединение не установлено!");
mysql_select_db('university'); // выбор БД
mysql_query("SET NAMES 'utf8'"); // кодировка
$res = mysql_query("SELECT * FROM news WHERE course = {$_GET['id']}"); /* MISTAKE IS HERE*/
var_dump($res) ;
echo $_GET['id'];
mysql_error();
while($news = mysql_fetch_assoc($res)) {?>
<table border="1" align="center" style="word-wrap: break-word;" width="80%" cellspacing="0" cellpadding="1">
<tr><th width="30">ID</th><th>Название</th></tr>
<tr>
<td><a href="detail.php?id=<?=$news['id']?>"><?=$news['id']?></td>
<td><a href="detail.php?id=<?=$news['id']?>"><?=$news['program']?></td>
</tr><?
}?>
</tbody></table>
because i'm using echo $_GET['id']; i see that it gets what i need (the name of category, but still doesn't work)
and yes, i know that use mysqli or pdo is more better
Thank u, it works now.