Answer the question
In order to leave comments, you need to log in
How to get an array?
Working source code
<?php
$con = mysqli_connect("localhost","root","root","demo");
$brand_query = "SELECT * FROM xf_category";
$brand_query_run = mysqli_query($con, $brand_query);
if(mysqli_num_rows($brand_query_run) > 0)
{
foreach($brand_query_run as $brandlist)
{
$checked = [];
if(isset($_GET['category']))
{
$checked = $_GET['category'];
}
?>
<div>
<input type="checkbox" name="category[]" value="<?= $brandlist['id']; ?>"
<?php if(in_array($brandlist['id'], $checked)){ echo "checked"; } ?>
/>
<?= $brandlist['title']; ?>
</div>
<?php
}
}
else
{
echo "No Brands Found";
}
?>
<?php
if(mysqli_num_rows($category_query) > 0)
{
foreach($category_query as $categorylist)
{
$checked = [];
if(isset($_GET['category']))
{
$checked = $_GET['category'];
}
?>
<div>
<input type="checkbox" name="category[]" value="<?= $categorylist['id']; ?>"
<?php if(in_array($brandlist['id'], $checked)){ echo "checked"; } ?>
/>
<?= $categorylist['title']; ?>
</div>
<?php
}
}
else
{
echo "No Categorys Found";
}
?>
//Read xf_category
$sql = $pdo->prepare("SELECT * FROM xf_category");
$sql->execute();
$category_query = $sql->fetchAll(PDO::FETCH_OBJ);
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, array given in
Answer the question
In order to leave comments, you need to log in
Tell me what I did wrong?
result
Procedural style only: A mysqli_result object obtained with mysqli_query(), mysqli_store_result() or mysqli_use_result() or mysqli_stmt_get_result().
PDOStatement::fetchAll — Returns an array containing all rows in the result set
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question