开发者

How to assign a clicked category name to a variable?

I am attempting to build a category navigation system and so far have all my tables set up and indexed in mysql. My issue is understanding the logic for retrieving the categories I want using php.

I am thinking I need something like:

On click - store clicked category name in variable $category - query variable against database

SELECT subcategory_name FROM subcategories WHERE parent = "$category"

Does this sound right? I think there is not an on click function in php so I am unsure which function should I look int开发者_C百科o that I can use to assign the category name I click to the variable?


It doesn't seem like you want to use javascript in your app. You may want to use an anchor tag with $_GET variables to past the selected category e.g

// You can style the anchor tag to look like a button
<a href='querypage.php?category=books'>Select Books category</a>

On the page querypage.php, you can get the clicked category like this:

$category = $_GET['category'];
// Then you can run your query
SELECT subcategory_name FROM subcategories WHERE parent = "$category"


You are right there is no on click event in PHP. You will need to send an ajax (or normal) request (GET) if you want to run any thing on server (that is what .NET do in the background :))

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