This topic is locked
[SOLVED]

 how to use SQLQuery in find some data in Java Onload event

10/12/2012 6:23:56 AM
PHPRunner General questions
I
igiacchi author

Dear Sirs,

I need to generate a serial number using the data choosed form a lookup wizard, and other data present in a database table.

I made an SQL query to find my field value into a table and get the numeric value (INT) to generate my serial number.

I had obtained the right query but I'm not able to execute it, I don't know where is the error.

This is code written into Javascript OnLoad event:
function createserial()

{
// global $conn; don't run

// $conn = db_connect();

var SN = ctrlFieldphoto.getValue();

var createSN = SN.replace(/.jpg/,"");
$strSQL = "select sellqta from chphotos where filename='" + SN + "'";
//sellqta INT, contain a value that need to be increased using the quantity selled, then I trasforn this value in string to create a serial like this:

//Filename + "
" + selledqty
// No one of following run I reach some error

//$querystr = CustomQuery($strSQL);

//$query = db_query($querystr,$conn);

//$data = db_fetch_array($query);
ctrlFieldSN.setValue($strSQL);
}

ctrlFieldphoto.on('change',createserial);
Many thanks in advance

C
cgphp 10/12/2012

You can't execute PHP code inside the Javascript onload event. That event is only for client side code. You can make an ajax call to your PHP script to fetch the database value.

I
igiacchi author 10/12/2012



You can't execute PHP code inside the Javascript onload event. That event is only for client side code. You can make an ajax call to your PHP script to fetch the database value.


Many thanks in advance for your fast reply Cristian.

Could you give me some examples to do this because I don't have a great experience on this.

I'm tried to search into the forum some examples but I'm not able to understand what find.

PHPRunner 6.2

C
cgphp 10/13/2012

If you want to fetch data from database when the user selects a value from the lookup you can do an AJAX call. You can find more info about jquery AJAX call here: http://api.jquery.com/jQuery.ajax/

I
igiacchi author 10/13/2012



If you want to fetch data from database when the user selects a value from the lookup you can do an AJAX call. You can find more info about jquery AJAX call here: http://api.jquery.com/jQuery.ajax/


Dear Cristian,

I saw a lot of examples in the forum about the AJAX use, but sincerly I have already a lot of difficulties in using the PHPRunner, that when I saw the web pages that you kindly provided me on jQuery, at first I had the wish to shoot myself <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=68103&image=1&table=forumreplies' class='bbc_emoticon' alt=':blink:' />.

I'm not an expert in programming obviously that's why I asked you a simple example.

I also understand that you cannot write for each coming requests an example.

For this reason I spent many hours in searching for possible solutions in the forum, and I found this which I think can be adapted to my problem.
http://www.asprunner.com/forums/topic/19056-in-add-page-i-want-to-use-dropdown-menu-to-display-picture-in-the-same-add-page/
This guy use a query into a list page "Before process" and pass the result in Java OnLoad event (if I well understand).

Sincerly I understand the 10% of all this code but do you think that i can do the same to solve my problem.

I also tried to replicate its operation also creating a database, but I could not make it work.
Just another question, you can not modify the title of the post once created?

Admin 10/15/2012

Ivano,
you are looking for solution from the wrong angle. Since you are looking for a database interaction use BeforeAdd event where you can execute your queries and assign a value to the serial number field.
If you want to perform the same task before page is submitted, right after selection is made from the lookup wizard you do need to use AJAX and the complexity of this task is beyond the beginners level.

I
igiacchi author 10/15/2012



Ivano,
you are looking for solution from the wrong angle. Since you are looking for a database interaction use BeforeAdd event where you can execute your queries and assign a value to the serial number field.
If you want to perform the same task before page is submitted, right after selection is made from the lookup wizard you do need to use AJAX and the complexity of this task is beyond the beginners level.


Hi admin,

yes I need to submit this before and I know that is too complex for a beginners.

I hope to solve this problem using the patience of some guys that can help me on this.

But of course not only me, even more others in my condition for the future, why not?

A small and simple example can be used by everyone in the future and this can only be a benefit for you, this forum and your product.

tnx again admin

Admin 10/16/2012

This task (executing requests via AJAX) is not specific to PHPRunner. You can find a lot examples on the Web for any level of programming knowledge.
http://api.jquery.com/jQuery.ajax/

http://api.jquery.com/jQuery.get/
More or less complete tutorial with both client and server side code:

http://www.sitepoint.com/ajax-jquery/