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">
    <tr>
    <th>Competition Name</th>
    </tr>

    <?php

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

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

    <?php } ?>
</table>

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?

thanks

Recommended Answers

All 6 Replies

Member Avatar for 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?

this is my overview of the category.php page:
Click Here

and this where i want to put my list of competition
Click Here

help me :(

Member Avatar for diafol

Look for $_GET[] in the php manual

help me :(

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

solved. thanks diafol :D

Member Avatar for diafol

Ok ,mark as solved - link below.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.