Jump to content

Help with sending a URL parameter to second php page.


Recommended Posts

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.

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 :P

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.

 

 

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... :P

Which every way is the most secure and easiest.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.