Php::while Problem - any ideas?

free web hosting
Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

Php::while Problem - any ideas?

Arne-Christian
I am currently expericing a problem with the following code:
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?

 

 

 


Reply

Saint_Michael
I can tell its a forum script, but what forum are you using and what mod are you putting in?

Reply

jlhaslip
What is (or isn't) happening correctly?

Reply

Arne-Christian
Saint Michael: Its my own forum i am creating, so its no mod tongue.gif

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 wink.gif

Edit:
IPB Image

Reply

jlhaslip
What is the purpose of this code segment?
CODE

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?
CODE

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.

 

 

 


Reply

Arne-Christian
I fixed it now, with a little bit help form your code wink.gif
CODE

$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 tongue.gif

Thanks for the fast respondes biggrin.gif
I will add Trap17.com to special thanks to on my credits page smile.gif

Reply

jlhaslip
Aw, shucks. It was nothing.

Trap17 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.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : php ideas

  1. Determine If Visitor Is Legit Or A Bot - Need ideas on how to determine this (4)
  2. Learning Php methods - good books/ideas out there? (9)
    I'm looking to start learning some PHP this summer, I've got a good grip on HTML, given that
    I never read a book on it, and my friend taught me. I'm good in logic and math, and taught
    myself CSS, I only know a tad of javascript, but now I'm getting ready to go to the real stuff.
    HTML and CSS don't allow me to do enough, I want to learn PHP, but I'm not sure I can teach
    myself off of help sites anymore, this seems a bit complicated. One of my friends is learning PHP,
    too, so it will be an advantage to bounce ideas off each other. Anyway, I'm w...



Looking for php, problem, ideas

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for php, problem, ideas

*MORE FROM TRAP17.COM*
advertisement



Php::while Problem - any ideas?



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE