Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

while() difficulties

7:46 pm on Sep 13, 2008 (gmt 0)

New User

10+ Year Member

joined:Aug 5, 2008
votes: 0

I've been desperately trying to use a while() loop while using some mock-up "template" system in order to separate my coding from the templating, and it's not going well. Instead of displaying the contents that I ask of inside the loop, it treats the variables as NULL. Here is my coding example:

I'd like to indent properly, but I sadly cannot at some points because I'm grabbing fragments that are vital only.

while() loop

while ($sub_list = mysql_fetch_assoc($list))

All that load() function does is include the file. The file that has the actual contents now is:


@title: Submission List
@description: Lists the Submissions.

echo '
<a href="'.$sub_list['category'].'/'.$sub_list['alias'].'/">
<img src="'.$sub_list['thumbnail'].'" alt="" />
<br />
<td><a href="/forums/member.php?uid='.$sub_list['author'].'">'.$author['username'].'</a></td>
<td><a href="'.$category['cat_alias'].'">'.$category['cat_title'].'</a></td>

Yes, I have even attempted to use globals, but not even that works correctly with while() loops. Ignore any variables that are not $sub_list by the way.

If you need more information, I'd be glad to provide more.

[edited by: Furutsuzeru at 7:47 pm (utc) on Sep. 13, 2008]

11:34 pm on Sept 13, 2008 (gmt 0)

Junior Member

10+ Year Member

joined:June 6, 2005
votes: 0

I would say first things first... Try this and see what you get:

while ($sub_list = mysql_fetch_assoc($list))

It may be the case that you're getting null values back from the database.

6:39 am on Sept 14, 2008 (gmt 0)

New User

10+ Year Member

joined:Aug 19, 2008
votes: 0

if you want the $sub list variable to be available within the load() function you'll have to pass it.

$system->templates->load('submission/submission_list', $sub_list)

4:27 pm on Sept 14, 2008 (gmt 0)

New User

10+ Year Member

joined:Aug 5, 2008
votes: 0

I've already verified that these values are not null, MattAU, since I have tried this method.

tfk11, thank you. It seems that passing the variable did work (with a little bit of extra work and changing of variables to all be $data instead, for a little more consistent format).