PHP - How to Create Dynamic URLs?

前端 未结 5 718
挽巷
挽巷 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 18:14

    Here is the pertinent code for extracting a list of events in November from a table named calendar, with each event having a link to a page called event.php and with the event's id field appended to the end of the url:

    $result = mysql_query("SELECT * FROM calendar WHERE sort_month='11'");  
    while($row = mysql_fetch_array($result))  
    {echo  
    "".$row['event_name'].""  
    ;}  
    

    And here is the pertinent code on the event.php page. Note the row numbers in brackets depends on the placement of such in your table, remembering that the first row (field) would have the number 0 inside the brackets:

    $id = $_GET['id'];  
    $sql = "select * from calendar where id = $id";  
    $result = mysql_query($sql, $con);  
    if ($result){  
    $row = mysql_fetch_row($result);  
    $title = $row[12];  
    $content = $row[7];  
    }  
    ?>  
    
      
      
    <?php echo $title ?>  
      
      
    

    This works for me, thanks to the help from those above.

提交回复
热议问题