hi guys its my first day with php. i guess this is an easy one for you. can someone help me to display each element of my array $result[] as a string in $result_device[]?
<?php
$mysqli = new mysqli("localhost", "root", "password", "db");
$sql = "SELECT erker, brunnen, stehlampe, computer, mediacenter FROM
devices";
if (!$result = $mysqli->query($sql)) {
echo "Query: " . $sql . "\n";
echo "Errno: " . $mysqli->errno . "\n";
echo "Error: " . $mysqli->error . "\n";
exit;
}
$result = $result->fetch_row();
$i = 0;
foreach ($result as list ($result_device)) {
if ($result_device[i]==0){
$result_device[i] = "ausgeschaltet";
}
elseif ($result_device[i]==1){
$result_device[i] = "eingeschaltet";
}
$i++;
}
echo $result_device[0];
echo $result_device[1];
echo $result_device[2];
echo $result_device[3];
echo $result_device[4];
$result->close();
$mysqli->close();
?>
thank you very much!
$result = $result->fetch_row();Do you really want to over-write the object?iis not going to use the declared$ivalue. In fact, you don't need to use a counter ($i) if you are just generating an indexed array. You can push values into your result array, by using$result_device[]='whatever';What coding tutorials did you read to arrive at this code?s okay for me to overwrite $result, then i dont need another variable i guess or?