Old 05-05-2008, 05:07   #1 (permalink)
hollywooood
Registered User
 
Join Date: Jan 2008
Posts: 55
if and if else....

This may seem just like a replay from my last switch statement post but I have tried to apply the same principals to my coding. A bit of a back story--I run a small web design company in Bali Indonesia and until I am capable of programming these things myself I hired a programmer. Though the Indonesians are quite smart they seem to take some unnecessary steps to getting the job done. Here is some coding I am trying to figure out at the moment as to how to make it work in PHP5. It all works fine in 4 but not 5. I have a feeling that I need to use the $_GET in here somewhere but where?

Thanks for any help on this!

PHP Code:
<?php
div
('isinya');
if(
$page=="")
$page="Home";
//====================== home and who are we ???
if($page=="Home" || $page=="Who are we")
    {
    
$dpt=mysql_query("select * from fnf_content
    where fnftitle='$page' and fnftype ='page'
    order by fnftitle"
);
    while(
$baris=mysql_fetch_array($dpt))
        {
        
$isi=$baris[fnfcontent];
        
$pic=substr($isi,0,strpos($isi,"|"));
        
$text=substr($isi,strpos($isi,"|")+1);
        if(
$page=="Home")
            {
            
div('home');
            
ee("<img src=\"img/upload/".$pic."\" border=\"0px\" alt=\"".$baris[fnftitle]."\">");
            
div();
            }
        elseif(
$page=="Who are we")
            {
        
div('page_pic');
        
ee("<img src=\"img/upload/".$pic."\" border=\"0px\" alt=\"".$baris[fnftitle]."\">");
        
div();
        
div('page_text');
        
ee($text);
            }
        
div();
        }
    }
//====================== product
elseif($page=="Product")
    {
    
div('product');
        
div('select_type');
        
$shirt=="Man" ?    to('','Man'):to("?page=$page&shirt=Man",'Man');
        
ee('&nbsp;|&nbsp;');
        
$shirt=="Ladies" ?    to('','Ladies'):to("?page=$page&shirt=Ladies",'Ladies');
        
ee('&nbsp;|&nbsp;');
        
$shirt=="Toddler" ?    to('','Toddler'):to("?page=$page&shirt=Toddler",'Toddler');
        
ee('&nbsp;|&nbsp;');
        
$shirt=="Hat" ?    to('','Hat'):to("?page=$page&shirt=Hat",'Hat');
        
div();
        
$dpt=mysql_query("select * from fnf_content
        where fnftype='product' and fnfcategory='$shirt' and fnfstatus='Publish'
        order by fnftitle"
);
        while(
$baris=mysql_fetch_array($dpt))
            {
            
$isi=$baris[fnfcontent];
            
$pic[]=substr($isi,0,strpos($isi,"|"));
            
$text[]=substr($isi,strpos($isi,"|")+1);
            }
        
$jml=sizeof($pic);
        
$pro=="" $pro=$pro=$pro;
        
//== count for page
        
if($jml>2)
            {
            
$next=$pro+2;
            
$back=$pro-2;
            if(
$next<$jml)
                
$maju="<a href=\"?page=$page&shirt=$shirt&pro=$next\">Next</a>";
            else
                
$maju="Next";
            if(
$back>=0)
                
$mundur="<a href=\"?page=$page&shirt=$shirt&pro=$back\">Back</a>";
            else
                
$mundur="Back";
            }        
        if (
$jml=="0")
            {
            
div('gbrsatu');
            
ee('<br /><br /><br />We currently have no product for this category<br /><br />Visit us soon...');
            
div();
            }
        else
            {
            
//== echo pos 1 for content
            
div('gbrsatu');
            if(
$pic[$pro]=="")
                
$gbr="";
            else
                
ee("<img src=\"img/upload/$pic[$pro]\" border=\"0px\" alt=\"$text[$pro]\">");
            
div();
            
div('textsatu');
            
ee($text[$pro]);
            
div();
            
//== echo pos 2 for content
            
$y=$pro+1;
            
div('gbrdua');
            if(
$pic[$y]=="")
                
$gbr="";
            else
            
ee("<img src=\"img/upload/$pic[$y]\" border=\"0px\" alt=\"$text[$y]\">");
            
div();
            if(
$shirt=="Hat")
                {
                
div('textsatu');
                
div();
                }
            
div('textdua');
            
ee($text[$y]);
            
div();
            }
    
//== echo page
    
if ($jml>2)
        {
        
div('next_back');
        
ee("&laquo; ".$mundur." | ".$maju." &raquo;");
        
div();
        }
    
div();
    }
