[英]How to get variable for category_ID in this code
PHP: PHP:
<?php
$con = mysqli_connect("localhost","root","","bookofexperiences");
$sql2 ="SELECT Category_Title FROM category WHERE Category_ID=5";
$query = mysqli_query($con, $sql2);
$row = mysqli_fetch_assoc($query);
$scategory = $row['Category_Title'];
echo("<h3>". $scategory. "<h3/>");
echo("<hr><br>");
?>
I want get different Category_ID
when pressing different button. 我想按不同的按钮时得到不同的Category_ID
。 Now I'm using each button for different page which had only changed Category_ID
. 现在,我将每个按钮用于仅更改Category_ID
不同页面。 when I press a button, I got "Category_ID=5" and their content. 当我按下一个按钮时,我得到了“ Category_ID = 5”及其内容。 When I press a another button, I got "Category_ID=6" and their content. 当我按下另一个按钮时,我得到了“ Category_ID = 6”及其内容。 But Now I used two different pages for this work. 但是现在我使用了两个不同的页面来完成这项工作。 I want fix this one for one page. 我要将此问题修复为一页。 please help me how to fix this problem 请帮我解决这个问题
make the category id part of the url, then use $_GET to pull it into your query. 将类别ID设置为网址的一部分,然后使用$ _GET将其拉入查询。 So your url would be your domain.com/index.php?category=5 所以您的网址就是您的domain.com/index.php?category=5
then you code would change to: 那么您的代码将更改为:
$sql2 = "SELECT Category_Title FROM category WHERE Category_ID='$_GET[category]'";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.