如何从DB中获取阵列并在Laravel的桌子中显示
嘿,我正在研究一个项目,并且我想在一个数组中保存了一些数据,我想在下表中显示这些数据。
[{“ Medicine”:[“ Azax 500片剂”,“ Benadryl糖浆”,“ Bro-Zedex糖浆”],“剂量”:[“ 1丸”,“ 1丸”,“ 1丸”,“ 1丸B”,“计时”:[“每天两次”,“每天两次A”,“每天两次”,“ b”],“持续时间”:[“ 1周”,“ 1周A”,“ 1周B”]}]
I尝试获取数据,但我得到的结果并不理想。 听到我的控制器代码
$PrescId = $Request->id;
$PrescDetails = DB::table('prescriptionunrege')->where('id',$PrescId)->first();
$Prescription = DB::table('prescriptionunrege')->where('id',$PrescId)->get();
return view('test',compact('PrescDetails','Prescription'));
听到的是我的刀片文件代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div>Name: {{ $PrescDetails->Name }}</div>
<div>Contact: {{ $PrescDetails->Contact }}</div>
<div>Gender: {{ $PrescDetails->Gender }}</div>
<div>Age: {{ $PrescDetails->Age }}</div>
<div>Diagnosis: {{ $PrescDetails->Diagnosis }}</div>
<div>{{ $PrescDetails->Prescription }}</div>
<div style="margin-top: 55px">
<table>
<tr>
<th>Medicine</th>
<th>Dosage</th>
<th>Timing</th>
<th>Duration</th>
</tr>
@foreach ($Prescription as $item)
<tr>
<td>{{ $item->Prescription[0] }}</td>
</tr>
@endforeach
</table>
</div>
</body>
</html>
听到我的输出是我的输出
任何帮助都非常感谢。谢谢
Hey there i am working on a project and i have saved some data in an array which i would like to show in a table below is the array.
[{"medicine":["Azax 500 Tablet","Benadryl Syrup","Bro-Zedex Syrup"],"dosage":["1 pill","1 pill A","1 pill B"],"timing":["Twice a day","Twice a day A","Twice a day B"],"duration":["1 week","1 week A","1 week B"]}]
I tried getting the data but the result i got was not ideal.
Hear is my controller code
$PrescId = $Request->id;
$PrescDetails = DB::table('prescriptionunrege')->where('id',$PrescId)->first();
$Prescription = DB::table('prescriptionunrege')->where('id',$PrescId)->get();
return view('test',compact('PrescDetails','Prescription'));
hear is my blade file code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div>Name: {{ $PrescDetails->Name }}</div>
<div>Contact: {{ $PrescDetails->Contact }}</div>
<div>Gender: {{ $PrescDetails->Gender }}</div>
<div>Age: {{ $PrescDetails->Age }}</div>
<div>Diagnosis: {{ $PrescDetails->Diagnosis }}</div>
<div>{{ $PrescDetails->Prescription }}</div>
<div style="margin-top: 55px">
<table>
<tr>
<th>Medicine</th>
<th>Dosage</th>
<th>Timing</th>
<th>Duration</th>
</tr>
@foreach ($Prescription as $item)
<tr>
<td>{{ $item->Prescription[0] }}</td>
</tr>
@endforeach
</table>
</div>
</body>
</html>
Hear is my output
https://drive.google.com/file/d/1iBaE4HqbLBnj1cH56uDlUqL3UYoVfED8/view?usp=sharing
any help is really appreciated. Thankyou
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在迭代处方项目,并显示它们的第一个索引,
如果您的结果是您想要的,并且仅显示不良表现不好,则必须使用
剂量,时机,持续时间
或您的结果仅显示
Medicine
项目,而不是更多,则必须在其他部分中显示相同的索引(
剂量,计时,时间,持续时间
)因为我不知道您的确切问题,也是一个结果示例,我无法修改代码...
的回答,在注释中显示结果后,请使用此块代码:
完全不清楚问题
You are iterating for prescription items, and showing first index of them,
if your result is expected as you want and just table is showing bad, you must use a
<td>
for each ofdosage, timing, duration
or if your result show only
medicine
items and not more,you must show same index in other sections (
dosage, timing, duration
)because i don't know your exact problem, and a result example, i can't modify code...
show response of
not clear question at all, after showing result in comments, use this block code :