If....ElseIF....Else help!
Moderator: General Moderators
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..
I would need to know what it is you want to show on your page.. including column names..
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
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?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
I'm assuming you have another sql query along with this one? that is printing out the actual text of the section ID?
Ok you know what i actually just tried this
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?
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%">';
}
?>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?
get rid of the single quotes around
Code: Select all
$sectionid=='1'
$sectionid=='18'Yes, you have to set sectionid...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
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.....
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.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
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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>';
}
?>- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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.blade_922 wrote:How do i get the section id from database and assign it to the variable $sectionid?
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
*
*/
?>lol 38 minutes? Look when i first posted this thread.
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.
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%">';
}
?>