Hi guys
I have retrieved data from the database using this code:
$floor= Floor::model()->findAll(“id = :x”,(array(’:x’ => $_REQUEST[‘id’])));
$floor->no_of_rooms gets the value of the column no_of_rooms which is an integer
How can I then loop the value of the integer?
Kindly help
patrickm
(Yiiframework)
January 6, 2017, 1:47pm
2
What do you mean with "loop the value of the integer"?
1 Like
$floor= Floor::model()->findAll(“id = :x”,(array(’:x’ => $_REQUEST[‘id’])));
echo $floor->no_of_rooms; gives the value e.g 5
I want to 5 rows each for one room
voshkin
(Voshkinengineer)
January 6, 2017, 4:05pm
4
$floor= Floor::model()->findAll(“id = :x”,(array(’:x’ => $_REQUEST[‘id’])));
echo $floor->no_of_rooms; gives the value e.g 5
I want to 5 rows each for one room
$floors = Floor::model()->findAll("id = :x",(array(':x' => $_REQUEST['id'])));
foreach($floors as $floor) {
echo $floor->no_of_rooms;
}
this code will print each no_of_rooms
I want to have the same number of forms of different model as the no_of_rooms
E.g if echo $floor->no_of_rooms is 3, it should generate 3 forms
selvakumar
(Selvakumar Kaliyappan)
January 7, 2017, 7:20am
6
I guess you need something like this:
$floor = Floor::model()->findOne("id = :x",(array(':x' => $_REQUEST['id'])));
for ($i=0; $i < $floor->no_of_rooms; $i++) {
# your code...
}
giannis
(Giannisdag)
January 7, 2017, 8:37am
7
You also should check the guide. http://www.yiiframework.com/doc-2.0/guide-db-active-record.html#selecting-extra-fields . Here it describes how you can create virtual fields which will be produced after some calculations, I think this case matches your question
I guess you need something like this:
$floor = Floor::model()->findOne("id = :x",(array(':x' => $_REQUEST['id'])));
for ($i=0; $i < $floor->no_of_rooms; $i++) {
# your code...
}
Yes, thats what I need and I have implemented but its crushing the whole code
Thanks a lot. I appreciate your help
Its now working, I appreciate