| Author |
Message |
Desbrina Jadeite

Joined: 11 Jun 2005 Posts: 2985 Location: Earth
|
Posted: Sat Dec 08, 2007 9:47 am Post subject: define within while |
|
|
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
|
Posted: Sat Dec 08, 2007 2:47 pm Post subject: |
|
|
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
|
Posted: Sat Dec 08, 2007 2:49 pm Post subject: |
|
|
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 |
|
| |
|
|
|