Php Laravel中的简单MySQL选择查询问题
这是我的Laravel查询下拉列表 其中,我获取Php Laravel中的简单MySQL选择查询问题,php,mysql,laravel,laravel-4,Php,Mysql,Laravel,Laravel 4,这是我的Laravel查询下拉列表 其中,我获取$CountryID,并从在选择框中显示的区域表中选择区域名称 但是我不知道如何在这里使用where条件 我犯了什么错误 $CountryID = Input::get('CountryID'); $roles = DB::table('region')->lists('regionname'); foreach ($roles as $value) { echo "<option value=".$value.">".$val
$CountryID
,并从在选择框中显示的区域表中选择区域名称
但是我不知道如何在这里使用where
条件
我犯了什么错误
$CountryID = Input::get('CountryID');
$roles = DB::table('region')->lists('regionname');
foreach ($roles as $value)
{
echo "<option value=".$value.">".$value."</option>";
}
echo "</select>";
}
要执行本机查询,请执行以下操作:
$roles = DB::table('region')->lists('regionname');
注:
现在我得到了region表中的所有字段,您所要做的就是添加一个where子句
$CountryID = Input::get('CountryID');
$roles = DB::table('region')->where('countryId', $CountryID)->lists('regionname');
foreach ($roles as $value)
{
echo "<option value=".$value.">".$value."</option>";
}
echo "</select>";
}
$CountryID=Input::get('CountryID');
$roles=DB::table('region')->其中('countryId',$countryId)->列表('regionname');
foreach($value形式的角色)
{
回显“$value.”;
}
回声“;
}
我会将您的查询更改为:
$results = DB::table('region')->select('regionname', 'regionid')
->where('countryId', $CountryID)
->get();
这将返回一个stdClass对象数组,您可以从中访问属性:
foreach($results as $result)
{
echo $result->regionid;
}
它表示“数组到字符串的转换”,您的查询相当于从countryid=$countryid的区域中选择regionname,对吗?如果我需要->列表('regionname','regionid');如何在哪一行上打印foreach“数组到字符串转换”中的“regionid”?您的$CountryID看起来是一个数组,或者$value是一个数组。
foreach($results as $result)
{
echo $result->regionid;
}