hi, i'm new in programming PHP. I have this task to be done.
the first page which is category.php show the list of category that I retrieve from the database name 'event' with table 'category'
here is the code:

//the connect_db already done in single php file

<table border=1 bgcolor="blue">
    <th>Competition Name</th>


    $sql = "SELECT cat_id , cat_name FROM `category`";
    $result = mysql_query($sql);

    while ($r=mysql_fetch_array($result)){
        <a href="testing_cat.php?id=<?php echo $r['cat_id']?>"><?php echo $r['cat_name'] ?></a>

    <?php } ?>

this script has run well which show me the link of localhost/webtest/testing_cat.php?id=CA001 when I click the first category.

My question is how to get the result showing the list of competition that only have the same cat_id as in hyperlink?


5 Years
Discussion Span
Last Post by diafol

If you mean:

<a href="testing_cat.php?id=<?php echo $r['cat_id']?>"><?php echo $r['cat_name'] ?></a>

1) Get the id value from $_GET['id']
2) Clean it with mysql_real_escape_string() and call it $id
3) Use it in a query, e.g.

"SELECT ... FROM competitions WHERE cat_id = $id" 

thanks for the help diafol. I want to ask after I redirect the click from the list of category, I wish the new page which is localhost/webtest/testing_cat.php?id=CA001 will show the result of competition from code CA001. I still don't too understand with the php.
WHere i need to put the $_get['id'] in the new webpage script?


Look for $_GET[] in the php manual

help me :(

I did. The link above is more help. Give it a go.


Ok ,mark as solved - link below.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.