This topic is locked

Question about adding custom code

1/11/2006 5:58:12 AM
PHPRunner General questions
OCTheEagle author

Hi,
I've got a question about adding a custom table event on loading a list page.
When the page loads, a certain delete and insert query should be run before it shows you the page. The code is as follows:

<?php

//Connect met database

$dbcnx = @mysql_connect('localhost', 'blabla', 'blabla');

if (!$dbcnx) {

exit('<p>Kan niet connecten met de server.</p>');

}
//Connect met grappen database

if (!@mysql_select_db('prototype')) {

exit('<p>Kan prototype database niet vinden</p>');

}

?>
<?php

//remove contents

$sqldelete = @mysql_query("DELETE FROM totaalbeschikbaar");
//Select query

$sql = @mysql_query("SELECT init, year(datum) as jaar, week(datum) as week, sum(Contract+Overwerk-Nietbeschikbaar) AS totaal FROM Personeelsvoorraad GROUP BY init, jaar, week");
while ($result = mysql_fetch_array($sql)){

$init = htmlspecialchars($result['init']);

$jaar = htmlspecialchars($result['jaar']);

$week = htmlspecialchars($result['week']);

$totaal = htmlspecialchars($result['totaal']);
$sql2 = "INSERT IGNORE INTO Totaalbeschikbaar SET

Init = '$init',

Jaar = '$jaar',

Week = '$week',

Totaal = '$totaal'";
@mysql_query($sql2);

}


I'm wondering if this is possible with the 'adding custom code' option, if yes, should I take special things in notice?.
Btw: It is possible to perform this script by placing alle the code in a file called 'total.php' and place it in the include directory. After that you have to edit '_list.php' file and add the following code in it:

'include("include/total.php"); ' just before 'CheckFileTime();' With my question I just want to know if you can also use the 'add custom code' option here.

Sergey Kornilov admin 1/11/2006

You can do this adding your code to ListPageOnLoad Event.
Just make sure you remove <?php and ?> from your code.

OCTheEagle author 1/12/2006

You can do this adding your code to ListPageOnLoad Event.

Just make sure you remove <?php and ?> from your code.


Sadly, that doesn´t seem to work. My code looks like this now:

function ListOnLoad($strSQL)

{

//********** Custom code ************

// put your custom code here
//Connect met database

$dbcnx = @mysql_connect('localhost', 'blabla', 'blabla');

if (!$dbcnx) {

exit('<p>Kan niet connecten met de server.</p>');

}
//Connect met grappen database

if (!@mysql_select_db('prototype')) {

exit('<p>Kan prototype database niet vinden</p>');

}
echo "<p>Connectie gelukt</p>";
// Haal eerst alles weg

$sqldelete = @mysql_query("DELETE FROM totaalbeschikbaar");
echo "<p>Delete gelukt</p>";
//Select query

$sql = @mysql_query("SELECT init, year(datum) as jaar, week(datum) as week, sum(Contract+Overwerk-Nietbeschikbaar) AS totaal FROM Personeelsvoorraad GROUP BY init, jaar, week");

if (!$sql) {

exit ('<p>Query mislukt</p>');

}
echo "<p>Query gelukt</p>";
while ($result = mysql_fetch_array($sql)){

$init = htmlspecialchars($result['init']);

$jaar = htmlspecialchars($result['jaar']);

$week = htmlspecialchars($result['week']);

$totaal = htmlspecialchars($result['totaal']);
$sql2 = "INSERT IGNORE INTO Totaalbeschikbaar SET

Init = '$init',

Jaar = '$jaar',

Week = '$week',

Totaal = '$totaal'";
@mysql_query($sql2);
}
}


When I build the pages and acces the program nothing seems to happen when I load the page.

Sergey Kornilov admin 1/12/2006

Hi,
there was a bug in previous PHPRunner 3.0 version that broke events mechanism.
Please download and install the latest update (build 80)