//====================== display form
elseif($page=="Contact us")
    include 
"adon/contact.php";
//====================== newsletter
elseif($page=="Newsletter")
    {
    
$dpt=mysql_query("select * from fnf_content
    where fnftype='newsletter' and fnfstatus='Publish'
    order by fnfdate asc"
);
    while(
$baris=mysql_fetch_array($dpt))
        {
        
$idn[]=$baris[ID];
        
$jdl[]=$baris[fnftitle];
        
$tgl[]=$baris[fnfdate];
        
$isi=$baris[fnfcontent];
        
$pic[]=substr($isi,0,strpos($isi,"|"));
        
$text[]=substr($isi,strpos($isi,"|")+1);
        }
    
$jml=sizeof($pic);
    
div('news_letter');//== start div newsletter
    
if($idn[0]=="")
    
ee('we currently have no news...<br /> comming soon...');
        
ee("<a name=\"top_news\"></a>");//== bookmark newsletter
        
div('menuisinews');//== start div menu news
            
ee('<hr />');
        for (
$i=$i<$jml $i++)
            {
            
to("?page=Newsletter#$idn[$i]","$jdl[$i]");
            
ee('<br />'.$tgl[$i]);
            
ee('<hr />');
            }
        
div();
        for (
$i=$i<$jml $i++)
            {
            if(
$pic[$i]=="")
                
$gbr="";
            else
                
$gbr="<img src=\"img/upload/$pic[$i]\" border=\"0px\" alt=\"$jdl[$i]\">";
            
div('title_news');//==title
                
ee("<a name=\"$idn[$i]\"></a>".$jdl[$i]);
            
div();
            
div('date_news');//==date
                
ee($tgl[$i]);
            
div();
            
div('gbr');//==image
                
ee($gbr);
            
div();
            
div('content_news');//==text
                
ee($text[$i]);
            
div();
            
div('backtotopp');
                
to("?page=Newsletter#top_news","Back to top");
                
ee('<hr />');
            
div();
            }
    
div();
    }
div();
?>

Last edited by hollywooood : 06-05-2008 at 02:17.
  Reply With Quote
Old 05-05-2008, 06:23   #2 (permalink)
hollywooood
Registered User
 
Join Date: Jan 2008
Posts: 55
This may help too....it's the menu include file.

PHP Code:
<?php
$page
=="Home"?$phome="homec.jpg":$phome="dot.gif";
$page=="Product"?$pprod="prodc.jpg":$pprod="dot.gif";
$page=="Contact us"?$pconus="conusc.jpg":$pconus="dot.gif";
$page=="Newsletter"?$pnews="newsc.jpg":$pnews="dot.gif";
$page=="Who are we"?$pwho="whoc.jpg":$pwho="dot.gif";
//====================== menu
?>
    <div id="menusamping">
        <div id="home"><a href="?page=Home">
        <img src="img/<?php echo $phome;?>" border="0px" width="96px" height="29px" /></a></div>
        <div id="prod"><a href="?page=Product&shirt=Man">
        <img src="img/<?php echo $pprod;?>" border="0px" width="103px" height="26px" /></a></div>
        <div id="conus"><a href="?page=Contact us">
        <img src="img/<?php echo $pconus;?>" border="0px" width="118px" height="24px" /></a></div>
        <div id="news"><a href="?page=Newsletter">
        <img src="img/<?php echo $pnews;?>" border="0px" width="118px" height="24px" /></a></div>
        <div id="who"><a href="?page=Who are we">
        <img src="img/<?php echo $pwho;?>" border="0px" width="138px" height="28px" /></a></div>
    </div>

