Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    creating new version of page each time they click on a link

    Ok. So, I've built some tables in MySQL, a list of mammals, amphibians and reptiles.

    When people visit the Mammals page (mammals.php), I want there to be a list of Mammal common names (common_name), and if they click on that common_name, a new version of mammals.php is displayed that writes all the info we have for that specific mammal.

    I know how to write the list of mammal common names. I know how to write all the info for that mammal to a static page.

    However, I can't figure out how to make clicking the echo'd common_name a link to a new instance of mammal.php.

    I really don't want to make 100+ pages, one for each mammal, amphibian and reptile. I want to create a function that can be used for all three.


    while($row = mysql_fetch_array($result))
    {
    echo "<tr>";
    echo "<td>" . $row['common_name'] . "</td>";
    echo "</tr>";
    }
    echo

    Where do I put in the POST, the Variable, the link, the function?

    There must be a simple way to use 'common_name' in the naming paradigm for the on-click variable, such as $Common_Name = $result, but one that creates a unique instance of that variable on-click, so that the function can use that info to compare it to the table values and WHERE they are equal, write a new instance of the page.

    No, this is not for an assignment. This is for a professor's side project website. Yeay me
    Last edited by evestudent; 01-18-2012 at 02:31 AM.

  • #2
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,395
    Thanks
    8
    Thanked 1,078 Times in 1,069 Posts
    echo "<td><a href='show.php?name={$row['common_name']}&type=mammal'>{$row['common_name']}</td>";

    Then you have a php script called "show.php" that gets the name.

    PHP Code:
    <?php
    // connect to database .... at the top of script

    $name=mysql_real_escape_string($_GET['name']);
    $type=mysql_real_escape_string($_GET['type']);


    // do the query 
    $query="SELECT * FROM $type WHERE common_name='$name' ";

    // blah blah

    // loop through the result (you should only have 1 row) and display the information.

    .

  • #3
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Awesome! Give me a minute to test it and I'll post if I have a clue or not

  • #4
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    did not work

    Success!

    At least in part.

    Now it doesn't recognize the comparison of common_name to $name in show.php, because it wants to change all spaces in that name to "%20", like "Box Turtle" becomes "Box%20Turtle", so when we select where common_name is equal to $name, they are different, so it doesn't list anything.

    Anyway to fix this?

  • #5
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, I tested the value of $name by echoing it before writing the table, and $name does not contain the %20, just regular spaces, so no worries there. However, it still is pulling no value for the comparison of common_name and $name. I'll keep puttering.

  • #6
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Argh!

    Here's the place where it's hanging up on show.php....

    echo $name;
    echo $type;

    // do the query
    $query="SELECT * FROM $type WHERE common_name='" . $name . "'";

    echo $name . "<br>";

    Everything before the query works, so we have solid usable values for $name and $type, so it should work in the query.

    But, everything after the query doesn't work. It selects nothing, thinking there are no instances where $name and common_name are the same.

    Any suggestions?

  • #7
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    YEAY!

    Hubby Jim helped me to see that I'd forgotten the mysql_query in my query

    It works!

  • #8
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,395
    Thanks
    8
    Thanked 1,078 Times in 1,069 Posts
    You should also know that you can combine, or JOIN tables when doing queries.
    I didn't mention that before because it seems like you're a total beginner. What
    you're doing now with separate queries is fine. You'll discover more advanced things
    as time goes by.

    Google will be your best source of examples and tutorials.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •