Page 3 of 4

Posted: Thu Aug 31, 2006 7:16 pm
by RobertGonzalez
Before the second query, echo out $section_id. See what comes of it.

Posted: Thu Aug 31, 2006 7:18 pm
by feyd
blade_922 wrote:lol 38 minutes? Look when i first posted this thread.
When you first created the thread has little baring on what I said.

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:
[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.
I highly suggest you do not break that rule, or any others, in the near future.

Posted: Thu Aug 31, 2006 7:21 pm
by blade_922
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 this

Code: Select all

/* More than one, we need an array */ 
        unset($sectionid); 
 echo       $sectionid = array(); 
        while ($row = mysql_fetch_array($system)) 
        { 
            $sectionid[]['sectionid'] = $row['sectionid']; 
        } 
    } 
    else

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]

Posted: Thu Aug 31, 2006 7:33 pm
by RobertGonzalez
Ok, so the code is working. You just need to loop the $section_id array now.

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.

Posted: Thu Aug 31, 2006 7:37 pm
by blade_922
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?

Code: Select all

{ 
        /* More than one, we need an array */ 
        unset($sectionid); 
      $sectionid = array(); 
        while ($row = mysql_fetch_array($system)) 
        { 
            $sectionid[]['sectionid'] = $row['sectionid']; 
        } 
    }
And how do i set a loop on an array?

Regards

Posted: Thu Aug 31, 2006 7:45 pm
by RobertGonzalez
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...

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 />';
}
?>
Or some similar loop methodology. Try looking into the manual for arrays and such. I am sure that will be helpful.

Posted: Thu Aug 31, 2006 7:53 pm
by blade_922
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.

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

Posted: Thu Aug 31, 2006 8:13 pm
by RobertGonzalez
If all you want to do is see if the value of section_id (from the database) is equal to 18, do this...

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 */
    }
}
?>
EDIT | Sorry, closed a missing bracket

Posted: Thu Aug 31, 2006 8:24 pm
by GeXus
blade, can you paste the entire source code for your main page... it sounds like you have totally over complicated what your trying to achieve.

Posted: Fri Sep 01, 2006 2:15 am
by blade_922
Hi , K from what Everah said i did this

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

Posted: Fri Sep 01, 2006 2:19 am
by RobertGonzalez
There are 889 records being displayed. You want to do what with them?

Posted: Fri Sep 01, 2006 2:44 pm
by blade_922
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

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

Posted: Fri Sep 01, 2006 3:39 pm
by blade_922
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

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




?>
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

Posted: Sat Sep 02, 2006 6:58 pm
by RobertGonzalez
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%">'; 
}
?>

Posted: Sun Sep 03, 2006 11:36 am
by blade_922
Well, you know what im trying to do, because i have said it in the previous posts. Im not a hardcore programmer, rather quite the opposite thats what i asked here. So from what i said in the Posts of what im trying to do, does it match the code we have just now?

Regards