0
I wonder if you could help me?
I need to check if array contains a specific value in a mysql query.
In a function I get the day value of the week:
$wekc = 4
In table tb_turg, I own the weekg column that holds the values like this:
idturg weekg
1 1,3,5
2 1,2,4
3 0,4
4 3,6
5 4,6
6 1,2
7 1,4,6
8 0,1,2,3,
9 2,4
10 3,5
Then I created the array like this:
$sqlturg = "SELECT weekg,abng,classg FROM tb_turg WHERE abng != '$nwdatefer' AND classg = '1' ORDER BY idturg ASC";
$querya = $conn->query($sqlturg);
while($rowtg = $querya->fetch_assoc()) {
$weekg = $rowtg["weekg"];
@$nwekga .= $weekg." - ";
}
Then I separated this array:
$nwekg = rtrim($nwekga, ' - ');
$aw = explode(' - ', $nwekg);
foreach($aw as $bw) {
$cw = $bw;
$sqlga = mysqli_query($conn, "SELECT idturg,weekg FROM tb_turg WHERE weekg = '$cw' AND classg = '1' ORDER BY idmodg ASC");
$rowtga = $sqlga->fetch_assoc();
$idturg = $rowtga["idturg"];
$ag = $rowtga["weekg"];
$fw = explode(',', $ag);
foreach($fw as $gw) {
$hw = $gw;
}
if (in_array($wekc, $fw)) {
$sqlgb = mysqli_query($conn, "SELECT idturg,codturg FROM tb_turg WHERE idturg = '$idturg' AND classg = '1'");
$rowtgb = $sqlgb->fetch_assoc();
$idturg = $rowtgb["idturg"];
$codturg = $rowtgb["codturg"];
echo $idturg . "<br>";
} else {
echo "";
}
}
But it is not working because it is repeating results of the $sqlgb query
CONCLUSION: He would have to list the idturg only of the lines that have the day 4 (Thursday), without repeating.
Thank you very much!