android - php通过用户id获取mysql数据

时间:2016-02-05 20:27:50

标签: php android mysql database

这是我用于从MySQL获取数据的PHP URL。我需要制作mysqli_fetch_array代码,说明uid表中的填充app-datauid表中的users相同,以获取app-data中所有行的数据{1}} uid向每个用户展示app-data表中的项目。

$host = "";
$user = "";
$pwd = "";
$db = ""; 

$con = mysqli_connect($host, $user, $pwd, $db);

if(mysqli_connect_errno($con)) {
    die("Failed to connect to MySQL: " . mysqli_connect_error());
} 

$sql = "SELECT * FROM app_data ORDER By id";
$result = mysqli_query($con, $sql);

$rows = array();

while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
    $rows[] = $row; 
}

mysqli_close($con);

echo json_encode($rows);

1 个答案:

答案 0 :(得分:0)

我认为这是正确答案:

<?php

$host = "";
$user = "";
$pwd = "";
$db = ""; 

$con = mysqli_connect($host, $user, $pwd, $db);

if(mysqli_connect_errno($con)) {
    die("Failed to connect to MySQL: " . mysqli_connect_error());
} 

$sql = "SELECT * FROM app_data WHERE u_id=".$_POST['posted_uid']." ORDER By id";
$result = mysqli_query($con, $sql);

$rows = array();

while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
    $rows[] = $row; 
}

mysqli_close($con);

echo json_encode($rows);

未来的小小提示:

请勿完全搜索您想要的内容,只搜索部分内容。