This topic is locked

Saving records in new table

2/24/2007 10:26:51 PM
PHPRunner General questions
D
darkmage0 author

Hey im having some issues with trying to save the records on my list page after I do a simple search into another table. I have tried to use the Onload but I don't know what values I should put in the value section in an insert statement. These are the values im trying to save

{$row.1Unit_1_Date_value}, {$row.1Unit_1_Startup_Totalizer_value},

{$row.1Unit_1_Shutdown_Totalizer_value}, {$row.1Totalizer_Total_value}
this is the insert statement I tried too use
$sql="INSERT INTO `unit_1 out day to day flow total` (`Unit_1_Out Date`, `Unit_1_Out Startup Totalizer`, `Unit_1_Out Shutdown Totalizer`, `Unit_1_Out Totalizer Total`)

VALUES ('$date', '$startup', '$shutdown', '$total')";
any help would be great THX Travis

J
Jane 2/26/2007

Travis,
you can do it using ListOnLoad event.

Here is a sample:

function ListOnLoad()

{

global $conn,$strSQL;

if (strpos($strSQL,"where"))

{

$rs = db_query($strSQL,$conn);

while ($data = db_fetch_array($rs))

{

$sql="INSERT INTO `unit_1 out day to day flow total` (`Unit_1_Out Date`, `Unit_1_Out Startup Totalizer`, `Unit_1_Out Shutdown Totalizer`, `Unit_1_Out Totalizer Total`) VALUES ('".$data["date"]."', '".$data["startup"]."', '".$data["shutdown"]."', '".$data["total"]."')";

db_exec($sql,$conn);

}

}

}

D
darkmage0 author 2/28/2007

Hey
Thank you so much Jane that worked great for a few of my pages. Two of the pages however will still not load the old data to the new table's, I think it has something to do with that I am using a multi-table query since it worked fine for the pages which only query one table. Here is the SQL for one of the pages that is not working the other page is the same thing but with turb instead of ph in the name but otherwise same layout.
[codebox]SELECT

`unit_1 ph out`.`Unit_1_Out pH Date` AS `Date`,

Max(`unit_1 ph out`.`Unit_1_Out pH`) AS `Max`,

Min(`unit_1 ph out`.`Unit_1_Out pH`) AS `Min`

FROM

`unit_1 ph out` ,

`unit_1 system log`

WHERE

`unit_1 ph out`.`Unit_1_Out pH` BETWEEN '6.5' AND '8.5' AND

`unit_1 ph out`.`Unit_1_Out pH Date` BETWEEN `unit_1 system log`.`Unit_1 Startup Time` AND `unit_1 system log`.`Unit_1 Shutdown Time`

GROUP BY

DayOfMonth(`unit_1 ph out`.`Unit_1_Out pH Date`)[/codebox]
Here is the listOnLoad I tried to use
[codebox]function ListOnLoad()

{

global $conn,$strSQL;

if (strpos($strSQL,"where"))

{

$rs = db_query($strSQL,$conn);

while ($data = db_fetch_array($rs))

{

$sql="INSERT INTO `unit_1 out day to month ph report` (`Unit_1_Out pH Date`, `Unit_1_Out pH Max`, `Unit_1_Out pH Min`) VALUES ('".$data["Date"]."', '".$data["Max"]."', '".$data["Min"]."')";

db_exec($sql,$conn);

}

}

}[/codebox]
But when I go and check the tables to see if the old data has been saved the table is empty any idea's THX Travis

Alexey admin 2/28/2007

Hi,
the code looks correct.

Make sure you didn't remove "ListOnLoad" yellow box from the List page in Visual Editor.

If it's not there insert this code to any place in the List page:

{doevent name="ListOnLoad"}


If this doesn't help try to debug the code.

Put some echo statements there to see what does the code do.

D
darkmage0 author 2/28/2007

Hey I got it working just removed "if (strpos($strSQL,"where"))" from
function ListOnLoad()

{

global $conn,$strSQL;

if (strpos($strSQL,"where"))

{

$rs = db_query($strSQL,$conn);

while ($data = db_fetch_array($rs))

{

$sql="INSERT INTO `unit_1 out day to day flow total` (`Unit_1_Out Date`, `Unit_1_Out Startup Totalizer`, `Unit_1_Out Shutdown Totalizer`, `Unit_1_Out Totalizer Total`) VALUES ('".$data["date"]."', '".$data["startup"]."', '".$data["shutdown"]."', '".$data["total"]."')";

db_exec($sql,$conn);

}

}

}

and every thing went fine thanks guys

Travis