[SOLVED] array return only one item instead of two

sc_lookup(estimateFormID, “select EstimateForm.id from EstimateForm, EstimateItem
where EstimateForm.id = EstimateItem.estimate_code
and EstimateItem.price=’$product_price’”);

$estimate_ids = {estimateFormID[0][0]};

sc_alert("$estimate_ids[0]");

array return only one item, should have two items

if I use below script,then error message mysql_fetch_row() expects parameter 1 to be resource, string given

sc_lookup(estimateFormID, “select EstimateForm.id from EstimateForm, EstimateItem
where EstimateForm.id = EstimateItem.estimate_code
and EstimateItem.price=’$product_price’”);

$estimate_ids = {estimateFormID[0][0]};

while ($estimate_id = mysql_fetch_row($estimate_ids)) {
sc_alert("$estimate_ids[0]");
}

Regards,
Franko TSE

sc_lookup return an array. So the first row is in element 0, the next in 1 etc. To find out how many items in the array you need to find the size of the array. The array already contains the full resultset that’s why you can’t use fetch_row.

Hello Albert,

really appreciate your response, but why sc_alert only return one value, should be two id, 2 and 3 but just return 2

sc_lookup(estimateFormID, “select EstimateForm.id from EstimateForm, EstimateItem
where EstimateForm.id = EstimateItem.estimate_code
and EstimateItem.price=’$product_price’”);

$estimate_ids = {estimateFormID[0][0]};

sc_alert("$estimate_ids[0]");

Because

$estimate_ids = {estimateFormID[0][0]};

returns only one element (first field of first row)

Hello Albert,

so how to get all array elements, thank you

It’s a two dimensional array. TO find the number of rows you use sizeof: http://php.net/manual/es/function.sizeof.php
the number of columns you know because that’s the amount of fields in your select list.

array[0][0], first field, first row
array[0][1], second field, first row
array[1][1], second field second row.,

Does that help?

sc_lookup(product_id, “SELECT id FROM EstimateForm”);
$product_id = {product_id[0][0]};

Estimateform contains 2 id, 4,5
print ($product_id); returns 4
print ($product_id[0]); returns 4
print ($product_id[1]); returns nothing

[QUOTE=frankotse;15834]sc_lookup(product_id, “SELECT id FROM EstimateForm”);
$product_id = {product_id[0][0]};

Estimateform contains 2 id, 4,5
print ($product_id); returns 4
print ($product_id[0]); returns 4
print ($product_id[1]); returns nothing[/QUOTE]

Try

{product[0][0]}; like:


$check_sql = "SELECT id FROM EstimateForm";
sc_lookup(rs, $check_sql);

if (isset({rs[0][0]}))     // Row found
{
    {product} = {rs[0][0]};
}

if (isset({rs[1][0]}))     // Row found
{
    {product} = {rs[0][0]};
}

Since you can determine the size of the array, you know how many rows you have. Otherwize I would recommend:


$check_sql = 'SELECT id FROM EstimateForm";

sc_select(rs, $check_sql);
if (false == {rs})     // Error while accessing database
{
    sc_error_message('Error while accessing database.');
}
else
{
   while(!$rs->EOF)
    {
		{yourfield} = $rs->fields[0];
		$rs->MoveNext();
    }
    $rs->Close();
}

I use below script for a AppGini generated app but don’t know how to rewrite in scriptcase

$estimate_ids = sql(“select EstimateForm.id from EstimateForm, EstimateItem where EstimateForm.id = EstimateItem.estimate_code and EstimateItem.price=’$product_id’”);
EstimateItem.estimate_code and EstimateItem.price=’$product_id’");
while ($estimate_id = mysql_fetch_row($estimate_ids)) {
updateEstimateTotals($estimate_id[0]);
}

I used below traditional code to solve it, hope can help others

$id ={id};
mysql_connect(“localhost”, “root”, “password”);
mysql_select_db( “test” );
$query=mysql_query(“select price from Product where id = ‘$id’”);

$query1= mysql_fetch_row($query);
$product_price=$query1[0];
mysql_query(“update EstimateItem
set total=’$product_price’* qty where price=’{id}’”);
//print “$product_price”;

$sql=mysql_query(“select EstimateForm.id from EstimateForm, EstimateItem
where EstimateForm.id = EstimateItem.estimate_code
and EstimateItem.price=’$id’”);
while ($estimate_id = mysql_fetch_row($sql)) {
updateEstimateForm($estimate_id[0]);
//print “$estimate_id[0]”;
}