Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 287
  • Last Modified:

submit an action to a php file

Hello,
i got a question about how to call a php from a html:

i want to display some users name in alphbatic order, something like:

A B C D E F...Z

When user click A, then all user's last name starts from A will be pulled out from the database and displayed.

So I'm thinking in a form of html, there is some code :
< form >
<a href="" onclick=""> A </a>
<a href="" > B</a>
<a href="" > C </a>

</form>

My questions are:
1. How to envoke/submit an action from the  letter "A" ...that call a php file?

2. Do I need to call the php file 26 times?
Some sample code will be very helpful to me.

Any suggestion is greatly appreciated,
lilyyyan
0
lilyyan
Asked:
lilyyan
  • 3
  • 2
3 Solutions
 
b0lsc0ttCommented:
Why use an html file at all?  Do you want all names displayed or just those for the letter clicked on?  Do you want these display without reloading the page or does that not matter?

Since PHP sends html to the browser I don't see why you need 2 files.  Just use a PHP page and script.  The script can first send just the letters.  Each will have a link to resubmit the page when clicked.  The link can be used by the PHP script to know a letter was requested and send back a reply with the names for that letter.

If you can provide html and php you currently have then I can be more specific.  However in general it would be something like ...

if (isset($_GET['letter']) {
    // code to get letter from URL query string, get names that match and send response back to browser
} else {
    // code for default page, no letter clicked so just send list of letters
}

Let me know how this helps or what questions you have.

bol
0
 
orbic1Commented:
lilyyan - you don;t seem to have much of a grasp of php yet. If its urgent, get somebody else to do it!

you should have (including b0lsc0tt's code):

file: myfile.php

<?php

if (isset($_GET['letter']) {
    // code to get letter from URL query string, get names that match and send response back to browser
   echo $_GET['letter']; // This will show the letter
   $letter = $_GET['letter']; // This will let you do something with the letter a bit more easily
   
    // You can connect to your database and run a query like: SELECT * FROM table WHERE letter='$letter'

} else {
    // code for default page, no letter clicked so just send list of letters
   // You might want to put your HTML code shown below here
}

?>

<a href="myfile.php?letter=a">A</a>
<a href="myfile.php?letter=b">B</a>
<a href="myfile.php?letter=c">C</a>
....
<a href="myfile.php?letter=z">Z</a>



Have a look at:

http://www.php.net
http://uk2.php.net/variables.predefined        for $_GET
http://uk3.php.net/mysql      for mysql stuff
http://www.phpfreaks.com        for tutorials etc

0
 
lilyyanAuthor Commented:
Hi thanks very much for your replies.

yeah, i don't know much about php so far, yet i would like to have a try: )))

okay, let me start step by step..

Basically, I want the first look  of myfile.php like this:

A B C .... Z //  all letters are clickable

//Then under the letters, all of user names is displayed, in alphbatic order, but I don't have to do this step for now.

//The firest step I want to is: when user click any one of letters, for example : A, then all user's last name starts from A will be displayed.

Some questions about the code:
1. Would you please explain a little more about this line? How do I know if the letter A is set, and its value ?
<a href="myfile.php?letter=a">A</a>

2. Do I neen a onclick action for submit the request?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
b0lsc0ttCommented:
>> Would you please explain a little more about this line? <<

That line would be on the page from the start.  Each letter would look like that but with a unique value after the letter= part.  The script would know A was selected when the A link was clicked because letter would equal A.  You get the value of letter with $_GET['letter'] in your PHP script.

>> Do I neen a onclick action for submit the request? <<

You would not need an event (onclick or submit) to trigger this.  Those are anchors or links and will work as it is.  All of this is done in the PHP file "myfile.php".

I hope that answers all of your questions and gets you going.  Let us know if you still have more on this or what additional info you need.

bol
0
 
b0lsc0ttCommented:
I'm glad I could help.  Thanks for the grade, the points and the fun question.

bol
0
 
orbic1Commented:
Thank you too! Its nice to get this sort of question once every now and then! Stick with the PHP - its ultimately very frustrating, rewarding, sleep depriving and good fun!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now