If....ElseIF....Else help!
Moderator: General Moderators
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
When you first created the thread has little baring on what I said.blade_922 wrote:lol 38 minutes? Look when i first posted this thread.
Take a look at your previous post times: Aug 31st, 2006 06:12:23pm and Aug 31st, 2006 06:50:02pm. Well, that's 38 minutes apart.
The latter post added no value to the previous post or this thread therefore it is generally classified as a bump. Which then falls under the following rule:
I highly suggest you do not break that rule, or any others, in the near future.[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:4. All users of any level are restricted to bumping (as defined here) any given thread within twenty-four (24) hours of its last post. Non-trivial posts are not considered bumping. A bump post found in violation will be deleted, and you may or may not recieve a warning. Persons bumping excessively be considered as spammers and dealt with accordingly.
Everah | Please use
Put in an Echo there?
EDIT: oh i see you want me to put echo $sectionid; just before i do the $sql query. I did that and it just says Array beside each article at the top.
Everah | 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]
you mean do thisCode: Select all
/* More than one, we need an array */
unset($sectionid);
echo $sectionid = array();
while ($row = mysql_fetch_array($system))
{
$sectionid[]['sectionid'] = $row['sectionid'];
}
}
elsePut in an Echo there?
EDIT: oh i see you want me to put echo $sectionid; just before i do the $sql query. I did that and it just says Array beside each article at the top.
Everah | 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]- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Ok, so the code is working. You just need to loop the $section_id array now.
Also, you may wan to seriously consider using
Also, you may wan to seriously consider using
Code: Select all
tags when posting PHP. Seeing code in plain text is really unnerving and hard to read.Sorry about that, i thought i used the php tags previously. Sorry i must have forgot.
K so i need to loop the array, which part of the code exactly do i loop
This bit?
And how do i set a loop on an array?
Regards
K so i need to loop the array, which part of the code exactly do i loop
This bit?
Code: Select all
{
/* More than one, we need an array */
unset($sectionid);
$sectionid = array();
while ($row = mysql_fetch_array($system))
{
$sectionid[]['sectionid'] = $row['sectionid'];
}
}Regards
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Before I get too confused, clarify again what it is you want to achieve. To point you in the right direction, you are going to need to loop the $section_id array, using either a foreach loop or for loop...
Or some similar loop methodology. Try looking into the manual for arrays and such. I am sure that will be helpful.
Code: Select all
<?php
foreach ($section_id as $value)
{
echo 'This section id is ' . $value . '!<br /><br />';
}
/* Or, to use a for loop */
$section_id_count = count($section_id);
for ($i = 0; $i < $section_id_count; $i++)
{
echo 'This section id is ' . $section_id[$i]['section_id'] . '!<br /><br />';
}
?>Ok what i am trying to acheive is to determine which row of code to use depending on the sectionid of the article. That way i can set different class's for different sectionid's.
So correct me if im wrong this time but will that code above work for me in this case? Im not actually trying to echo out the sectionid. I just want it to get the sectionid from the database so the next bit of code can see if sectionid==18 and if it does then echo "this code".
Here is all the code so far excludinf the loop above. So you can see if there is a simpler way.
See i was told in the bottom code that it needs to read what $sectionid is assigned to in database and in code.
See if there is a simpler way than all the code you gave me.
Regards
So correct me if im wrong this time but will that code above work for me in this case? Im not actually trying to echo out the sectionid. I just want it to get the sectionid from the database so the next bit of code can see if sectionid==18 and if it does then echo "this code".
Here is all the code so far excludinf the loop above. So you can see if there is a simpler way.
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%">';
}
?>See i was told in the bottom code that it needs to read what $sectionid is assigned to in database and in code.
See if there is a simpler way than all the code you gave me.
Regards
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
If all you want to do is see if the value of section_id (from the database) is equal to 18, do this...
EDIT | Sorry, closed a missing bracket
Code: Select all
<?php
$system = mysql_query("select * from mos_content") or die(mysql_error());
while ($donnee = mysql_fetch_array($system))
{
if ( 18 == $donnee['sectionid'] )
{
/* Do what you want in here if section id is 18 */
}
else
{
/* Otherwise, do something else in here */
}
}
?>Hi , K from what Everah said i did this
But that ends up displaying hundreds of small images which are set in class. Like Gexus said previously it shows the number of articles as image. Like if there is 899 articles it will display 899 small blue and red boxes going across the page instead of just 1.
How would this be sorted?
Also Gexus there is no point in posting the ENTIRE source code. The Source Code is HUGE on that page.[/url]
Code: Select all
<?php
$system = mysql_query("select * from mos_content") or die(mysql_error());
while ($donnee = mysql_fetch_array($system))
{
if ( 1 == $donnee['sectionid'] )
{
echo '<td class="contentheading' . $params->get('pageclass_sfx') . '" width="90%" >';
}
else
{
echo '<td class="contentheadingps3' . $params->get('pageclass_sfx') . '" width="90%">';
}
}
?>How would this be sorted?
Also Gexus there is no point in posting the ENTIRE source code. The Source Code is HUGE on that page.[/url]
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Hi i dont want to do anything with the records.
See the code we have in the css is to display a small image. And the PHP determines which css to use which determines which image will be used.
The code somehow malfunctions and calculates which css to use on every article and displays that in each article. So it displays the image for article 1,2,3,4,5,6,7,8,9..... etc up to the number of articles in each article. So if theres 1000 articles it displays 1000 images each time.
How can i make it stop from doing this?
here is the code i have just now
See the code we have in the css is to display a small image. And the PHP determines which css to use which determines which image will be used.
The code somehow malfunctions and calculates which css to use on every article and displays that in each article. So it displays the image for article 1,2,3,4,5,6,7,8,9..... etc up to the number of articles in each article. So if theres 1000 articles it displays 1000 images each time.
How can i make it stop from doing this?
here is the code i have just now
Code: Select all
<?php
$system = mysql_query("select * from mos_content") or die(mysql_error());
$donnee = mysql_fetch_array($system);
if ( 1 == $donnee['sectionid'] )
{
echo '<td class="contentheading' . $params->get('pageclass_sfx') . '" width="90%" >';
}
else
{
echo '<td class="contentheadingps3' . $params->get('pageclass_sfx') . '" width="90%">';
}
?>Hi ok im 95% there i managed to sort the multiple class image showing.
Ok now the problem is, is that the IF doesnt work but the Else does.
here is current latest code
Ok that is the code. See i actually have 2 categories if its not 1 then its 18 so all sectionid that =18 would use the class contentheadingps3. But instead it uses contentheadingps3 for all the articles instead of only the ones with sectionid=18.
The section is stated in the mysql database. So somehow its not reading the IF anyone know a fix?
Regards
Ok now the problem is, is that the IF doesnt work but the Else does.
here is current latest code
Code: Select all
<?php
$system=mysql_query("select * from mos_content") or die(mysql_error());
while ($donnee = mysql_fetch_array($system))
{ $donnee= $donnee['sectionid']; }
for ($i=1; $i<=1; $i++)
{
if ( 1==$donnee['sectionid'] )
echo '<td class="contentheading' . $params->get('pageclass_sfx') . '" width="90%" >';
else
echo '<td class="contentheadingps3' . $params->get('pageclass_sfx') . '" width="90%">';
}
?>The section is stated in the mysql database. So somehow its not reading the IF anyone know a fix?
Regards
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Here is your code with comments. Is this really what you want to do?
Code: Select all
<?php
/* Set the var $system equal to the resource ID of this query */
$system=mysql_query("select * from mos_content") or die(mysql_error());
/* Regardless of how many records there are in the result */
/* use the last record in the result */
while ($donnee = mysql_fetch_array($system))
{ $donnee= $donnee['sectionid']; }
/* Run a single iteration (one loop) */
for ($i=1; $i<=1; $i++)
{
/* See if the value of this non-existent array var is 1 */
if ( 1==$donnee['sectionid'] )
echo '<td class="contentheading' . $params->get('pageclass_sfx') . '" width="90%" >';
else
/* This line will always display because of the way your code runs */
echo '<td class="contentheadingps3' . $params->get('pageclass_sfx') . '" width="90%">';
}
?>