1

I need some help with my SQL queries from php.

Here is my PHP code:

$sql = "SELECT * FROM datab WHERE  (`datestamp` BETWEEN '$date' AND '$date') AND (`timestamp` BETWEEN '08:00:01' AND '20:00:00')";
$result = $conn->query($sql);
while($list = mysqli_fetch_array($result))
 {
 //echo "$list[0]</br>";
 echo "$list[1]</br>";  //this is the column from MySQL corresponding to temperatures
 //echo "$list[2]</br>"; //this is the column from MySQL corresponding to other entries (humidity)
 //echo "$list[3]</br>";
 // echo "$list[4]</br>";
 // echo "$list[5]</br>";
 //echo "$list[6]</br>";
 // echo "$list[7]</br>";
}

So, I need to access my each temperature like an array or a list element and I don't know how to do it. I think the solution is to add each $list[1] element into another array inside that while.

Basicaly I want to access the element like temp[2] (or smth like that) to be the second element from the printed $list[1].

Can anyone help me?

1

1 Answer 1

1

Create another array for temperature:

$temperature = array();
while($list = mysqli_fetch_array($result))
{
 $temperature[] = $list[1]; // so now you will be able to acess the temperature array from anywhere outside this loop
}
Sign up to request clarification or add additional context in comments.

1 Comment

many thanks! it works great. This is what I need it. sorry that I'm dumb with php but I have a project which needs to be done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.