jeudi 23 juin 2016

Adding a variable to another variable in php [on hold]

In my database I have a row with multiple columns for an item. It is listed as item1, item2, item3, etc.

I want to create a form using a loop so I do not have to create inputs for all items.

$i=0
while ($i < 20){
 echo $item$i;
 $i++;
}

Obviously this does not work but that is the general idea.

Thanks.

EDIT: To be more clear I would really like to echo all of the "item" columns from my database query.

I am using laravel. I have a row that has 20 item columns, item1, item2, item3, item4 and so on.

I want to echo all of the item columns in a loop instead of having to type each one out.

Here is my code.

 $query = DB::table('item_table')->where('item_id', '1')->first();
 $i     = 1;
 if ($query->item1 == 'Y'){
     echo $query->item1;
 }
 if ($query->item2 == 'Y'){
     echo $query->item2;
 }

Is there an easier way to do this?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/28PmNH7
via IFTTT

Aucun commentaire:

Enregistrer un commentaire