SebZ Posted February 7, 2008 Share Posted February 7, 2008 G'day. I've been working with PHP for a couple of years and I'm really pleased with what it has to offer. Just a quick question, I'm creating a gallery using SimpleViewer and have set up a PHP document to get data from a MySQL database and display it as an XML document. I've also added a $_GET command so the code can know what gallery to get from the database... But the only problem is that it's only on the PHP->XML document and not on the main page... Will I need to set up some sort of $_POST command to read what the main page is asking? Sorry if it makes no sense... It's kinda hard to explain... I might whip up an image to help explain what I mean if no-one gets what I mean. Cheers! ~Sebastian. Quote Link to comment https://forums.phpfreaks.com/topic/89825-help-with-sending-a-url-parameter-to-second-php-page/ Share on other sites More sharing options...
SebZ Posted February 7, 2008 Author Share Posted February 7, 2008 M'Kay, it may be a bit difficult to read so I'll rephrase it. 'gallery.php' has the Flash file with an XML request going to 'galleryData.php' A URL variable goes through gallery.php to select a different gallery in the database and then print that in the XML document, galleryData.php. The problem then hits there, how do I get the URL variable passed to the XML document? Using the require('galleryData.php'); doesn't work because of the header being XML and saying that the HTML code that follows being invalid. But one stroke of luck is that it then recognises that it needs to be that certain gallery. Hm.. Thinking out loud here... How about running the code that asks for the database in a separate file but requested in the main page so the URL variable is passed through and the XML document then requesting that file so in the end, the variable goes though.... If it doesn't make sense, then don't worry because I think I know what I need to do... I'll be back and upload the code to show you what I meant Quote Link to comment https://forums.phpfreaks.com/topic/89825-help-with-sending-a-url-parameter-to-second-php-page/#findComment-460392 Share on other sites More sharing options...
SebZ Posted February 7, 2008 Author Share Posted February 7, 2008 Nope... didn't work. I just need to pass the variable through... Any thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/89825-help-with-sending-a-url-parameter-to-second-php-page/#findComment-460411 Share on other sites More sharing options...
teng84 Posted February 7, 2008 Share Posted February 7, 2008 sorry can you explain it a little more!? Quote Link to comment https://forums.phpfreaks.com/topic/89825-help-with-sending-a-url-parameter-to-second-php-page/#findComment-460415 Share on other sites More sharing options...
SebZ Posted February 7, 2008 Author Share Posted February 7, 2008 (Might as well chop it down to this...) I get a URL variable from one php page with this code... if(isset($_GET['q'])) { $colname_gallery = $_GET['q']; } and I want to send it to another one to get results from a MySQL database. Quote Link to comment https://forums.phpfreaks.com/topic/89825-help-with-sending-a-url-parameter-to-second-php-page/#findComment-460420 Share on other sites More sharing options...
teng84 Posted February 7, 2008 Share Posted February 7, 2008 and how do you want to send it to another page? post, session, or get again? Quote Link to comment https://forums.phpfreaks.com/topic/89825-help-with-sending-a-url-parameter-to-second-php-page/#findComment-460423 Share on other sites More sharing options...
laffin Posted February 7, 2008 Share Posted February 7, 2008 how do u extract the variable from a non existant xml file. galleryData.php, builds the xml file dynamicly... function getxmlcontent() { ob_start(); include('galleryData.php'); $contents=ob_get_contents(); ob_end_cleant(); return $contents; } using ob_ functions u can capture the output of the file, keeping it within a function, keeps the script from overwriting any global variables $xmlcontents=getxmlcontents(); than ya can use a preg_match or strstr function to find the parameter ya looking for and extract it. Quote Link to comment https://forums.phpfreaks.com/topic/89825-help-with-sending-a-url-parameter-to-second-php-page/#findComment-460424 Share on other sites More sharing options...
SebZ Posted February 7, 2008 Author Share Posted February 7, 2008 I'll post the code from all 3 files... gallery.php <?php if(isset($_GET['q'])) { $colname_gallery = $_GET['q']; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>SimpleViewer</title> <script type="text/javascript" src="swfobject.js"></script> <link rel="stylesheet" type="text/css" href="/styles/flash.css" /> </head> <body> <div id="flashcontent">SimpleViewer requires Macromedia Flash. <a href="http://www.macromedia.com/go/getflashplayer/">Get Macromedia Flash.</a> If you have Flash installed, <a href="index.html?detectflash=false">click to view gallery</a>.</div> <script type="text/javascript"> var fo = new SWFObject("viewer.swf", "viewer", "100%", "100%", "7", "#181818"); fo.addVariable("preloaderColor", "0xffffff"); fo.addVariable("xmlDataPath", "galleryData.php"); fo.write("flashcontent"); </script> </body> </html> mysql_gallery.php <?php require('connect.php'); require('gallery.php'); if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } mysql_select_db($database_truevision, $truevision); $query_gallery = sprintf("SELECT * FROM gallery WHERE gallery = %s", GetSQLValueString($colname_gallery, "text")); $gallery = mysql_query($query_gallery, $truevision) or die(mysql_error()); $row_gallery = mysql_fetch_assoc($gallery); $totalRows_gallery = mysql_num_rows($gallery); ?> galleryData.php <?php header ("Content-Type: text/xml"); include('mysql_gallery.php'); print '<?xml version="1.0" encoding="UTF-8"?>'; print '<simpleviewerGallery maxImageWidth="480" maxImageHeight="480" textColor="0xFFFFFF" frameColor="0xffffff" frameWidth="20" stagePadding="40" thumbnailColumns="3" thumbnailRows="3" navPosition="left" title="'. $row_gallery['gallery'] .'" enableRightClickOpen="false" backgroundImagePath="" imagePath="" thumbPath="">'; do { print '<image>'; print '<filename>'. $row_gallery['location'] .'</filename>'; print '<caption>'. $row_gallery['title'] .'</caption>'; print '</image>'; } while ($row_gallery = mysql_fetch_assoc($gallery)); print '</simpleviewerGallery>'; mysql_free_result($gallery); ?> I don't really know what I'm doing... Which every way is the most secure and easiest. Quote Link to comment https://forums.phpfreaks.com/topic/89825-help-with-sending-a-url-parameter-to-second-php-page/#findComment-460429 Share on other sites More sharing options...
teng84 Posted February 7, 2008 Share Posted February 7, 2008 where did you use this? <?php if(isset($_GET['q'])) { $colname_gallery = $_GET['q']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/89825-help-with-sending-a-url-parameter-to-second-php-page/#findComment-460432 Share on other sites More sharing options...
SebZ Posted February 7, 2008 Author Share Posted February 7, 2008 What do you mean? $colname_gallery? Quote Link to comment https://forums.phpfreaks.com/topic/89825-help-with-sending-a-url-parameter-to-second-php-page/#findComment-460436 Share on other sites More sharing options...
SebZ Posted February 7, 2008 Author Share Posted February 7, 2008 Huh! I just did a few tests, and it turns out that the variable is getting to the code... on both pages! I created an else on it to send it to the first gallery and that works... I wonder why the rest isn't. Quote Link to comment https://forums.phpfreaks.com/topic/89825-help-with-sending-a-url-parameter-to-second-php-page/#findComment-460453 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.