Incrementing a value

Is there a possibility to let a user increase a value by clicking a radio button or something similar?I want to make a voting form for a Top-10 on my Internet radio, and I have a MySQL database with 3 fields: Song (VARCHAR), Artist (VARCHAR) and Votes (INT).What I would like is for the users to look for their song, then click somewhere to vote for that song, thus incrementing the “Vote” value.Then the songs should be sorted according to the number of votes.Is there any way to do this, and more importantly, how can it be done?I have been told to use AJAX, but unfortunately I do not have a clue how to do that.Any help will be much appreciated.Thank you.

You of course can add onclick event to the radio button and use Ajax to update the record as you said, but that may cause wrong votes as the user may easily change from one song to another by clicking the radio buttons.A suggested way may be:

  • use ListOptions_Load/Rendered server event (see Server Events and Client Scripts in the help file) to add a column and add a button for each row
  • the button should have onclick event to ask the user to confirm the vote, if yes, post back the song name to the same page by $.post() (see http://api.jquery.com/jQuery.post/)
  • use Page_Load server event to check $_POST and if data exists, execute an UPDATE statement, e.g.
    if (isset($_POST[“Song”])) ew_Execute(“UPDATE YourTable SET Votes = Votes + 1 WHERE Song = '” . ew_AdjustSql($_POST[“Song”]) . “'”);

Thank you for your good advice.I shall try this solution, and it is great to know that, although this is not a support forum, people are willing to help, unlike other places.I have got a bit further, but I cannot find how to create a radio button.My fields are called (My table is not in English) “Nummer” (Number), “Lied” (Song), “Artiest” (Artist) and “Stemmen” (Votes).
The first one is of the type INT, auto-increment, and the Primary field, The two following are of the type VARCHAR and the last one INT again, in the last one, all rows have the value 0 (no votes).The column where the radio button is to appear is in place and is called “Stem”, but there is of course nothing there yet.I want people to be able to vote for one song, first they search the list (search function I managed to set up working fine), and wheb they have the song they were looking for they click the radio button, which then increments the number of votes by one.Any further advice possible, please?Thank you.

use ListOptions_Load/Rendered server event (see Server Events and Client Scripts in the help file) to add a column and add a button for each rowWe meant push button, but if you still prefer a radio button, you can still use above server events to add your column and your tag. The suggested approach remains the same.

This code did it for setting the column:// ListOptions Load event
function ListOptions_Load() {
$item = &$this->ListOptions->Add(“new”);
$item->Header = “Stem”; // Set the column header (for List page)
$item->OnLeft = FALSE; // Link on left
$item->MoveTo(3);//Move the column to the specified index
}

But I cannot find the code anywhere to add a button to all records in the column “Stem”.Thank you.

Simply put the following code inside “ListOptions_Rendered” server event:$opt1 = $this->ListOptions->Items[“new”];
$opt1->Body = “Your button syntax goes here …”;

Thank you,Now the word for the button caption appears, which is because I do not have a clue what syntax to enter.However, I think I am not that far off from the final solution.Here is what I have so far:List Page
Page_Load:// Page Load event
function Page_Load() {
if (isset($POST[“Lied”])) ew_Execute(“UPDATE Stemming SET Stemmen = Stemmen + 1 WHERE Lied = '” . ew_AdjustSql($POST[“Lied”]) . “'”);
//echo “Page Load”;
}

ListOptions_Load:// ListOptions Load event
function ListOptions_Load() {
$item = &$this->ListOptions->Add(“new”);
$item->Header = “Stem”; // Set the column header (for List page)
$item->OnLeft = FALSE; // Link on left
$item->MoveTo(3);//Move the column to the specified index
}
ListOptions_Rendered:// ListOptions Rendered event
function ListOptions_Rendered() {
$opt1 = $this->ListOptions->Items[“new”];
$opt1->Body = “Stem”;
// Example:
//$this->ListOptions->Items[“new”]->Body = “xxx”;
}

I am obviously still missing something, and I do apologise for my stupid and ignorant questions, but this is all so new and confusing to me.
However, PHPMaker has done a lot for me in the few days I have used it, and I intend to practice with it with gradually more difficult exercises.Everybody’s help is very much appreciated.Thank you.

Another step further, as this code:// ListOptions Rendered event
function ListOptions_Rendered() {
$this->ListOptions->Items[“new”]->Body = “<button type="button">Stem”;
;
// Example:
//$this->ListOptions->Items[“new”]->Body = “xxx”;
//$this->ListOptions->Items[“new”]->Body = “<button type="button">xxx”;
}

created the button for me.I was wondering whether to add the $POST action as described earlier now to finalise the action (ie. increment the vote by 1 when clocked).Thank you all so much.

You may refer to the code in the generated *list.php page for onclick event. Simply search for “onclick” phrase in that file, then you will find some of the usage of it.

Alternatively, you may also consider to Google for “javascript onclick event” as there are so many examples of usage of onclick event out there.

What would be the v2022 way of doing the below in the page_load server event?

function Page_Load() {
if (isset($POST["xyz"])) ew_Execute("UPDATE Table1 SET abc = abc + 1 WHERE id = '" . ew_AdjustSql($POST["xyz"]) . "'");
}

I have tried

if (isset($_POST["xyz"])) ExecuteStatement("UPDATE Table1 SET abc = abc + 1 WHERE = '" . AdjustSql($_POST["xyz"]) . "'");
}

but the update does not run, I think the if (isset($_POST[“xyz”])) part does not work in v2022?
Many thanks

acuervo wrote:

if (isset($_POST[“xyz”])) ExecuteStatement(“UPDATE Table1 SET abc = abc + 1 WHERE = '” . AdjustSql($_POST[“xyz”]) . “'”);

You have a wrong WHERE clause.