Jump to content
xisto Community
Sign in to follow this  
Arne-Christian

Php::while Problem any ideas?

Recommended Posts

I am currently expericing a problem with the following code:

			$db = new db;			$db->connect();			$forum_mod = $db->query("SELECT * FROM eb_moderator WHERE `forum_id` = '{$forum_id}';");			$moderator = "<strong>Moderators:</strong> ";			while ( $mod = mysql_fetch_array($forum_mod)) {				$mod_name = $mod['member_name'];				if($mod['member_name'] !== "") {					$moder = " <a href=\"index.php?act=members&memberid={$mod['member_id']}\">" . $mod_name . "</a>,";				}				if($mod['member_name'] == "") {				$moder = "none";				}				$moderator = $moderator . $moder;			}

Does anybody got an idea how to fix this?

Share this post


Link to post
Share on other sites

Saint Michael: Its my own forum i am creating, so its no mod :P

 

jlhaslip: Well it prints out the correnct information one place (Name of the moderator), BUT when there isn't a moderator at forum X it should print out none, but here comes the tricy part, it dosnt do that -.-, give me 1 minute i will take a screenshot :)

 

Edit:

Posted Image

Edited by Arne-Christian (see edit history)

Share this post


Link to post
Share on other sites

What is the purpose of this code segment?

if($mod['member_name'] == "") {				$moder = "none";				}				$moderator = $moderator . $moder;

If you want to print "none" for the number of Moderators, check the mysql query results array for the number of results and then perform the while loop inside the loop?
if ( count(mysql_fetch_array($forum_mod)) > 0) {				while( $mod = mysql_fetch_array($forum_mod)) {				$mod_name = $mod['member_name'];				if($mod['member_name'] !== "") {					$moder = " <a href=\"index.php?act=members&memberid={$mod['member_id']}\">" . $mod_name . "</a>,";echo $moder;				}else {echo "none";}

I don't know if all the code is correct, but the logic might work differently than what you have now.

Treat this as pseudo-code.

Share this post


Link to post
Share on other sites

I fixed it now, with a little bit help form your code :P

$rows = mysql_num_rows($forum_mod);			if ($rows > 0) {				while ( $mod = mysql_fetch_array($forum_mod)) {					$mod_name = $mod['member_name'];					if(count($mod['member_name']) > 0) {						$eb_moderator = "<strong>Moderators:</strong> ";						$eb_moderator .= " <a href=\"index.php?act=members&memberid={$mod['member_id']}\">" . $mod_name . "</a>,";					}				}			}			else {				$eb_moderator = "<strong>Moderators:</strong> ";				$eb_moderator .= "<i>None</i>";			}
thats the new code :)

Thanks for the fast respondes B)
I will add Xisto.com to special thanks to on my credits page :P

Share this post


Link to post
Share on other sites

Aw, shucks. It was nothing.Xisto appreciates all its members and if you would pass the word around, it will only make this a better place.Good luck on your project.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.