If then statement problem *INTRIGUING*

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
spoon_watch
Forum Newbie
Posts: 3
Joined: Tue Feb 10, 2004 12:43 am

If then statement problem *INTRIGUING*

Post by spoon_watch »

long time listener first time caller....

anyways I have a question, i'm relatively new to php, but i want to create a compound if statement to use one echo over another when someone has a smaller or larger resolution.

however i do not understand how i would go about calling the users resolution and then choosing to echo one output over another.

and since i cannot create the forementioned if statement i have not had a chance to see if it will easily work within the other if statement.

what i'm trying to achieve is that my existing if statement which dynamically generates a frameset for my site will then choose not only which page to output in the frameset but also which dimensions to use for the frameset.

it's a challenge but your help is deeply appreciated,

MIKE
User avatar
Michael 01
Forum Commoner
Posts: 87
Joined: Wed Feb 04, 2004 12:26 am

Post by Michael 01 »

just do it this way (all credit goes to: Java Scripts) and this guy: mike.lindahl@telia.com

Code: Select all

<!--Put the actual script between the head-tags-->

<SCRIPT LANGUAGE="JavaScript">
//submitted to A1 javaScripts by Micke (mike.lindahl@telia.com)
<!--
function redirectPage() &#123;
var url640x480 = "url";   //put the url´s here
var url800x600 = "http://www.a1javascripts.com/essential_scripts/800x.html";
var url1024x768 = "url";
if ((screen.width == 640) && (screen.height == 480)) 
window.location.href= url640x480;
else if ((screen.width == 800) && (screen.height == 600))
window.location.href= url800x600;
else if ((screen.width == 1024) && (screen.height == 768))
window.location.href= url1024x768;
else window.location.href= url800x600;
&#125;
// -->
</SCRIPT>
</HEAD>
	
<!--Put the event onload in the body-tag-->
<BODY onload="redirectPage();">
As you can see, you can enter in the addresses you wish to foramt to the user's resolution.
spoon_watch
Forum Newbie
Posts: 3
Joined: Tue Feb 10, 2004 12:43 am

Thanks Michael (POST CONT'D ADDING MORE DETAILS)

Post by spoon_watch »

Thanks Michael 01 for your reply, but I'm already using a very similar javascript code that way.

My post was more concerned about compounding all the PHP if statements into one simple redirect frameset code like this; if your id variable is this then check the variable for validity, then if correct read the variable and output the proper files into each of the framesets at a certain size. I wanted to know if you could read the users screen resolution before I outputed the frameset echo so that I could make two or three different sizes of output framesets all in one file without having to redirect them from the index.

From all the research I've done it's much easier to do it the way that I have it now, I was wondering if their was a php way of compunding the if statements. If you have any more ideas please help me out.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

you can set a variable using javascript taht the php will understand..

for example:

Code: Select all

&lt;!--Put the actual script between the head-tags--&gt; 

&lt;SCRIPT LANGUAGE="JavaScript"&gt; 
//submitted to A1 javaScripts by Micke (mike.lindahl@telia.com) 
&lt;!-- 
function redirectPage() &#123; 
var url640x480 = "?res=1";   //put the url´s here 
var url800x600 = "?res=2"; 
var url1024x768 = "?res=3"; 
if ((screen.width == 640) &amp;&amp; (screen.height == 480)) 
window.location.href= url640x480; 
else if ((screen.width == 800) &amp;&amp; (screen.height == 600)) 
window.location.href= url800x600; 
else if ((screen.width == 1024) &amp;&amp; (screen.height == 768)) 
window.location.href= url1024x768; 
else window.location.href= url800x600; 
&#125; 
// --&gt; 
&lt;/SCRIPT&gt; 
&lt;/HEAD&gt; 
    
&lt;!--Put the event onload in the body-tag--&gt; 
&lt;BODY onload="redirectPage();"&gt;
*notice the links are set to ?res=1 ?res=2 ?res=3
*you can change these to index.php?res=1 or if its on a different page otherpage.php?res=1. But if the frameset is being loading on the same page you might want to leave it as ?res=1

Code: Select all

<?php 
      $res = $_REQUEST['res']; 
      if ( $res == "1" ) { 
          $variable=$condition;
      } elseif ( $link == "2" ) { 
            $variable=$condition;
      }elseif ( $link == "3" ) { 
          $variable=$condition;
     }else{ 
          $variable=$condition;
} ?>
I dont know how you are going to echo your frameset so I left it simply as $variable=$condition so you can set your parameters in there. Just make sure this is all before you are loading the frameset.

THats just off the top of my header. I will search for an easier method to check for resolutions and setting variables.. check back tommorow
spoon_watch
Forum Newbie
Posts: 3
Joined: Tue Feb 10, 2004 12:43 am

close but no cigar

Post by spoon_watch »

Thank you Phenom, you are a phenomenon of php coding.

I appreciate your enthusiasm in helping me.

Perhaps some enlightenment on the frameset code could be in order.

I hope this doesn't mess anything up but I'm going to post the section of code I'm using right now

<?php
require_once("master.php");
function index($id)
{
global $link, $sitename;
if(!isset($id))
{
echo "<html><head><title>$sitetitle</title></head><body>Error, No ID!</body></html>\n";
}
elseif(!isset($link[$id]))
{
echo "<html><head><title>$sitetitle</title></head><body>Error, Unknown ID!</body></html>\n";
}
else
{
echo "<FRAMESET ROWS=59,440 BORDER=0 FRAMEBORDER=0 FRAMESPACING=0><FRAME SRC=top.htm

MARGINHEIGHT=0 MARGINWIDTH=0 FRAMEBORDER=0 NORESIZE SCROLLING=no NAME=topframe>
<FRAME SRC=".$link[$id][address]." name=mainframe></FRAMESET>\n";
}
}
switch($op)
{
default:
index($id);
break;
}
?>
It may seem kind of complicated but the code stands as it is. No reformatting is necessary.

I want to be able to use an if statement to choose between three different sets of frame sizes and outputs.

Right now it only outputs the one size of frameset but I believe there is a way to make it choose first between the ID then between a $res or what not.

Marinate on that a little bit and bestow some knowledge on a newb.

Thanks again for your help guys, I'm learning alot.
Post Reply