This topic is locked

Opting in to a table

1/29/2007 10:01:28 AM
PHPRunner General questions
I
ictaylor author

Hi
This is a bit of a strange one:
I have users that register on my site and in doing so obviously enter their details. I want for them to able to log in and upon viewing their details to be able to click on a button or something that will forward their entered data into another table.
I want this to happen because I run weekly competitions on my site and I want users to return to the site and click on this 'button' to enter this weeks competition rather than all users being entered automatically from my users table. Some users may not want to enter certain competitions and I need a way for all my users to have an option to enter some competitions and not others
I hope that makes sense!

J
Jane 1/30/2007

Hi,
you can do it using events.

For example, create View page, proceed to the Visual Editor tab, turn on HTML mode, find this line:

<A href="orders_view.php?{$row.1editlink}">View</A>

and replace it with this one:

<A href="orders_view.php?{$row.1editlink}">Add competitions</A>



Then add ViewOnLoad event. Here is a sample code:

function ViewOnLoad()

{

global $where,$conn,$strTableName;
//add record to the AnotherTable

$strSQLSave = "INSERT INTO AnotherTable (Field1, Field2) SELECT Field1, Field2 FROM ".$strTableName." where ".$where;

db_exec($strSQLSave,$conn);
//redirect to the List page

?>

&lt;script>

window.location='./TableName_list.php';

</script>

<?php

exit();

}

I
ictaylor author 1/30/2007

Hi,

you can do it using events.

For example, create View page, proceed to the Visual Editor tab, turn on HTML mode, find this line:

and replace it with this one:
Then add ViewOnLoad event. Here is a sample code:


Thanks Jane
Where do I go to enter the viewonload event? - is that done on the HTML mode of the visual editor - if so where do I need to insert your code and on which page?
I use mySQL so do I need to swap $strSQLSave = for $strmySQLSave = ?
Also is there any way I can echo the number of people who have entered the competition on my register page - to say something like " If you enter you currently stand a 1 in xxxxx chance of winning" where xxxxx is the number of current entries?

J
Jane 1/30/2007

Hi,
add event code on the Events tab (step 11) in the PHPRunner.

Also you don't need to change $strSQLSave variable.
I'm not sure that I understand you correct.

Where and when do you want to display message?

I
ictaylor author 1/30/2007

Hi,

add event code on the Events tab (step 11) in the PHPRunner.

Also you don't need to change $strSQLSave variable.
I'm not sure that I understand you correct.

Where and when do you want to display message?


When new users go to my 'register page' where they choose their login name and password, I wanted the number of people already registered for the current competition to display underneath.

Sergey Kornilov admin 1/30/2007

You can use RegisterOnLoad event to get current number of registered users and display it on the page.
The following SQL query gets you a number of records in the table:

select count(*) from ...