PHP - How to Create Dynamic URLs?

前端 未结 5 665
挽巷
挽巷 2021-02-06 17:32

I\'ve scoured the web for a tutorial about this simple task, but to no avail. And so I turn to you helpful comrades. Here\'s what I need to do:

I have a MySQL database w

5条回答
  •  说谎
    说谎 (楼主)
    2021-02-06 17:58

    This is basic php. You would simply query the DB for the event details before the page headers are written and write the html accordingly.

    The first thing I would ask you is if you know how to connect to your database. From there, you query based on the $_GET['id'] value and use the results to populate your html.

    Not to be rude, but the question itself suggests you're new to PHP, right? So in order to provide a solution that works we might want to know just how far you got.

    Also, you can rewrite your dynamic urls to appear like static ones using apache's mod_rewrite. It's probably a novice level thing if you're interested in "pretty" url's.

    MODIFIED ANSWER:

    In your loop you would use the id from the query result (assuming your primary key is id)...

    while($field = mysql_fetch_array($result)) { 
        echo "

    "; echo $field['month']." ".$field['day'].", ".$field['year']; echo "

    "; echo "

    "; echo ''.$field['event_name'].''; echo "

    "; }

    Then on somepage.php you would use the get var id to pull the relevant info...

    $result = mysql_query("SELECT * FROM `calendar` WHERE `id` = '".mysql_real_escape_string($_GET['id'])."');
    

    don't forget to look into mysql_real_escape_string() for cleaning entries.

提交回复
热议问题