Use ew_ExecuteRow

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
Almeida 3A
User
Posts: 85

Use ew_ExecuteRow

Post by Almeida 3A »

how to bring the result with:

$sql_item = ew_ExecuteRow("SELECT
con_rel_saldo_item_nat.AnoNome,
con_rel_saldo_item_nat.NomeItemProgramacao
FROM
con_rel_saldo_item_nat
GROUP BY
con_rel_saldo_item_nat.AnoNome,
con_rel_saldo_item_nat.NomeItemProgramacao
HAVING
con_rel_saldo_item_nat.AnoNome = '2017'");

while or foreach ?

how do I do?


ghasembaghi
User
Posts: 293

Post by ghasembaghi »

you can ew_ExecuteRow use only for one record.
for more than one record you should below code:
(Note: Please replace YOUR QUERY and FIELDNAME)

<?php
$query = "YOUR QUERY";
$result = $GLOBALS["conn"]->Execute($query);
if($result){
while(!$result->EOF){
echo $result->fields('FIELDNAME');
$result->MoveNext();
}
$result->Close();
}
?>


Almeida 3A
User
Posts: 85

Post by Almeida 3A »

$ row = ew_ExecuteRow ("SELECT * FROM MyTable WHERE ...");

I thought that it gave to several results because it has the (*) ...


kirondedshem
User
Posts: 642

Post by kirondedshem »

If you read help "Some Global Functions" you will see that
ew_ExecuteRow:Executes the query, and returns the first row as an array.so irespective of how many it gets it always returns the first one
ew_ExecuteRows:Executes the query, and returns the rows as an array.

So if you want to loop through the result set you have to use ew_ExecuteRows or you can even use ew_Execute like below example

$TheQuery = "select * from my_table ";
$all_result = ew_Execute($TheQuery) or die("error during: ".$TheQuery);
$all_rows = $all_result->GetRows();
foreach ($all_rows as $a_row )
{
//get values from a given row using column name
$age = $a_row["age"];
}


mobhar
User
Posts: 11709

Post by mobhar »

Almeida 3A wrote:
I thought that it gave to several results because it has the (*) ...

It depends on how you mean by "several results". If you meant "several results" is to get values from all fields (SELECT *) in the first row returned, then using ew_ExecuteRow is enough.

For example, in your "MyTable" table contains 3 fields (FieldOne, FieldTwo, FieldThree), then you may simply use the following code to get the values from those fields respectively:

echo $row["FieldOne"];
echo $row["FieldTwo"];
echo $row["FieldThree"];


Almeida 3A
User
Posts: 85

Post by Almeida 3A »

Got it.

Thank you


Post Reply