This topic is locked
[SOLVED]

 Run sql Statement via button?

11/21/2006 4:16:12 PM
PHPRunner General questions
sol_knar author

Hello,

I would like to add a button that would execute a sql update statement on my database. Supposing that my sql statement is this.

Update tablename SET fieldname=0 WHERE fieldname =1

How is this best accomplished?

Thanks,

William

Alexey 11/22/2006

William,
here is what you can do.

Proceed to the Visual Editor tab, click to the place you want to place the button, switch to HTML mode and insert this code there:

<input type=button value="Do SQL" onclick="sqlform.submit();">


Then insert this code in the very end of the file:

<form name="sqlform" method=post>

<input type=hidden name="sql" value="1">

</form>


Proceed to Events tab and add this code to the OnLoad event of your page:

global $conn;

if(@$_POST["sql"]=="1")

{

db_exec("update ... set...",$conn);

}

sol_knar author 11/22/2006

Great. Code is perfect. However I do not seem to be able to directly edit the html? Is that intentional?

Thanks,

William

admin 11/22/2006

William,
you can switch to HTML mode in visual editor.

D
dani 4/11/2007

would this work for pre-programmed (hardcoded) searches? I'd like to have several buttons like "SHOW OPEN", "SHOW PENDING", and so on. Each button would hide records that don't meet the search, of course.
Thanks
Dani

J
Jane 4/11/2007

Dani,
sure this method works for search queries.

Just add following code in the HTML mode on the Visual Editor tab:

<INPUT onclick="java script: window.location='TableName_list.php?a=search&amp;value=1&amp;SearchFor=666&amp;SearchOption=Contains&amp;SearchField=Price';" type=button value="some search">


You don't need to add additional form or event.

D
dani 4/11/2007

Dani,

sure this method works for search queries.

Just add following code in the HTML mode on the Visual Editor tab:

<INPUT onclick="java script: window.location='TableName_list.php?a=search&amp;value=1&amp;SearchFor=666&amp;SearchOption=Contains&amp;SearchField=Price';" type=button value="some search">


You don't need to add additional form or event.



It worked! Thanks!

D
dani 4/11/2007

Dani,

sure this method works for search queries.

Just add following code in the HTML mode on the Visual Editor tab:

<INPUT onclick="java script: window.location='TableName_list.php?a=search&amp;value=1&amp;SearchFor=666&amp;SearchOption=Contains&amp;SearchField=Price';" type=button value="some search">


You don't need to add additional form or event.


Can we use AND, OR, NOT with this method?
Much thanks
Dani

J
Jane 4/12/2007

Dani,
sure you can use AND, OR and NOT in your search queries.

D
dani 4/13/2007

Dani,

sure you can use AND, OR and NOT in your search queries.


I'm having trouble imagining how to code a search like that into a url. Let's say I want a button for price = 666 and stock = yes. How do I hardcode that into this query?:

<INPUT onclick="java script: window.location='TableName_list.php?a=search&value=1&SearchFor=666&SearchOption=Contains&SearchField=Price';" type=button value="some search">
R
rayjvb 4/13/2007



I'm having trouble imagining how to code a search like that into a url. Let's say I want a button for price = 666 and stock = yes. How do I hardcode that into this query?:

<INPUT onclick="java script: window.location='TableName_list.php?a=search&value=1&SearchFor=666&SearchOption=Contains&SearchField=Price';" type=button value="some search">



Hello, my first time to post. I'm very interested in this question and solution. I too am having the same issues! Any further help in this matter would be greatly appreciated. Thank you support team!!!!

admin 4/13/2007

Here is how this can be done:

  1. Proceed to the search page in Visual Editor and switch to HTML mode
  2. Change form method prom POST to GET
    <FORM name=editform action=Cars_list.php method=GET>


3. Build an application, proceed to the search page and choose search options including NOT, AND, OR etc.

Run the search and copy the URL.
4. Use this URL in your code.
5. Switch form back to POST.

D
dani 4/13/2007

Here is how this can be done:

  1. Proceed to the search page in Visual Editor and switch to HTML mode
  2. Change form method prom POST to GET
  3. Build an application, proceed to the search page and choose search options including NOT, AND, OR etc.

    Run the search and copy the URL.
  4. Use this URL in your code.
  5. Switch form back to POST.


Did it! And it works! Thanks!
This is how it looks like (it should be all in one line. I broke it to make it easier to read):

http://www.....com/orders/orders_list.php?

a=advsearch&

type=and&

asearchfield%5B%5D=status&asearchopt_status=Equals&value_status=PAID&

asearchfield%5B%5D=shipway&asearchopt_shipway=Equals&value_shipway=TRUCK



This shows me all the orders with status = PAID and shipway = TRUCK.
Now I'd like to throw something MORE interesting:
Is there a way to do CUMMULATIVE filter buttons?
For example: I click on "PAID" and it filters out all unpaid records, then i click on "TRUCK" and applies the new filter over the already filtered records.
The way I understand it the current method (like the code above) passes parameters to an existing search function, but it doesn't actually work on the mysql table itself. Maybe the cummulative filter buttons could be achieved by coding actual SQL queries in them. Is this doable?
Thanks
Dani