Page 1 of 4

If....ElseIF....Else help!

Posted: Sat Aug 19, 2006 6:33 pm
by blade_922
Hey guys. Im having some trouble. First here is the error.

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/gtcave/public_html/pspcave/components/com_content/content.html.php


Basically i want it to check the section id and if its a certain section i want it to print the code. Like if sectionid=1 i want it to use a different css class and if sectionid=18 i want it to use a different css class.

And the script...

Code: Select all

<?php 


$system=mysql_query("select * from mos_content") or die(mysql_error());
while ($donnee = mysql_fetch_array($system))
{  $sectionid=$donnee['sectionid']; }

if ( $sectionid='1')
{
echo "<td class="contentheading<?php echo $params->get( 'pageclass_sfx' ); ?>" width="90%" >";
}
elseif ( $sectionid='18')
{
echo "<td class="contentheadingps3<?php echo $params->get( 'pageclass_sfx' ); ?>" width="90%">";
}
else
{
echo "<td class="contentheading<?php echo $params->get( 'pageclass_sfx' ); ?>" width="90%">";
}

?>
Please someone spot the dumb mistake i have made and cannot see. Thanks

Posted: Sat Aug 19, 2006 6:38 pm
by bokehman
Nested echos and php tags.

Posted: Sat Aug 19, 2006 6:39 pm
by feyd
And quote nightmares. :)

Posted: Sat Aug 19, 2006 6:40 pm
by blade_922
lol ok i will unest the echo's but what about quotes nightmare? whats up with them?


Regards

Posted: Sat Aug 19, 2006 6:42 pm
by feyd
Have a careful read through: http://php.net/language.types.string

Posted: Sat Aug 19, 2006 6:42 pm
by Benjamin

Code: Select all

<?php
$system = mysql_query("select * from mos_content") or die(mysql_error());

while ($donnee = mysql_fetch_array($system)) {
    $sectionid = $donnee['sectionid'];
     if ( $sectionid='1')
     {
        echo '<td class="contentheading' . $params->get('pageclass_sfx') . '" width="90%" >';
     }
     elseif ( $sectionid='18')
     {
        echo '<td class="contentheadingps3' . $params->get('pageclass_sfx') . '" width="90%">';
     } else {
        echo '<td class="contentheading' . $params->get('pageclass_sfx') . '" width="90%">';
     }
}
?>

Posted: Sat Aug 19, 2006 7:12 pm
by blade_922
ok hey about that solution above by astions.

See first it just used to say

Code: Select all

<td class="contentheading<?php echo $params->get( 'pageclass_sfx' ); ?>" width="90%">"
Then i made the php code to determine what class to use. The code actually ends up showing a small 30x30 image which is displayed next to article titles. before it just used to show one image, but with Astions solution it makes the page 3 times wider and the images show itself like 1000 times now...

any solution.

Posted: Sat Aug 19, 2006 7:31 pm
by feyd
= vs ==.
assignment vs equality.

Posted: Sat Aug 19, 2006 7:35 pm
by blade_922
i changed the sectionid= to sectionid== and still no hope

Posted: Sun Aug 20, 2006 5:28 am
by Benjamin
Your not echo'ing rows. Your only echo'ing columns. You need some <tr>'s in there I imagine. All I did was clean up and fix your code. I didn't change it at all. As feyd said, you also need == in comparison operations, otherwise your just assigning the value to the variable, not comparing it.

Posted: Thu Aug 31, 2006 4:07 pm
by blade_922
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi there, Im STILL at this would you believe. I really need to get this working, so if you can help that would be grateful!

Here is the current code. Which may still be wrong.

Code: Select all

<?php 
$system = mysql_query("select * from mos_content") or die(mysql_error()); 

while ($donnee = mysql_fetch_array($system)) { 
    $sectionid = $donnee['sectionid']; 
     if ( $sectionid=='1') 
     { 
        echo '<tr><td class="contentheading' . $params->get('pageclass_sfx') . '" width="90%" ></tr>'; 
     } 
     elseif ( $sectionid=='18') 
     { 
        echo '<tr><td class="contentheadingps3' . $params->get('pageclass_sfx') . '" width="90%"></tr>'; 
     } else { 
        echo '<tr><td class="contentheading' . $params->get('pageclass_sfx') . '" width="90%"></tr>'; 
     } 
} 
?>

Here is the css code for it to choose what css class to use.

Code: Select all

.contentheading {
	height: 30px;
	background: url(../images/contenthead.jpg) top left repeat-x;
                color: #0033FF;
	text-indent: 15px;
	font-weight: bold;
	font-size: 15px;
}


.contentheadingps3 {
	height: 30px;
	background: url(../images/contentheadps3.jpg) top left repeat-x;
	color: #0033FF;
	text-indent: 15px;
	font-weight: bold;
	font-size: 15px;
}

But now take a look here http://www.pspcave.com and look at the blue images going down the page there, should only be one.

(Can somone help asap as i cant leave the site like this for too long so i can revert to the previous code which is
<td class="contentheading<?php echo $params->get( 'pageclass_sfx' ); ?>" width="90%"> and that usually worked before but i need the advanced code above working as its different.)


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu Aug 31, 2006 4:16 pm
by GeXus
Can you do this

Code: Select all

select count(*) from mos_content
(im assuming that the page you listed, should not be using a sectionid, if it should.. then do the count * where = to that section id.

How many results do you have?

Posted: Thu Aug 31, 2006 4:42 pm
by blade_922
Theres 898 records at the moment. Why would ya need to know that?

Regards

Posted: Thu Aug 31, 2006 4:54 pm
by GeXus
Well, thats how many square bullets you have being printed out... minus what has sectionid 1 and 18.

Posted: Thu Aug 31, 2006 5:03 pm
by blade_922
oh ok, why does that happen? And how would i solve this problem? I take it you see what im trying to do here? Please help me find a solution, i need to finish this in the next few hours.

Regards