Reply
php conditional statements
Old 01-30-2005, 12:37 PM php conditional statements
Novice Talker

Posts: 9
I am using an embeded php function (cutenews infact) with a conditional statement to change some variables, and i was wondering if you saw anything wrong with my script. I am trying to make it so category 2 has the template photos and category 3 has the template footage.

PHP Code:
<?PHP
$category 
"2,3";
if (
$category==2)
(
$template"photos");
else 
(
$template"footage");

$number "6";
include(
"cutenews/show_news.php");
?>
I already tried to get an answer to this in the cutenews forums (cutephp.com) but it didnt work out, and yall seem to know much more about php.
firago is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 01-30-2005, 01:11 PM
Logical Program's Avatar
Super Talker

Posts: 130
Location: Atlanta, Georgia
Hrmm... I'm not sure about the variable $category = "2,3", but you have the structure for the conditional statement wrong, and the comparison must be quoted unless it's another variable...

PHP Code:
<?PHP

$category 
"2,3"
if (
$category == '2'){ 
    
$template"photos"
} else { 
    
$template"footage"
}

$number "6"
include(
"cutenews/show_news.php"); 

?>
__________________
Logical Programming - For all of your website programming and design needs, make the logical choice. Logical Assistance For Real-World Clients.
Logical Program is offline
Reply With Quote
View Public Profile Visit Logical Program's homepage!
 
Old 01-30-2005, 02:52 PM
ACJavascript's Avatar
Humble Mod

Posts: 548
Location: CT, USA
Hey,

Well Logical is right, since $catagory is holding "2,3" as text you need to check it as a text variable.

But the check is wrong becuase $catagory equals "2,3"