Last edited by hollywooood : 06-05-2008 at 02:16.
  Reply With Quote
Old 05-05-2008, 07:15   #3 (permalink)
freelancr
Web Developer
 
freelancr's Avatar
 
Join Date: Oct 2006
Location: Stratford-upon-Avon, Warwickshire, UK
Posts: 1,848
Send a message via MSN to freelancr Send a message via Skype™ to freelancr
The reason this code, and that in your previous post, works in php4 and not in php5 is because of a setting called [ PHP: Using Register Globals - Manual ] If you click that link and read that page it will tell you in plain english what you need to be looking out for to get your code to work in PHP4.

By default PHP4 used to have register_globals default to being on, so this "lazy code" would work. In PHP5, the default value is off, and in php6, you cannot use it at all.

A little tip, when posting code into the forum... use the following tags around it to preserve any indentation, makes it far easier to read. [code ] // PHP [/code ] (without the spaces before the last bracket)
__________________
  Reply With Quote
Old 05-05-2008, 10:05   #4 (permalink)
hollywooood
Registered User
 
Join Date: Jan 2008
Posts: 55
I can't thank you enough! Good luck on your Zend exam! Sounds like your going to kill it!
  Reply With Quote
Old 05-05-2008, 10:36   #5 (permalink)
pgo
Moderator
 
pgo's Avatar
 
Join Date: Jan 2005
Location: Brooklyn, NYC
Posts: 11,869
Quote:
Originally Posted by freelancr
A little tip, when posting code into the forum... use the following tags around it to preserve any indentation, makes it far easier to read. [code ] // PHP [/code ] (without the spaces before the last bracket)
Actually, [php ] [/php ] will syntax-highlight PHP as will [html ] [/html ]
__________________
  Reply With Quote
Old 05-05-2008, 15:02   #6 (permalink)
freelancr
Web Developer
 
freelancr's Avatar
 
Join Date: Oct 2006
Location: Stratford-upon-Avon, Warwickshire, UK
Posts: 1,848
Send a message via MSN to freelancr Send a message via Skype™ to freelancr
Quote:
Originally Posted by pgo
Actually, [php ] [/php ] will syntax-highlight PHP as will [html ] [/html ]

learn something new every day
__________________
  Reply With Quote
Old 05-05-2008, 15:04   #7 (permalink)
pgo
Moderator
 
pgo's Avatar
 
Join Date: Jan 2005
Location: Brooklyn, NYC
Posts: 11,869
Now all we need is [js ] and [/js ]
__________________
  Reply With Quote
Old 06-05-2008, 02:15   #8 (permalink)
hollywooood
Registered User
 
Join Date: Jan 2008
Posts: 55
Appreciate the good info and will continue to grow as a programmer unless my head pops off first. I am still unable to wrap my mind around the code that has been written and what I need to do to make it work for PHP5. Until then I used this little piece of code in my .htaccess
PHP Code:
php_flag register_globals on 
Hopefully by the time PHP6 is in full effect I'll understand this better and can make the changes with more ease. Thanks again for all the great feedback, you guys are awesome!!!!

Will
  Reply With Quote
Old 06-05-2008, 11:23   #9 (permalink)
Hunch
Grumpy old man
 
Hunch's Avatar
 
Join Date: Oct 2007
Location: North Japan
Posts: 1,128
Let me just quote from the PHP Manual on register globals:

Quote:
WARNING
This feature has been DEPRECATED in PHP 5 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged.

I'd recommend you look for another solution such as modifying your code (since it's hardly a stretch to do it).
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8