Page 1 of 4 123 ... LastLast
Results 1 to 10 of 32

Thread: How do you pass a value through the address URL?

  1. #1
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    602
    Thanks
    266
    Thanked 13 Times in 13 Posts

    Default How do you pass a value through the address URL?

    I have seen a lot of websites where the id value for the current record is passed on the end of the URL address. For example:

    http://www.website.com/view_entry.php?id=23045

    How do you get the view_entry.php file to be a file that will allow you to do this? Do you place something in the file to know to look there for a value? Or how do you get the file to run using that particular value?

    How do you stick the bit on at the end (after the ?)?

    I'd google it but don't know what it's called. Thanks.

  2. #2
    Join Date
    Jul 2007
    Location
    Azerbaijan, Baku
    Posts
    144
    Thanks
    11
    Thanked 27 Times in 25 Posts

    Default

    If i didn't understand you correctly sorry.

    Then get that value with mysql.

    SELECT * FROM myarticle WHERE id='$id';

    then they get that row and etc.

  3. #3
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,626
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    The values passed as a part of the URL string is based on HTTP method GET. So you can use your server-side method for gathering the parameters like the normal GET method based ones.

    In most of the server-side tools they have different methods for gathering parameters from the client in GET and POST methods. Anything that comes as a part of the URL string will be considered as a GET method.

    Please find an example below based on PHP

    filename: one.htm
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    	<head>
    		<title>Untitled Document</title>
    		<style type="text/css">
    
    		</style>
    		<script type="text/javascript">
    
    		</script>
    	</head>
    	<body>
    		<a href="one.php?name=Code&age=33">PHP File</a>
    	</body>
    </html>
    filename: one.php
    Code:
    <?php
    	$name = $_GET['name'];
    	$age = $_GET['age'];
    	
    	print "The parameters passed through URL are $name and $age";
    ?>
    If you have a webserver in your PC then save these code in the mentioned names in the publishing root of your webserver, browse the HTM file and click the link and you can see how the parameters are passing.

    Hope this helps.

  4. The Following User Says Thank You to codeexploiter For This Useful Post:

    kuau (07-18-2008)

  5. #4
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    602
    Thanks
    266
    Thanked 13 Times in 13 Posts

    Default

    Yes! That is what I'm talking about! Here is the code that displays the link:

    Code:
    <a href="/php/event-detail.php?event_id=$event_id">
    but when I click on it, the address URL looks like this:

    http://www.calendarmaui.com/php/event-detail.php?event_id=$event_id

    If I put a literal number instead of $event_id it works, but it is a list of different events so I have to use a variable. Thanks so much for helping me with this. It is a live site and I have to get it working asap.
    Last edited by kuau; 07-18-2008 at 12:45 PM. Reason: fixed the tags

  6. #5
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,626
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Code:
    <a href="/php/event-detail.php?event_id=$event_id">
    Try to chanage the above one to the following.

    Code:
    <a href="/php/event-detail.php?event_id=<?=$event_id ?>">some link text</a>
    Or

    Code:
    <a href="/php/event-detail.php?event_id=<?php print $event_id ?>">some link text</a>
    Then see the link shows the value stored in $event_id in the URL or not.

  7. The Following User Says Thank You to codeexploiter For This Useful Post:

    kuau (07-18-2008)

  8. #6
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    602
    Thanks
    266
    Thanked 13 Times in 13 Posts

    Default

    Dear Code:

    Yes, that is almost it! But it put the same number on all of the links so I tried moving the display to inside the while loop and it seemed to fix the links sort of, but it wonked out something and made it take a long time. Would you mind please taking a look at the code & tell me where to put the bracket? It's only 52 lines.

    Thanks a million. e
    Last edited by kuau; 07-18-2008 at 01:21 PM. Reason: sp

  9. #7
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,626
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    A link to your page or the source code needs to be furnished here for that.

  10. #8
    Join Date
    Jan 2008
    Posts
    4,167
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Check my post below.
    Last edited by Nile; 07-18-2008 at 01:52 PM.
    Jeremy | jfein.net

  11. #9
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    602
    Thanks
    266
    Thanked 13 Times in 13 Posts

    Default

    Any suggestions for improvement gratefully accepted.

    Code:
    <?php 
    putenv("TZ=Pacific/Honolulu");
    include('cal-connectdb.php'); 
    
    $today = date ('Y-m-d');
    
    $query = " SELECT `event_id`, `startdate`, `event_title`
               FROM `event`
    			     WHERE `featured` = '1' AND `startdate` >= '".$today."'						  
               ORDER BY `startdate`, `event_title` LIMIT 200 ";	
    
    $result = @mysql_query($query,$connection) or die("Couldn't execute $query query.");
    $eventList = array();
    
    while ($row = mysql_fetch_array($result))
    {
    	$event = array();
    
    	$event_id  = $row['event_id' ];
    	
    	// Get details for each event
    		
    	$query = "SELECT `event_title`, date_format(`startdate`, '%M %D, %Y') as date, time_format(`starttime`, '%h:%i %p') as time
    			      FROM `event` 
    		  			WHERE event_id = '".$event_id."'  ";
    
    	$result2 = @mysql_query($query,$connection) or die("Couldn't execute $query query.");
    	$row2 = mysql_fetch_array($result2);
    
    	$event['event_title'] = $row2['event_title'];
      $event['startdate']   = $row2['date'];
      $event['starttime']   = $row2['time'];
    	$event['endtime']     = $row2['endtime'];
    	
    	mysql_free_result($result2);
    	unset($row2);
    
    	array_push($eventList, $event);	
    	
     } 
    
    //mysql_free_result($result);
    //unset($row);
    
    mysql_close($connection); 
    ?>	
    
    <? foreach($eventList as $event) { ?>
    	<div class="event">
    		<a href="/php/event-detail.php?event_id=<?=$event_id?>"> <?=$event['event_title'];?></a><br><?=$event['startdate'];?> at <?=$event['starttime'];?>
    	</div><!--End event-->
    <? } ?>

  12. #10
    Join Date
    Jan 2008
    Posts
    4,167
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Change line #50, to this:
    PHP Code:
    <a href="/php/event-detail.php?event_id=<?=$event_id++;?>"> <?=$event['event_title'];?></a><br><?=$event['startdate'];?> at <?=$event['starttime'];?>
    Jeremy | jfein.net

Bookmarks

Posting Permissions

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