php - 以正确的格式从数据库获取数据到单选按钮

标签 php mysql laravel

美好的一天。

这是我想要输出到我的 Blade 页面的插图。

1. What was your dining experience?

Dine-in

Carry out

Delivery

2. How did you order?

Hotline

Online/Website

In-person

但是我不知道应该在哪里调整,在我的php中还是在我的Mysql

在我的 Controller 中:

 public function getsurveyquestion()
{

  $questionstitle = DB::select('SELECT q_type,q_title FROM survey_question');

  $questions = DB::select('SELECT q_type,q_title,qcategory_question as category FROM survey_question as sq LEFT JOIN 
  (SELECT id,qid,qcategory_question FROM survey_category_question) scq ON sq.id = scq.qid');

  return view('/survey')
  ->with('question',$questions)
  ->with('questiontitle',$questionstitle);
}

在我的 Blade 页面中:

@foreach($questiontitle as $questions)

  <b style="font-weight:300;"">{{$questions->q_title}}<br><br></b>

  @foreach($question as $test)
    {{$test->category}}<br><br>

  @endforeach

@endforeach

这是我对 Blade 页面的输出,这是错误的。 enter image description here 我的查询输出: myqueryoutput

最佳答案

在您的 Blade 页面中修改:

@foreach($questiontitle as $questions)
  <b style="font-weight:300;"">{{$questions->q_title}}<br><br></b>
    @foreach($question as $test)
       @if($questions->q_title == $test->q_title) {{-- add condition here --}}
          {{$test->category}}<br><br>
       @endif
    @endforeach
@endforeach

关于php - 以正确的格式从数据库获取数据到单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50827759/

相关文章:

php - 如何通过单个查询从带有 where 过滤器的 30k MySQL 表中快速选择 3 条随机记录?

MySQL:如何根据位置获取记录

mysql - 无法加载身份验证插件 'caching_sha2_password'

Laravel 锁定数据库上的表直到更新完成

php - 语法错误或访问冲突 : 1064 You have an error in your SQL syntax in alter table

php - mysql查询隐藏被阻止的用户所有帖子

PHP Mysql 从函数插入语句

php代码使用INNER JOIN语句计算一个数字在一行中出现的次数

php - 使用 AWS 弹性 Beanstalk 的 FTP

javascript - 接受错误后重新加载页面