Following is the code I am testing now for a comparison website.
But I couldn't make it work with the prepared statement function.
My code works well if I didn't use the prepared statement method.
The table structure or use of foreach
might look not the proper method, but it is necessary for some other functions.
<?php
$dbname="ty465yu67u76i7";
$dbpass="jf54tg5y65y66u";
$dbuser="4t5t5y6y65u67u";
$hostname="localhost";
// SETP TWO : connecting to the database
$mysqli = new mysqli($hostname, $dbuser, $dbpass, $dbname);
$pid1="202882";
$userIdArray = [202882,202883,202884];
// number of question marks
$questionMarksCount = count($userIdArray);
// create a array with question marks
$questionMarks = array_fill(0, $questionMarksCount, '?');
// join them with ,
$questionMarks = implode(',', $questionMarks);
// data types for bind param
$dataTypes = str_repeat('i', $questionMarksCount);
// SETP THREE : SQL query
$results = $mysqli->prepare("SELECT * FROM phonespecs WHERE pid IN('.$questionMarks.')");
$results -> bind_param($dataTypes, ...$userIdArray);
$results -> execute();
$results -> store_result();
?>
<div class="basic-information">
<h3>Basic Information </h3>
<table class="table">
<tbody>
<tr>
<td>Models</td>
<?php foreach ($results as $result){ ?>
<td> <strong><?php
if(!empty($result['name'])) {
$mobname=$result['name'];
} else{$mobname="Empty";}
echo $mobname; ?></strong> </td>
<?php } ?>
</tr>
<tr>
<td>Manufacturer</td>
<?php foreach ($results as $result){ ?>
<td> <strong><?php echo $result['brand']; ?></strong> </td>
<?php } ?>
</tr>
--and more table data--