Results 1 to 10 of 10

Thread: passing variable to next page

  1. #1

    Default passing variable to next page

    Although I am using Netobjects 12 this may be the wrong forum since it is purely a PHP question. However I could not find an appropriate forum for it.

    It is a long time since I have done any php coding and I took the following code from a working site I built a long time ago. Unfortunately on this new site I cannot get the variable $photo_id to pass to the next page. When I hover the mouse over the thumbnail it shows the correct id but not on the following page.
    Can someone help please?
    Code:
    <?php
    $query = "SELECT photo_id, photo_thumbnail, photo_caption  FROM memphoto ORDER by photo_id DESC";
    
    $ret = mysql_query($SQL); 
    $numrows = mysql_num_rows($ret);
    
    if (!$ret) { echo( mysql_error()); } 
    else { 
    
    $col=0;
    
    echo '<table width="500" border="0" cellspacing="1" cellpadding="2" align="center">';
    while ($row = mysql_fetch_array($ret)) { 
    $photo_id = $row['photo_id'];
    $thumbnail = $row['photo_thumbnail'];
    $caption = $row['photo_caption'];
    
    	if($col==0) echo '<tr>'; 
    
    echo "<td><a href=\"view_photo.php?photo_id=$photo_id\"><img src=\"$thumbnail\"></td>";
    
    	$col++;
    	if ($col==4){
    		echo '</tr>';
    		$col=0; }
    	}
    }
    if($col!=0) str_repeat('<td></td>', 4 - $col);
    echo '</table>'; 
    ?>
    I used the same code some time ago at
    http://www.strathclydewoodturners.co...Alex%20Francis
    and that works fine. Could this be a PHP version problem. Sorry for being an idiot about this but I am not a programmer.

  2. #2
    Senior Member LBA's Avatar
    Join Date
    Jan 2010
    Location
    California
    Posts
    543

    Default

    Can you show us the pages that aren't working?

    Laurence

  3. #3
    Senior Member chuckj's Avatar
    Join Date
    Jan 2010
    Location
    www.beyondfusion.com - Florida
    Posts
    1,302

    Default

    You either have to pass the variable as part of a URL (the GET method) or as a session variable.
    Chuck Joslin
    www.BeyondFusion.com
    PHP & MySQL development with Fusion
    Fusion support for AllWebMenus (Likno) Contact me for custom AWM menus for your sites.
    Tutorials and Forums

  4. #4
    Senior Member LBA's Avatar
    Join Date
    Jan 2010
    Location
    California
    Posts
    543

    Default

    That code is using the GET method. I was curious to see if the result page shows the parameter in the location bar. If so, then the problem could be in the naming of the result page (PHP?) or maybe in the $_GET code.

    Laurence

  5. #5

    Default

    Laurence

    Yes it shows the parameter in the location bar. I have tried to show the page but cannot even get the thumbnails to show on the remote server. Will need to start again. Probably come back to you when I get that page working.
    Greenockturner

  6. #6
    Senior Member LBA's Avatar
    Join Date
    Jan 2010
    Location
    California
    Posts
    543

    Default

    If it shows in the location bar, the parameter is being successfully passed to the page. So the question isn't How to pass a parameter... it's How to do something with a passed parameter. Does the resulting page have a PHP filename extension? What is the code that you are placing on that page?

  7. #7

    Default passing variable to next page

    The code I am placing on the page is as follows
    Code:
    <?php
    echo ('photo_id is: $photo_id');
    $SQL = 'SELECT photo_id, photo_filename, photo_caption, photo_description, photo_gallprice FROM memphoto WHERE photo_id = $photo_id ';
    
    // execute SQL statement 
    $ret = mysql_query($SQL); 
    $numrows = mysql_num_rows($ret);
    
    if (!$ret) { echo( mysql_error()); } 
    else { 
    
    while ($img = mysql_fetch_array($ret)) { 
    $id = $img['photo_id'];
    $photo = $img['photo_filename'];
    $caption = $img['photo_caption'];
    $description = $img['photo_description'];
    $price = $img['photo_gallprice'];
     
    }
    }
    // set the initial value for previous and next image id
    $prev = $next = 0;
    // get the previous image
    		$sql  = 'SELECT photo_id FROM memphoto WHERE photo_id < $photo_id ORDER BY photo_id DESC LIMIT 0, 1'; 
    				 		
    		$result = mysql_query($sql) or die('Error, get image info failed. ' . mysql_error());
    		
    		if (mysql_num_rows($result) > 0) {
    			$row = mysql_fetch_assoc($result);
    			$prev = $row['photo_id'];
    		}
    		//echo ("previous id is: $prev");
    
    		// get the next image
    		$sql  = 'SELECT photo_id FROM memphoto WHERE photo_id > $photo_id ORDER BY photo_id ASC LIMIT 0, 1'; 
    		
    		$result = mysql_query($sql) or die('Error, get image info failed. ' . mysql_error());
    		
    		if (mysql_num_rows($result) > 0) {
    			$row = mysql_fetch_assoc($result);
    			$next = $row['photo_id'];
    		}
    		//echo ("next id is: $next");
    ?>
    I now have the page working showing the problem at http://www.francisgreenock.co.uk/htm...thumbnails.php
    Thanks for your help so far. I feel I am at last getting somewhere

  8. #8
    Senior Member LBA's Avatar
    Join Date
    Jan 2010
    Location
    California
    Posts
    543

    Default

    The URL parameter is being passed to the page but before you can do anything with it, your code needs to grab it from the URL and define it as a variable. The GET statement is what you use to be able to take what's in the URL and do something with it. You need to add this at the top, before the first echo statement...

    $photo_id = $_GET['photo_id'];

    Laurence

  9. #9

    Default passing variable to next page

    I have now added the code like this
    Code:
    <?php
    $photo_id = $_GET['photo_id'];
    echo ('photo_id is: $photo_id');
    $SQL = 'SELECT photo_id, photo_filename, photo_caption, photo_description, photo_gallprice FROM memphoto WHERE photo_id = $photo_id ';
    Still not working!!! Sorry

  10. #10
    Senior Member LBA's Avatar
    Join Date
    Jan 2010
    Location
    California
    Posts
    543

    Default

    Use double-quotes in place of your single quotes, as below:

    echo ("photo_id is: $photo_id");

    Laurence

Posting Permissions

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