So you have it like this:
if($catagory=="2"){ //But $catagory equals "2,3"


So this is what I suggest doing.

PHP Code:

$catagory
="2,3";

$new_cat=explode(",",$catagory);
foreach(
$new_cat AS $cat_id){
if(
$cat_id=="1"){
   
$template"photos"
}else{
  
$template="footage";
}
}


$number "6"
include(
"cutenews/show_news.php"); 

?> 
I havn't tested the above script so heres hoping it works
__________________
CYTech-services.com - 100 Satisfied Customers - Custom Programming and Web Development
ACJavascript is offline
Reply With Quote
View Public Profile Visit ACJavascript's homepage!
 
Old 01-30-2005, 07:30 PM
Novice Talker

Posts: 9
i get one of these messages when i do that.

Parse error: parse error, unexpected $ in /home/canssite/public_html/cpskate/index.php on line 104
firago is offline
Reply With Quote
View Public Profile
 
Old 01-30-2005, 07:33 PM
Novice Talker

Posts: 9
Logical program, your script works, except that category 2 has the template footage. category 3 also has the template footage.

Last edited by firago : 01-30-2005 at 07:39 PM.
firago is offline
Reply With Quote
View Public Profile
 
Old 01-30-2005, 07:33 PM
ACJavascript's Avatar
Humble Mod

Posts: 548
Location: CT, USA
104. Could you please post the whole code.
__________________
CYTech-services.com - 100 Satisfied Customers - Custom Programming and Web Development
ACJavascript is offline
Reply With Quote
View Public Profile Visit ACJavascript's homepage!
 
Old 01-30-2005, 07:41 PM
Novice Talker

Posts: 9
here is the whole code using logical program's code

PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>CPSkate</title>
<style type="text/css">
<!--

.news {
    font-family: Arial;
    font-size: 12px;
    font-color: #000000;
}

a {    
    font-color: #000000;
    text-decoration: none;
}

-->
</style>
</head>

<body bgcolor="FFFFFF">

<div align="center"><img src="images/cpskate_header.gif" alt="CPSkate" width="776" height="49" /></div>

<table width="776" align="center" cellpadding="0" cellspacing="0" bgcolor="#999999" style="border-left: 2px solid #000000; border-bottom: 2px solid #000000; border-right: 2px solid #000000; border-top: 0px solid #000000;">
      <tr>      
        <td bgcolor="#999999"><img src="images/side_spacer.gif" alt="" width="15" height="5" /></td>        
        <td bgcolor="#FFFFFF"><img src="images/news_header.gif" alt="" width="360" height="19" border="0" usemap="#Map1" /></td>

        <td bgcolor="#999999"><img src="images/center_spacer.gif" alt="" width="22" height="5" /></td>
        <td bgcolor="#FFFFFF"><img src="images/media_header.gif" alt="" width="360" height="19" border="0" usemap="#Map2" /></td>
        <td bgcolor="#999999"><img src="images/side_spacer.gif" alt="" width="15" height="5" /></td>
      </tr>
      
      <tr>
        <td bgcolor="#999999"></td>
        
        <td valign="top" bgcolor="999999" cellpadding="0" cellspacing="0" border="0">
        <table bgcolor="FFFFFF" cellpadding="0" cellspacing="0" width="360" style="border-left: 1px solid #000000; border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 0px solid #000000;">
          <tr>

            <td>
        <img src="images/white_horiz_break.gif" alt="" width="358" height="10" /><br />
<?PHP
$category 
"5";
$number "6";
include(
"cutenews/show_news.php");
?>
        </td>
          </tr>
        </table>
                        
        <td bgcolor="#999999"></td>
        
        <td valign="top" bgcolor="999999" cellpadding="0" cellspacing="0" border="0">
        <table bgcolor="FFFFFF" cellpadding="0" cellspacing="0" width="360" style="border-left: 1px solid #000000; border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 0px solid #000000;">
          <tr>
            <td>
        <img src="images/white_horiz_break.gif" alt="" width="358" height="10" /><br />
<?PHP

$category 
"2,3";
if (
$category == '2'){
    
$template"photos";
} else {
    
$template"footage";
}

$number "6";
include(
"cutenews/show_news.php");

?> 
        </td>
          </tr>
        </table>
                
        <td bgcolor="#999999"></td>    
      </tr>
      
      <tr>      
        <td bgcolor="#999999"></td>        
        <td bgcolor="#999999"><img src="images/bottom_spacer.gif" alt="" width="360" height="6" border="0" /></td>
        <td bgcolor="#999999"></td>
        <td bgcolor="#999999"><img src="images/bottom_spacer.gif" alt="" width="360" height="6" border="0" /></td>
        <td bgcolor="#999999"></td>

      </tr>
</table>
<br /> 

<map name="Map1" id="Map1">
  <area shape="rect" coords="0,0,19,10" href="allnews.php" />
</map>
<map name="Map2" id="Map2">
  <area shape="rect" coords="341,0,360,10" href="http://cpskate.canssite.com" />
  <area shape="rect" coords="0,0,37,10" href="http://cpskate.canssite.com/allmedia.php" />
</map>
</body>
</html>
The second php script is the one that is acting up.
firago is offline
Reply With Quote
View Public Profile
 
Old 01-30-2005, 08:20 PM
Logical Program's Avatar
Super Talker

Posts: 130
Location: Atlanta, Georgia
Could you provide a more in-depth detail if what you're trying to do?

If blah, then have footage, etc... That would help a bit more.
__________________
Logical Programming - For all of your website programming and design needs, make the logical choice. Logical Assistance For Real-World Clients.

Last edited by Logical Program : 01-30-2005 at 08:23 PM.
Logical Program is offline
Reply With Quote
View Public Profile Visit Logical Program's homepage!
 
Old 01-30-2005, 10:17 PM
Novice Talker

Posts: 9
I am using cutenews (a php aplication) and the template for the posts with the category of 2 should be photos. And the template for the posts with the category 3 should be photo.

Is that better?
firago is offline
Reply With Quote
View Public Profile
 
Old 01-30-2005, 10:30 PM
Logical Program's Avatar
Super Talker

Posts: 130
Location: Atlanta, Georgia
From what I understand, this should be the solution.

if ($category == '2'){
$template= "photos";
} elseif ($category == '3') {
$template= "footage";
} else {}
__________________
Logical Programming - For all of your website programming and design needs, make the logical choice. Logical Assistance For Real-World Clients.
Logical Program is offline
Reply With Quote
View Public Profile Visit Logical Program's homepage!
 
Old 01-31-2005, 12:10 AM
Novice Talker

Posts: 9
nice try but no cigar. now all of the posts are the default
firago is offline
Reply With Quote
View Public Profile
 
Old 01-31-2005, 12:26 AM
Logical Program's Avatar
Super Talker

Posts: 130
Location: Atlanta, Georgia
The phrase 'From what I understand..." means confusion. (need clarification) *cough*
__________________
Logical Programming - For all of your website programming and design needs, make the logical choice. Logical Assistance For Real-World Clients.
Logical Program is offline
Reply With Quote
View Public Profile Visit Logical Program's homepage!
 
Old 01-31-2005, 08:16 AM
ACJavascript's Avatar
Humble Mod

Posts: 548
Location: CT, USA
I noticed in your "full" script that $catagory is called twice.

The second time, it has a value of 2,3.

What does that mean?

Does that mean show template 2 (photos) then show 3?
Or only show 2 and not 3?
Or only show 3 and not 2?

Trying to just clarify everything
__________________
CYTech-services.com - 100 Satisfied Customers - Custom Programming and Web Development
ACJavascript is offline
Reply With Quote
View Public Profile Visit ACJavascript's homepage!
 
Old 01-31-2005, 06:57 PM
Novice Talker

Posts: 9
This what i have currently marked with a number on the coralating description of what each function is supposed to do

<?PHP

$category = "2,3"; <<1.>>

if ($category == '2'){ <<2.>>
$template= "photos";
} else {
$template= "footage";
}

$number = "6"; <<3.>>

include("cutenews/show_news.php"); <<4.>>

?>


<<1.>> This tells it which categories to include
<<2.>> This tells it to use template photos on the posts marked with the category 2 and use template footage on the posts marked with the category 3
<<3.>> This tells it the number of posts to include
<<4.>> This tells it where the actuall raw newsfeed is

I hope that helps
firago is offline
Reply With Quote
View Public Profile
 
Old 01-31-2005, 07:05 PM
madness's Avatar
Average Talker

Posts: 22
Hi,

u can link to this page for example ((demo.php?category=2))

and place the code

<?PHP
if ($category=2){
($template= "photos");
}else{
($template= "footage");

$number = "6";
include("cutenews/show_news.php");
?>
madness is offline
Reply With Quote
View Public Profile
 
Old 01-31-2005, 07:32 PM
Novice Talker

Posts: 9
i got a
"Parse error: parse error, unexpected $ in /home/canssite/public_html/cpskate/media.php on line 99"
firago is offline
Reply With Quote
View Public Profile
 
Old 01-31-2005, 08:08 PM
Novice Talker

Posts: 9
the url of the page is http://cpskate.canssite.com/media.php
firago is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to php conditional statements
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Webmaster Resources Marketplace:
Software Development Company | Webhosting.UK.com | Text Link Brokers 


   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.68249 seconds with 12 queries