类别数据库表:
id | name
1 | electronics
2 | Automotive
分类数据库表:
id user_id category_id cover title price description
102 1 2 iamges/1.jpg blabla 10 blablabla
我收到一条错误消息:注意: undefined variable :第 49 行 **\post.php 中的 name1
$id = $_GET['id'];
$res2 = mysql_query("SELECT * FROM `classifieds` WHERE `id` = '" . $id . "' LIMIT 1");
if($res2 && mysql_num_rows($res2) > 0){
while($row = mysql_fetch_assoc($res2)){
$id = $row['id'];
$user_id = $row['user_id'];
$category_id = $row['category_id'];
$price = $row['price'];
$cover = $row['cover'];
$title = $row['title'];
$description = $row['description'];
$profile_data = user_data($user_id, 'username');
$res3 = mysql_query("SELECT * FROM `categories` WHERE `id` = '" . $category_id . "' LIMIT 1");
if($res3 && mysql_num_rows($res3) > 0){
while($row1 = mysql_fetch_assoc($res3)){
$id1 = $row1['id'];
$name = $row1['name'];
}
}
}
}else{
echo 'error';
}echo $name;
为什么我得到 echo $name1; 的错误? ?
最佳答案
试试这个……
用这个替换..
$res2 = mysql_query("SELECT * FROM `classifieds` WHERE `id` = $id LIMIT 1");
还有
$res3 = mysql_query("SELECT * FROM `categories` WHERE `id` = $category_id LIMIT 1");
关于php - 从数据库中检索数据不适用于此代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21595148/