I am having the following php code that is called by the ajax and is shown in the page once the input field on the page is being changed. Everything is working fine but I can not get the variable for the number of rows in the query2.
<?php
$db = new mysqli('localhost', 'name' ,'pass', 'db');
$kw=$_GET['kw'];
$schicht=$_GET['schicht'];
$field_id=$_GET['field_id'];
if(!$db) {
echo 'Could not connect to the database.';
} else {
if(1==1) {
$query1 = $db->query("UPDATE dienstplan SET schicht= '".$schicht."' WHERE field_id='".$field_id."'");
}
if($query1)
{
echo '<div id="managementfields1" class="fieldslist2">';
while ($result = $query1 ->fetch_object()) {
$schichtcheck = $result->schicht;
$query2 = $db->query("SELECT * FROM codes WHERE lcfruh='$schichtcheck' OR lcmittag='$schichtcheck' OR lcmitlcspat='$schichtcheck' OR lcmitshspat='$schichtcheck' OR lcspaet='$schichtcheck' OR shmittag='$schichtcheck' OR shmitshspat='$schichtcheck' OR shmitlcspat='$schichtcheck' OR lcspaet='$schichtcheck' OR lcnacht='$schichtcheck' OR lcteildienst='$schichtcheck' OR shfruh='$schichtcheck' OR shspaet='$schichtcheck' OR shnacht='$schichtcheck' OR shteildienst='$schichtcheck' OR frei='$schichtcheck' OR modkod='$schichtcheck' OR lcshteil='$schichtcheck' OR shlcteil='$schichtcheck");
$rowcount = /// i need here number of rows from the query2;
if($rowcount>0) {
$color="white";
} elseif if($rowcount<1){
$color="red";
}
echo '<p><input name="schicht[]" style="background-color:'.$color.'" type="text" value="'.$result->schicht.'"></p>';
}
echo '</div>;
}
else {
echo '<h1>Error</h1>';
}
}
?>
$rowcount = $query2->num_rows;not work?var_dump($query2);to check that your query is correct?