How to execute a select query and get all the result

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
rebiscoco
User
Posts: 9

How to execute a select query and get all the result

Post by rebiscoco »

What i need to do is that i need to get all the result of the query.

for example:

i need to execute "SELECT * FROM Table1" and get all the result and put it inside an array.
I undestand that i can use ew_ExecuteRow( "SELECT * FROM Table1") but this only returns the first row.
I need to get ALL the results.

Is there a way to do this? or is there a method that executes the query and returns all the result of the query?
Thanks a lot! :)


digitalphotoworld
User
Posts: 416
Location: Nürnberg/Germany

Post by digitalphotoworld »

Just use ew_LoadRecordSet:

$sql = "SELECT * FROM table";
$rs = ew_LoadRecordset($sql);
$rows = $rs->GetRows();

Now you have an array $rows with all the records.


cidmoro
User
Posts: 1

Post by cidmoro »

could you explain a bit more, how can i see the records of the recordset?


mobhar
User
Posts: 11736

Post by mobhar »

try this:

$sql = "SELECT YourField FROM YourTable";
$rs = ew_Execute($sql);
if ($rs->RecordCount() > 0) {
$rs->MoveFirst();
$sData = "";
while ($rs && !$rs->EOF) {
$field_one = $rs->fields[0]; // get the value of first field
$sData .= $field_one . ",";
$rs->MoveNext();
}
echo $sData;
$rs->Close();
} else {
$this->setFailureMessage("No records are found.");
}


wungaz
User
Posts: 214

Post by wungaz »

$sql = "SELECT YourField FROM YourTable";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
echo $['field_ID'];
}


Post Reply