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

时间:2022-09-25 15:56:01

This my PHP URL for fetching the data from MySQL. I need to make mysqli_fetch_array code saying if filled uid in the app-data table is the same with uid in users table fetch the data from all row in app-data to the uid like every user show his items from app-data table.

这是我用于从MySQL获取数据的PHP URL。我需要制作mysqli_fetch_array代码,说明如果在app-data表中填充的uid与用户表中的uid相同,则将app-data中所有行的数据提取到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 个解决方案

#1


0  

I think this is the correct answer:

我认为这是正确的答案:

<?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);

Little tip for the future:

未来的小小提示:

Don't search exactly what you want, only search in parts.

不要完全搜索你想要的东西,只搜索部分。

#1


0  

I think this is the correct answer:

我认为这是正确的答案:

<?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);

Little tip for the future:

未来的小小提示:

Don't search exactly what you want, only search in parts.

不要完全搜索你想要的东西,只搜索部分。