$con=mysqli_connect($localhost,$username,$password,'db');
$query = 'SELECT `SN` FROM `list` WHERE `Floor` LIKE "LP60" AND `type`LIKE "pc"';
$result = mysqli_query($con,$query) or die(mysqli_error());
foreach ($result as $SN)
{
$get = mysqli_query($con,'SELECT * FROM pc WHERE pcSN LIKE '.$SN.'ORDER BY EvenID DESC LIMIT 1')
while ($get_row = mysqli_fetch_assoc($get)) {
echo '<tr>'; // printing table row
echo '<td id="ID">'.$get_row[0].'</td>';
echo '<td>'.$get_row[1].'</td>';
echo '<td>'.$get_row[2].'</td>';
echo '<td>'.$get_row[3].'</td>';
echo '<td>'.$get_row[4].'</td>';
echo '<td>'.$get_row[5].'</td>';
echo '<td>'.$get_row[6].'</td>';
echo '<td>'.$get_row[7].'</td>';
echo '<td>'.$get_row[8].'</td>';
echo '<td>'.$get_row[9].'</td>';
echo '<td>'.$get_row[10].'</td>';
echo '<td>'.$get_row[11].'</td>';
echo '<td>'.$get_row[12].'</td>';
echo '<td>'.$get_row[13].'</td>';
echo '<td>'.$get_row[14].'</td>';
echo'</tr>'; // closing table row
}
}
I have tested both query are working fine, have tested to print_r($SN) as well but at the end i got Array to string conversion error, any help please
I have found the solution by using
'" . mysqli_escape_string($con,$SN) . "'
and now the new code like this
$con=mysqli_connect($localhost,$username,$password,'db');
// mysql select query
$query = 'SELECT `SN` FROM `list` WHERE `Floor` LIKE "LP60" AND `type`LIKE "pc"';
$result = mysqli_query($con,$query) or die(mysqli_error());
while($row = mysqli_fetch_assoc($result))
{
foreach ($row as $SN){
$sql = "SELECT * FROM pc WHERE pcSN LIKE '" . mysqli_escape_string($con,$SN) . "' ORDER BY EvenID DESC LIMIT 1";
$get = mysqli_query($con,$sql);
while ($get_row = mysqli_fetch_assoc($get)) {
echo '<tr>'; // printing table row
echo '<td>'.$get_row['xxx'].'</td>';
.
.
.
.
echo '<td>'.$get_row['yyy'].'</td>';
echo'</tr>'; // closing table row
}
}
}
Thanks everyone has been helping me here, i think add up all little bit to made it worls. Thanks Wish this post can help any other as well