Forum Moderators: coopster

Message Too Old, No Replies

Tables (PHP > JavaScript > SQL )

Alter table and update image without refresh

         

cryoman

5:37 pm on Mar 30, 2006 (gmt 0)



I have encountered this problem, which my lack of knowledge doesn't allow me to solve.

The idea is to have table of one row and three columns, like this:

¦ "image" ¦ [url box to image (http://.../.gif)] ¦ "submit image" ¦

where:

1. In the second column url address to image is input manually by user.
2. By pressing "submit image" (.gif button), data from the second column is altered in SQL table and simultaneously "image" in the first column is reloaded to new value, that was just input in SQL table.

The idea is to reload only "image" in the first column and not the whole page.

I believe that the "image" should be located in iFrame, but not sure. Can anyone give an example of such a magic "submit image" button, that will do all procedure required without reloading the whole page?

scriptmasterdel

10:00 am on Mar 31, 2006 (gmt 0)

10+ Year Member



You really need to be looking into javascript to do this ....

cryoman

9:16 pm on Mar 31, 2006 (gmt 0)



Well thank you!
Unfortunately I know little about JavaScript and it will take some time for me to get used to it.
And... searching the net for the whole day I couldn't find a good example of JavaScript code to do what I need.

I know that onClick doesn't reload page, but can anybody give a JavaScript example, where SQL table is Altered by onClick, to do something like this:

array (<img src='.gif'> onClick=\"UPDATE Person SET FirstName = 'Nina' WHERE LastName = 'Rasmussen'"/);

Please note that this is WRONG!, non-functional example, just to give an idea of what I need.

Please help, if you can. Anybody?

Tastatura

9:55 pm on Mar 31, 2006 (gmt 0)

10+ Year Member



I am not JS expert by a long stretch, so take this with grain of salt, but hopefully this will give you something to think about until someone more knowledgeable replies.

As you probably know, in simplified terms OnClick performs some action once user clicked on desired ‘object’. See this for more in depth description:

[devguru.com ]
[javascriptkit.com ]

If I was solving your problem, I would define a function that handles your SQL stuff, and then just call it when needed, ie., something like this

function mysqlstuff() {
… sql code here…
}

<form>
<….. OnClick=”mysqlstuff()”>
</form>

below are links to few tutorials that you might find usefulel, however searching for”Javascript SQL” and/or “Javascript onclick SQL” yields bunch of useful results

[asp.net ]
[dotnetjunkies.com ]

HTH

zCat

10:22 pm on Mar 31, 2006 (gmt 0)

10+ Year Member



The buzzword you need to be searching for is "AJAX" (Asynchronous Javascript eXtension or something like that).

cryoman

9:59 am on Apr 1, 2006 (gmt 0)



Thank you all!
Indeed AJAX seems to be the solution, as I tried for some time implementing "function" into JavaScript with no results (database wasn't updated).
Still if you have a good example of code to do what I need please share, till then I will continue extensive search and study.
If I will manage to resolve my own issue, I'll sure publish the code for it here.

Sylver

4:18 pm on Apr 4, 2006 (gmt 0)

10+ Year Member



Just read it and while I am not quite sure this would work (a bit of beginner too), but if I had to work it out, I would probably try to do it like this:

Have a hidden form, use js to feed the query in the hidden input, and then use PHP to actually do the query at a later time.

As I say, I have no clue if this would work in your case.