Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to link html <a> to PHP???

Status
Not open for further replies.

stealth71

Programmer
Feb 22, 2005
14
0
0
US
I have a page for a mysql database that just lists everything in the database in a table. I want to be able to click on the column name and sort the table by that attribute. I know how to sort the database using mysql commands through PHP.

The Problem is I don't know how to call the PHP inside the tag.
Code:
<a href="<? print 'something';?>"> Something</a> This doesn't work.

Do I need to call a new page and just put the column name in the query string? Then use that to sort the database.

Is there a way to do this without calling a new page?
 
There are ways to resort the data without calling a new page. Those ways, however, would not use PHP and as such are outside the scope of this forum.

If you are willing to use PHP by refetching the page, point your anchor tag at a PHP script that can take a GET-method input. That script will use that input to determine how to sort and display the data. Something like:

<a href="
Want the best answers? Ask the best questions!

TANSTAAFL!!
 
You would construct the href attribute with the appropriate GET parameter, the column name:
Code:
<a href="list.php?orderby=whatevercolumn">whatever</a>
Producing the correct HTML with PHP is just printing out the appropriate strings.

If you ask about a "new" page, do you mean a different PHP script, or, is there a way to use client side scripting to re-order the result?
There is client side scripting that can do that, however, then you would be completely relying on the browser. For that question the JavaScript forum would be the appropriate place to post.

After all, I think reloading the page with the passed paramater should not be too much of a hassle.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top