Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Linux, Apache, MySQL > MySQL Help

MySQL Help Post any question relating to MySQL here and hopefully someone can help

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2004-07-24, 04:40 AM
Junior Member
 
Join Date: Jul 2004
Posts: 11
prolong199
Default

i have a button and when you click on it it executes a query, how do i make it so if i click a different button it executes a different query
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 2004-07-24, 09:39 AM
Xnuiem's Avatar
Senior Member
 
Join Date: May 2004
Location: DFW, Texas
Posts: 1,104
Xnuiem will become famous soon enough
Send a message via Yahoo to Xnuiem
Default

In whatever page you are going to after you press the buttons...

Name the buttons different things so when you press on one to submit the form, you can switch on that name. OR you can use the button as your input type and just go to URL using javascript and pass the argument in the URI. I suggest using the latter.

<input type=button value="button 1" onClick=goTo('page.php?button=1')>

<script language=javascript>
function goTo(url){
window.location.href = url;
}
</script>

Then in the destination page.

switch($_GET[button]){
case 1:
$sql = "query 1";
break;
case 2:
$sql = "query 2";
break;
}
mysql_query($sql);

This is all extremely basic logic. I doubt we are seeing anything new here, but you were more than likely having issues putting the logic together.

The best way to do this is figure out where you want to be. Then decide on a way to do that. Then work on how to get there. It doesnt have to be perfect, nor does it have to work the first time, and you can always change it later. But if you do not understand the process to follow and create logic, we will be seeing much more of you around here.
__________________
I rarely give code examples.
No, I have never used IIS or Windows of any kind as a web server. Get a real OS!
Please don't PM me, I won't respond.
Reply With Quote
  #3 (permalink)  
Old 2004-07-25, 05:13 AM
Moderator
 
Join Date: May 2004
Location: Portugal
Posts: 143
gesf is an unknown quantity at this point
Send a message via ICQ to gesf Send a message via MSN to gesf Send a message via Skype™ to gesf
Default

Xnuiem is right!
You can even do:
Code:
// Using this you´ll need the javascript function
// that´s in the Xnuiem post

<input id="query1" type="button" value="button 1" onClick="goTo('page.php)">

// Or: (in this case, the destination page 'page.php'
// will be in the form action

<input id="query1" type="submit" value="button 1">

// Then in the destination page.

// For the 2nd case: if(isset[$_POST['submit']]) {
// $_GET/$_POST depending on your form method

if(isset($_POST['query1']){
  $sql = "query 1";
}
elseif {
// Another one
}

mysql_query($sql);
Cheers
__________________
Best Regards,
Gonçalo "GesF" Fontoura

Website : gesf.org
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.5 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.5 (a popular PHP IDE) and NuCoder 2.0 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 11:05 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.