loop

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

loop

Post 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,
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

uh.. move the table creation and termination outside the loop. not hard.



woo! 5000 posts!@!#$@ :D
Last edited by feyd on Sat Oct 09, 2004 5:34 pm, edited 1 time in total.
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Post by SidewinderX »

but there are so many it is confusing the heck out of me
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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!!!
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post 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 ???
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

what do you mean by "differing precedence" :?:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post 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.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

feyd wrote:woo! 5000 posts!@!#$@ :D
Congrats. :wink:


</off-topic>
Post Reply