<?php
$hostname='localhost';
$user='root';
$password='';
$connect=mysqli_connect($hostname,$user,$password,'a_railway');
if(!$connect)
{
die('Could not connect');
}
$rs="central";
$rd="central";
$s="A";
$d="B";
$dist=call_dist($rs,$rd,$s,$d,$connect);
echo $dist;
function call_dist($rs,$rd,$s,$d,$connect)
{
$src_dist="SELECT Distance FROM $rs WHERE Station=$s ";
$dest_dist="SELECT Distance FROM $rs WHERE Station=$d ";
$src_dist=mysqli_query($connect,$src_dist);
$dest_dist=mysqli_query($connect,$dest_dist);
$dist=abs($src_dist-$dest_dist);
return $dist;
}
?>
为什么我的 Sql 查询不起作用?数据库没有问题。但查询不执行。我想在这个程序中找到距离,这是通过在点 A 和 B 处减去值来找到的。