Page 1 of 1

loop

Posted: Sat Oct 09, 2004 4:36 pm
by SidewinderX
hello i have a code ive been messing around for a bit, the code is suppose to generate a table and but the data in each one of the tebles rows as opposed to creating a new table for eack piece of data...i know it is doing this because the table is inside a loop, but there are so many it is confusing the heck out of me, so if someone could tell me the proper place to place what that would be awesome.

Here is the code:

Code: Select all

<?php
    $result3 = $db->sql_query("SELECT title, custom_title, view FROM " . $prefix . "_modules WHERE active='1' AND title!='$def_module' AND inmenu='1' ORDER BY custom_title ASC");
    while ($row3 = $db->sql_fetchrow($result3)) {
	$m_title = stripslashes($row3['title']);
	$custom_title = $row3['custom_title'];
	$view = intval($row3['view']);
	$m_title2 = ereg_replace("_", " ", $m_title);
	if ($custom_title != "") {
	    $m_title2 = $custom_title;
	}
	if ($m_title != $main_module) {
	    if ((is_admin($admin) AND $view == 2) OR $view != 2) {
		$content .= "<table border="0" width="100%">";
		$content .= "<tr><td background="themes/OrangeT3mplate/images/button.jpg" height="10"><big>&middot;</big></strong>&nbsp;<a href="modules.php?name=$m_title">$m_title2</a></td></tr>\n";
		$content .= "</table>";
		}
	}
    }
?>
The tables im talking about are on lines 13-15

Thanks,

Posted: Sat Oct 09, 2004 5:20 pm
by feyd
uh.. move the table creation and termination outside the loop. not hard.



woo! 5000 posts!@!#$@ :D

Posted: Sat Oct 09, 2004 5:24 pm
by SidewinderX
but there are so many it is confusing the heck out of me

Posted: Sat Oct 09, 2004 5:26 pm
by John Cartwright
i'll give you a hint...

[php_man]while[/php_man] is the beginning of the loop

and content .= <table>

and content .= </table> parts should not be in it!!

i have faith in your ability!!!

Posted: Sat Oct 09, 2004 5:56 pm
by mudkicker
out of subject i have a question in this code sidewinderx used in a if() AND & OR..

is it better to use && and || or AND and OR ???

Posted: Sat Oct 09, 2004 5:57 pm
by feyd
pretty much, as long as it's consistent, it doesn't matter.

technically, the word versions have differing precedence from the symbol versions.

Posted: Sat Oct 09, 2004 6:00 pm
by mudkicker
what do you mean by "differing precedence" :?:

Posted: Sat Oct 09, 2004 6:01 pm
by feyd

Posted: Sat Oct 09, 2004 6:06 pm
by mudkicker
AND is not the same like &&

for example:

Code: Select all

<?php $a && $b || $c; ?>
is not the same like

Code: Select all

<?php $a AND $b || $c; ?>
the first thing is
(a and b) or c

the second
a and (b or c)

'cause || has got a higher priority than and, but less than &&

of course, using always [ && and || ] or [ AND and OR ] would be okay, but than you should at least respect the following:

Code: Select all

<?php $a = $b && $c; ?>
<?php $a = $b AND $c; ?>
the first code will set $a to the result of the comparison $b with $c, both have to be true, while the second code line will set $a like $b and THAN - after that - compare the success of this with the value of $c

maybe usefull for some tricky coding and helpfull to prevent bugs :D

greetz, Warhog
that made everything clear, thanks.

Posted: Sun Oct 10, 2004 12:07 am
by m3mn0n
feyd wrote:woo! 5000 posts!@!#$@ :D
Congrats. :wink:


</off-topic>