Lifelesspeople.com

 Forum FAQsForum FAQs  Knowledge BaseKnowledge Base  RulesRules   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   HostingHosting   RegisterRegister 
 DonateDonate   WikiWiki   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

define within while

 
Lifelesspeople.com Forum Index -> Web Architects' Abode
Post new topic   Reply to topic View previous topic :: View next topic  
Author Message
Desbrina
Jadeite


Joined: 11 Jun 2005
Posts: 2985
Location: Earth

PostPosted: Sat Dec 08, 2007 9:47 am    Post subject: define within while Reply with quote

I have this code for setting how many images appear per line. Its fine for the first set out, but any after it stay the same

Code:
$i = 0; 
      while ($row = mysql_fetch_array($sql1)) {
      if (($row['type'] == "puzzle") and $row['amount'] == 15)
            define('CARDS_PER_ROW', 3);
      elseif ($row['amount'] == 5 || $row['amount'] == 10 || $row['amount'] == 15 || $row['amount'] == 20 || $row['amount'] == 25)
            define('CARDS_PER_ROW', 5);
      elseif ($row['amount'] == 4)
            define('CARDS_PER_ROW', 4);      
         echo "<img src=\"{$row['url']}\" alt=\"{$row['alttext']}\" /> " ;
         if (++$i % CARDS_PER_ROW == 0)
             echo '<br />';
      }
   }


Take for example this page
http://www.darknesswithin.com......er=Obi-Wan
Layout 1 appears fine, since theres 4 cards, but quigon doesn't. Theres 20 cards so it should be 5 per row

I'm not sure why its doing this, can anyone help
_________________
Midnight Tempest - A Sailor Moon TCG
Balanced Force - A Star Wars TCG
Caretaker - A Star Trek Voyager TCG
Back to top
 
nooc
Master Poster


Joined: 10 Aug 2005
Posts: 215


PostPosted: Sat Dec 08, 2007 2:47 pm    Post subject: Reply with quote

You can not redefine a constant.
Code:

// ..use something like..

function cards_per_row($row) { ... }

...

   if (++$i % cards_per_row($row) == 0) ...

...

// where cards_per_row() has some code that will return the correct number
Back to top
 
Desbrina
Jadeite


Joined: 11 Jun 2005
Posts: 2985
Location: Earth

PostPosted: Sat Dec 08, 2007 2:49 pm    Post subject: Reply with quote

i changed it to a variable, but i now have another problem with it

for some reason when switching from 4 to 5 per row, i end up with 4, 1 ,5

this is the new code
Code:
while ($row = mysql_fetch_array($sql1)) {
        if (($row['type'] == "puzzle") and $row['amount'] == 15)
               $perrow = 3;
        elseif ($row['amount'] == 5 || $row['amount'] == 10 || $row['amount'] == 15 || $row['amount'] == 20 || $row['amount'] == 25)
               $perrow = 5;
        elseif ($row['amount'] == 4)
               $perrow = 4;
            echo "<img src=\"{$row['url']}\" alt=\"{$row['alttext']}\" /> " ;
            print $perrow;
            if (++$i % $perrow == 0)
               echo '<br />';
        }

_________________
Midnight Tempest - A Sailor Moon TCG
Balanced Force - A Star Wars TCG
Caretaker - A Star Trek Voyager TCG
Back to top
 
Display posts from previous:   
Post new topic   Reply to topic    Lifelesspeople.com Forum Index -> Web Architects' Abode All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Home | Hosting | News | Forum | Links | System Status | About | Archive | Donate ]
Powered by phpBB © 2001, 2002 phpBB Group
All trademarks and copyrights on this page are owned by their respective owners. Posts and comments are owned by the poster. Everything else © 2001 - 2007 Lifelesspeople.com