Love Fuel?
Donate
About
Forums
Discussions
Login
FuelPHP Forums
Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
General
Foreach in function DB class
yurifc4
April 2015
Opa tranquilo?
I have
an appointment and
need
of the fields
the result
return
me "
modified"
.
In this case
, the field
"descricao
"
return
only
10 characters
,
using the
truncate
func
.
However,
does not show
me any
error
,
only it's
not working
too ...
suggestions
?
https://gist.github.com/YuriFontella/e6afae3caf1cfe7e87d5
Harro
April 2015
You are changing the loop variable of the foreach, which is always a copy, unless you use the & (by reference).
If you do that, you will get an exception, since database results are read-only and can not be modified.
Instead, I would have your RDBMS handle this using something like this:
$query = DB::select('*')
->select(array(DB::expr('LEFT(`descricao`,10)'), 'descricao'))
->from('publics')
->limit(4)
->execute();
It saves you having to loop over the result. If you want the loop, do this:
public static function publics_slide()
{
$query = DB::select()
->from('publics')
->limit(4)
->execute();
$result = array();
if ($query)
{
foreach($query as $row)
{
$row['descricao'] = Str::truncate($row['descricao'], 10);
$result[] = $row;
}
}
return $result;
}
yurifc4
April 2015
Mas que barbaridade!
Harro Verton
,
thank you very much,
was
all day
puzzling over
it
the two modes
have worked
.
Thanks again
for the explanation
,
solved
:
D
Add a Comment
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Apply for Membership
Categories
All Discussions
5,089
General
↳ General
3,364
↳ Job Board
13
↳ Installation & Setup
214
Packages
↳ Oil
213
↳ Orm
700
↳ Auth
261
Development
↳ Tips and Tutorials
126
↳ Code share
145
↳ Applications
52
In this Discussion
Harro
April 2015
yurifc4
April 2015