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

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

GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

Well, i don't know what you are trying to show on your main page.. right now there is no where clause in your sql query, so basically if the items are not within your if statements (sectionids), everything is going to be printed.. and the only thing you are printing is empty TDs..

I would need to know what it is you want to show on your page.. including column names..
blade_922
Forum Contributor
Posts: 132
Joined: Wed Jul 12, 2006 4:57 pm

Post by blade_922 »

Ok here is the story cut short. The script im tryin to make is to determine what sectionid class to use. The css is for the title row of articles.

So if the article section is 18 then it will use the class contentheadingps3 in the css and if the sectionid is 1 in for the article it will use contentheading as the class.

Im not sure how to set this.

Regards
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

blade_922 wrote:Ok here is the story cut short. The script im tryin to make is to determine what sectionid class to use. The css is for the title row of articles.

So if the article section is 18 then it will use the class contentheadingps3 in the css and if the sectionid is 1 in for the article it will use contentheading as the class.

Im not sure how to set this.

Regards
Where are you determining what section ID it is?

I'm assuming you have another sql query along with this one? that is printing out the actual text of the section ID?
blade_922
Forum Contributor
Posts: 132
Joined: Wed Jul 12, 2006 4:57 pm

Post by blade_922 »

Ok you know what i actually just tried this

Code: Select all

<?php
$sql= mysql_query("Select * from mos_content"); 

 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%">'; 
     } 
 
?>
and think i almost got this.

This now just shows the small box blue image in the correct position. In one of the articles should appear a red box image which is the test article half way down the page. But that still shows a blue box, in other words using the contentheading class instead of contentheadingps3 class. What seems to be the problem here?
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

get rid of the single quotes around

Code: Select all

$sectionid=='1'
$sectionid=='18'
blade_922
Forum Contributor
Posts: 132
Joined: Wed Jul 12, 2006 4:57 pm

Post by blade_922 »

It still shows the blue box image where the red box image should be.

Do i need to set what $sectionid is? If so how? If not then what else could be wrong
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

blade_922 wrote:It still shows the blue box image where the red box image should be.

Do i need to set what $sectionid is? If so how? If not then what else could be wrong
Yes, you have to set sectionid...

Back to my previous question.. how are you determining what section id it is?

Are all your sections comming from your DB? meaning you already have a query that is printing out your sections.....
blade_922
Forum Contributor
Posts: 132
Joined: Wed Jul 12, 2006 4:57 pm

Post by blade_922 »

ok how do i set sectionid?

And to your question, yes the sectionid is in the mos_content table from the database. And yes ALL my sections are coming from the database
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

blade_922 wrote:ok how do i set sectionid?

And to your question, yes the sectionid is in the mos_content table from the database. And yes ALL my sections are coming from the database
So from that query (if you insist on doing two queries).. also get the section id and assign that to your variable, then you can do your if statements.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Will this help?

Code: Select all

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

while ($donnee = mysql_fetch_array($system)) 
{
    if ( 18 == $donnee['sectionid'] )
    {
        $css_append = 'ps3';
    }

    echo '<tr><td class="contentheading' . $css_append . $params->get('pageclass_sfx') . '" width="90%" >In the cell</td></tr>';
}
?>
blade_922
Forum Contributor
Posts: 132
Joined: Wed Jul 12, 2006 4:57 pm

Post by blade_922 »

Hi Everah, thats not quite what im looking for. Thanks anway.

K so my head is killing me now but im glad im almost done. How do i get the section id from database and assign it to the variable $sectionid?


Regards
blade_922
Forum Contributor
Posts: 132
Joined: Wed Jul 12, 2006 4:57 pm

Post by blade_922 »

Anybody respond to the above post please? This is like 95% done and answering the above post would help me complete this after this long.

Thanks
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

blade_922 wrote:How do i get the section id from database and assign it to the variable $sectionid?
If it is just one section id, select based on it then read the result into that var. If there are more than one, you read them into an array.

Code: Select all

<?php
/* Decalre this var here, though it may change */
$section_id = 0;

/* Query for the section id(s) */
/* To make this a single section id, use a WHERE `section_id` = something */
$system = mysql_query("select `section_id` from `my_table`") or die(mysql_error());

/* Check to see if there is a result */
if ($row_count = mysql_num_rows($system))
{
    /* There is, so lets do some assigning */
    /* But wait, is it one or many results? */
    if ($row_count > 1)
    {
        /* More than one, we need an array */
        unset($section_id);
        $section_id = array();
        while ($row = mysql_fetch_array($system))
        {
            $section_id[]['section_id'] = $row['section_id'];
        }
    }
    else
    {
        /* There is only one value, so set it */
        while ($row = mysql_fetch_array($system))
        {
            $section_id = $row['section_id'];
        }
    }
}
/**
 * At this point, section_id will either be set to an array
 * or to a single value based on the result returned by 
 * the OR
 *
 * section_id will be the default value, 0
 *
 */
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

38 minutes of patience.. nice.
blade_922
Forum Contributor
Posts: 132
Joined: Wed Jul 12, 2006 4:57 pm

Post by blade_922 »

lol 38 minutes? Look when i first posted this thread. :P :P :P

I think something in that code is causing a problem with the title and date and author not appearing in the articles now. Maybe its the $row? does that take a new row to display stuff?
Viewable: http://www.pspcave.com

Ok here is the full code.

Code: Select all

<?php


/* Decalre this var here, though it may change */ 
$sectionid = 0; 

/* Query for the section id(s) */ 
/* To make this a single section id, use a WHERE `sectionid` = something */ 
$system = mysql_query("select `sectionid` from `mos_content`") or die(mysql_error()); 

/* Check to see if there is a result */ 
if ($row_count = mysql_num_rows($system)) 
{ 
    /* There is, so lets do some assigning */ 
    /* But wait, is it one or many results? */ 
    if ($row_count > 1) 
    { 
        /* More than one, we need an array */ 
        unset($sectionid); 
        $sectionid = array(); 
        while ($row = mysql_fetch_array($system)) 
        { 
            $sectionid[]['sectionid'] = $row['sectionid']; 
        } 
    } 
    else 
    { 
        /* There is only one value, so set it */ 
        while ($row = mysql_fetch_array($system)) 
        { 
            $sectionid = $row['sectionid']; 
        } 
    } 
} 
/** 
 * At this point, section_id will either be set to an array 
 * or to a single value based on the result returned by 
 * the OR 
 * 
 * section_id will be the default value, 0 
 * 
 */ 


$sql= mysql_query("Select * from mos_content"); 


 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%">'; 
     } 
 
?>
Post Reply