Malik Malik - 6 months ago 12
PHP Question

php pick data from web and show it in div

i have a div and also on same page i have some data which is show on web page i just want data show on div how can i do this? i am very very new in php .thanks here is the php file.

<?php
define('HOST','xxxxxxxxxxx');
define('USER','xxxxxxxxxxxxx');
define('PASS','xxxxxxxx');
define('DB','androidapi2');

$con = mysqli_connect(HOST,USER,PASS,DB);

$sql = "select * from users WHERE status = 1";

$res = mysqli_query($con,$sql);
$result = array();

while($row = mysqli_fetch_array($res)){
array_push($result,
array(
// 'id'=>$row[0],
'email'=>$row[3],
));
}
echo json_encode(array("result"=>$result));
mysqli_close($con);

?>

<html>
<head>

<title>DIC ChatBox Beta 1</title>
<style>
#usersOnLine {
font-family:tahoma;
font-size:12px;
color:black;
border: 3px teal solid;
height: 525px;
width: 250px;
float: right;
overflow-y:scroll;
}

.container{
width:970px;
height:auto;
margin:0 auto;
}
</style>
</head>
<body>
<div class="container">
</div>
<h2> all contacts</h2>
<div id="usersOnLine">
</div>
</div>
</body>
</html>


here is the div id usersonline where i want all data show . how to made it.

Answer

There is no need to use json_encode(array("result"=>$result));, directly use $result

<div id="usersOnLine">
<?php
foreach($result as $key => $val)
{
    echo $val['email'];
    echo "<br>";
}
 ?>
</div>