简体   繁体   中英

file_get_contents drops values from database, if id is variable

$query = "SELECT * FROM data where data.id=".$myrow[0]."";
$result = mysqli_query($mysqli, $query);
$rows = mysqli_fetch_row($result);

$homepage = file_get_contents('my page'); 
echo $homepage;

Page 'my page' contains $rows[1].

If $query="SELECT * FROM data where data.id=1" then $homepage displays $rows[1].

But if $query="SELECT * FROM data where data.id=".$myrow[0]."" then $homepage displays empty instead of $rows[1].

$myrow[0] was received correctly, in this case it is 2. Converting to the int didn't help.

$myrow[0] = 1; // add this line and try
$query = "SELECT * FROM data where data.id=".$myrow[0];
// ...

If it works, check if you have data with the id being 2. If you have data, try

$query = "SELECT * FROM data where data.id=" . intval($myrow[0]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM