I can not find nothing on internet about getting category id in url, so I post here.
I want an url like this : localhost/index.php&cat=1
, when I press submit button.
I use this code:
<form method="post" id="categories">
<select name="category">
<option value="">Select a category</option>
<?php
getCats();
?>
</select>
<button type="submit" form="categories" value="Submit">Submit</button>
</form>
and getcats
:
function getCats(){
global $con;
$get_cats = "select * from category";
$run_cats = mysqli_query($con, $get_cats);
while ($row_cats=mysqli_fetch_array($run_cats)){
$cat_id = $row_cats['cat_id'];
$cat_name = $row_cats['name'];
echo "<li><button><a href='index.php?cat=$cat_id'>$cat_name</a></button></li>";
}
}
It's possible to use form action=
in this case?
tag. and echoing- In