View Full Version : Dang thing won't loop!
TWTCommish
09-28-2001, 05:17 AM
I'm working on a hack, and I am using code with the below format (in my main vB directory)...however, the query only produces one row, even though running it manually produces more than that. It seems as if it's not running through the loop more than once...any idea on what might be wrong with it? Thanks in advance. :)
<?php
require("./global.php");
$forumlist = $DB_site->query("SELECT * FROM forum WHERE displayorder != '0' AND active = '1' ORDER BY parentid, displayorder");
while ($forum = $DB_site->fetch_array($forumlist)) {
// do stuff
}
$DB_site->free_result($forumlist);
unset($forum);
Could it be that those variables ($forumlist, $forum) are conflicting with some others in use in the global.php file?
JamesUS
09-28-2001, 05:32 AM
Quite possibly. Try unsetting them both before your code:
<?php
require("./global.php");
unset($forumlist);
unset($forum);
//your code here
TWTCommish
09-28-2001, 05:38 AM
Good idea. Just tried it, but still no loopage. :(
TWTCommish
09-28-2001, 08:32 PM
Alright, if someone can help me figure out what's wrong with this (seemingly) simple block of code, I'll give 'em a link in the footer of every page on my site (MovieForums.com) for 2 weeks (probably more...I'm lazy about taking stuff like that down). The site gets 150-200 posts a day on average.
Any assistance is appreciated! :)
Admin
09-28-2001, 08:36 PM
Will you put *another* link to Israel.com if I help you? :D
j/k, I can't really understand why it won't loop. :confused:
TWTCommish
09-28-2001, 09:04 PM
LOL...sure I would! Hehe. Yeah, I'm stumped to. It's really a very simple block of code. I ran the query elsewhere and it does indeed produce more than one record...the one that the script does spit out (by itself) each time is the last one returned when I run the query in phpMyAdmin...dunno if that's useful, though.
Dolby
09-28-2001, 11:45 PM
I have a script that lists stuff... Look at this and insert your stuff and it should work for you.
// echo "html that doesnt repeat";
$result=mysql_query("SELECT * FROM user where (usergroupid = '6' OR usergroupid ='8' OR usergroupid ='9') AND r_class = 'bard' order by username") or die ("Query Failed:".mysql_error());
while ($row = mysql_fetch_row($result)) {
echo "//html that repeats... <tr><td width=200><a href=rprofile.php?ruser=$row[2]>$row[2] $row[42]</a></td><td>Lvl:$row[43]</td><td>$row[44]</td><td width=100>$row[46]</td></tr>
<tr><td colspan=4><hr size=1 width=100%></td></tr>";
}
// echo "html that doesnt repeat";
TWTCommish
09-29-2001, 12:46 AM
Well, I have no problem grabbing data...I'm just sticking with vB's functions, because it's cleaner that way. I'm wondering if there is some quirk in the DB_site class that's preventing this loop from running properly.
JamesUS
09-29-2001, 07:11 AM
Which version are you on Chris?
TWTCommish
09-29-2001, 11:56 AM
Nope...this is with 2.0.3.
Wayne Luke
09-29-2001, 02:21 PM
Sounds like a logic error in your //do stuff section that is causing it to break out of the loop.
If your loop works properly with a simplified //do stuff such as "echo '$forumlist[title]<br />';" then look at the logic there.
Also if you are appending strings like building a template. Make sure you are actually appending and not replacing. You might be missing some periods somewhere.
TWTCommish
09-29-2001, 03:13 PM
Wayne was right, there was ONE character (a period) I was missing. Thanks, Wayne! What would you like the link to point to?
Wayne Luke
09-29-2001, 04:27 PM
I don't need a link. Thanks though.
TWTCommish
09-29-2001, 04:30 PM
Oh no, you deserve the thanks. :) I should've known it was a stupid oversight of mine, hehe. Anyway, the offer will stand for at least a couple weeks, so feel free to take me up on it later.
Thanks everyone for your time, I appreciate it.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.