Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 相应的ID未显示为“1”;精选;导致下拉列表_Php_Html_Select_Echo_Selected - Fatal编程技术网

Php 相应的ID未显示为“1”;精选;导致下拉列表

Php 相应的ID未显示为“1”;精选;导致下拉列表,php,html,select,echo,selected,Php,Html,Select,Echo,Selected,我有一个php页面,它将显示一个表单。在表单中,您需要选择一个驱动程序。驱动程序是从mysql数据库中选择的,这部分工作正常。但是,我希望看到登录的用户自动被选为此表单的默认驱动程序 我错过了什么?非常感谢您的帮助 mysqli_set_charset($connection, 'utf8'); $query = "SELECT name, substring_index(substring_index(mrb_users.user_qualified,'|',-2),'|',1) as d

我有一个php页面,它将显示一个表单。在表单中,您需要选择一个驱动程序。驱动程序是从mysql数据库中选择的,这部分工作正常。但是,我希望看到登录的用户自动被选为此表单的默认驱动程序

我错过了什么?非常感谢您的帮助

mysqli_set_charset($connection, 'utf8');

$query  = "SELECT name, substring_index(substring_index(mrb_users.user_qualified,'|',-2),'|',1) as driver, id  ";
$query .= "from mrb_users having driver like 'B%' ORDER BY name ";
$sql = mysqli_query($connection, $query);

$row = mysqli_num_rows($sql);
while ($row = mysqli_fetch_array($sql)){
echo "<option value='". $row['id'] ."' if('".$row['id']."'==='".$_SESSION['id']."') 'selected'>" .$row['name'] . ' - ' .$row['chauffeur'] ."</option>" ;
}

$conn->close();
mysqli\u set\u字符集($connection,'utf8');
$query=“选择名称、子字符串索引(子字符串索引(mrb_用户。用户符合条件,”、-2)、“|”,1)作为驱动程序,id”;
$query.=“来自mrb_用户,其驱动程序类似于“B%”按名称排序”;
$sql=mysqli\u查询($connection,$query);
$row=mysqli\u num\u行($sql);
while($row=mysqli\u fetch\u数组($sql)){
回显“$row['name'].-.”$row['chauffer'.]”;
}
$conn->close();

如果语句包含在双引号中,因此逐字打印,则看起来像PHP
。如果是这样,您应该能够使用浏览器的HTML检查器查看它

为清楚起见,我建议(1)将
if
语句分解为单独的一行,(2)使用
sprintf()
而不是串联大量字符串:

$sel=($row['id']==$\u会话['id'])
? '选定的
: '';
sprintf(“%s-%s”,
$row['id']、$sel、$row['name']、$row['chauffer']);

如果
语句包含在双引号中,因此逐字打印,则看起来像PHP
。如果是这样,您应该能够使用浏览器的HTML检查器查看它

为清楚起见,我建议(1)将
if
语句分解为单独的一行,(2)使用
sprintf()
而不是串联大量字符串:

$sel=($row['id']==$\u会话['id'])
? '选定的
: '';
sprintf(“%s-%s”,
$row['id']、$sel、$row['name']、$row['chauffer']);

谢谢,这无疑为我指明了正确的方向。在阅读您的答案并查看我的浏览器检查后,我注意到我正在比较两种数据类型。然后我注意到sprintf没有打印出来。我的解决方案如下:
$sel=($row['id']==$\u SESSION['id'])?'选定':'';echo sprintf(“%s-%s”、$row['id']、$sel、$row['name']、$row['chauffer']);)谢谢,这无疑为我指明了正确的方向。在阅读您的答案并查看我的浏览器检查后,我注意到我正在比较两种数据类型。然后我注意到sprintf没有打印出来。我的解决方案如下:
$sel=($row['id']==$\u SESSION['id'])?'选定':'';echo sprintf(“%s-%s”、$row['id']、$sel、$row['name']、$row['chauffer']);)