Jump to content


Photo

*solved* PHP Variable passing (I should be embarrassed)


  • Please log in to reply
3 replies to this topic

#1 laide234

laide234
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 13 September 2006 - 12:59 PM

Please take a look at my code below. I would like to pass the variable in $autoNum to whichever of the php pages are loaded (edit, add or delete). 

autoNum is the primary key


<?php 
switch ($view) {
	case 'edit' :
		$content 	= 'edit.php';		
		break;

	case 'add' :
		$content 	= 'add.php';		
		break;

	case 'delete' :
		$content 	= 'delete.php';		
		break;
		
	default :
		$content 	= 'edit.php';		
}
?>

      <td width="50%" colspan="2"> 
<?php 
	echo $autoNum;
	require_once $content; 
?>


How do I send $autoNum to the requested page. :-[

#2 scottybwoy

scottybwoy
  • Members
  • PipPipPip
  • Advanced Member
  • 532 posts
  • LocationUK

Posted 13 September 2006 - 01:06 PM

couldn't you use post?  Or put it in a class and use exteds on the following pages.

And while were here, what's case? looked it up in the man, just came up with cos isn't really the same?

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 13 September 2006 - 01:31 PM

If you are including/requiring scripts then any variables you have set in the script that is including/requiring the files can be using in the included/required script.

Eg:
test.php
<?php

$varname = 'Hello world';

// include test2.php
// we'll be able to use the variable set above in test2.php
include 'test2.php';

?>


test2.php
<?php

// show the value of $varname.
// this will use the variable we set in test.php
echo $varname;

?>


When you go to test.php you should get Hello World printed to the screen.

When using include/require what PHP is affectively doing is basically getting the contents of the required script and pasting it in the location of where the file gets included to as though the code was already there. For example, think of test.php being like this when you run test.php
<?php

$varname = 'Hello world';

// include test2.php
// we'll be able to use the variable set above in test2.php

// show the value of $varname.
// this will use the variable we set in test.php
echo $varname;

?>


#4 laide234

laide234
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 13 September 2006 - 01:36 PM

::) Man! I am such a noob.... "(probably simple answer)"  I would have never guessed that I didnt need to pass anything.

Thank a mill', wildteen88.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users