mercredi 31 octobre 2018

How to convert MySqli Loop Code Laravel controller

I want to work on a while loop in a foreach loop but I can't convert it to Laravel controller system. Please help.

foreach (range('a', 'z') as $i) 
{
echo $i = strtolower($i); 
$sql = "SELECT * FROM `list` Where name like '$i%' Limit 30";
$result = mysqli_query($con, $sql);
echo"<hr>
    <h3>Name Starting with ".strtoupper($i)."</h3>";
while($row=mysqli_fetch_array($result,MYSQLI_ASSOC))
{
    $id = $row['id'];
    $name = $row['name'];
    echo "<li><a href=\"name/".$row['id']."\">".$row['name']."</a></li>";
}
echo "<li><a href=\"name/".$i."\">More</a></li>";
echo"</ul>";
}

The code in Laravel that I have is

foreach (range('a', 'z') as $i) 
    {
        $list = DB::table('list')->where('name', 'LIKE', $i.'%')->limit(30)->get();            
        return view('pages.all', ['list' => $list]);            
    }

This code only Gives data for names starting with alphabet "a" but won't proceeds with the rest of the characters.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Q80i6V
via IFTTT

Aucun commentaire:

Enregistrer un commentaire