Page 1 of 1

a little struggle with variables and stuff!

Posted: Sun Apr 27, 2003 12:29 pm
by noBrainer
Hi all,

I'm new to PHP (not to programming) and have a little difficulty with variables. I know PHP for 3 days now and I'm "trying" to create a dynamic website for personal use.

The problem is this:

I have a demo section wich shows shockwave movies in a table. That all works fine. I wrote this code to show the shockwave movie:

Code: Select all

class demoView
	{
		function demoView($demoDCR)
		{
		echo("
		<object classid=clsid:166B1BCA-3F9C-11CF-8075-444553540000
 		 codebase='http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,0,0'
 		 ID=demoViewWin width=450 height=320>
		<param name=src value=demos/show/"."$demoDCR".".dcr>
		<param name=swStretchStyle value=fill>
		</object>
		");
		&#125;
	&#125;
	if ($demoFile !== NULL) &#123;
		new demoView($demoFile);
	&#125;
What I want is when the user clicks on a link the variable $demoFile gets updated to show the shockwave movie (to wich the link points). But I don't know how to get it to works.
Also the main PHP page has included/required all the part on the page.

require(header)
require(menu)
include(demos)

something like this. Everything runs. But I can't seem to get that friggin link to work.
Does anybody has an idea?

Thanks in advance.

Posted: Sun Apr 27, 2003 2:24 pm
by inn
hi noBrainer,

well about your inquiry, since you have used a class with a constructor that best way to execute that function through the link will be something like this :

suppose you have a link in your page thats like :
http://yousite.com/index.php.

if you have all the login in this file then i suppose passing the $demoView will be like this:
http://yoursite.com/index.php?demoview=yes

and your code will be :

Code: Select all

<?php

if ($_GET['demoview'] == "yes") {
    call_user_func (array ("demoView", "demoView"));
}

?>
this little code will make sure that the variable passed through the url (ie: demoview is 'yes') and if it is... it'll call your user function in the class demoview.

make sure that you have inserted your code that is the class demoView in the index page or included it through include or require.

hope this'll help ;)

Posted: Sun Apr 27, 2003 3:06 pm
by noBrainer
Thank you very much for the reply. I will give it a shot!

:mrgreen:

Cheers!

Posted: Sun Apr 27, 2003 6:03 pm
by noBrainer
I've tried it and I can't really figure it out. Maybe I need to explain some more to give you guys a more detailed view of the situation.

I have a main.php wich includes the other *.php files.
main.php looks like this:

Code: Select all

<?
	require("header.php");
	require("menu.php");

	if ($section == NULL)&#123;
		include("home.php");
	&#125;else&#123;
        include("$section".".php");
	&#125;
?>
As you can see I used the $section variable to control wich *.php file is included. This is the content I want to be showed.

Code: Select all

main.php?section=demos
This is what I used in the menu link to show the content for the demos.

Now, I don't really know how to let the included demos.php know that he has to use the $demoFile to display the shockwave movie of choice.

I could pass the variable via a link to demos.php (demos.php?demoFile=whatever) but then the browser only shows demos.php. So my header and menu files are gone. This is what I don't want to happen.

Am I approaching this the right way?
How can I link this properly when the demo thumbnail is clicked ( the demo thumbnails are also within demos.php)?

Cheers. 8)

ps. When I try to pass the variable via a URL (main.php?section=demos?demoFile=whatever) main.php tells me it can't find whatever.php! Why is that?

Or can't I give more then one variables through a URL?

Posted: Mon Apr 28, 2003 10:42 am
by noBrainer
Got it!