Jump to content
xisto Community
Sign in to follow this  
HmmZ

Listing From Table Row Data Listing all members

Recommended Posts

Hello, it's been a while since i've been active in the PHP Board ( i used to be really active in here ), not only to help others but also to request help ( people knowing those requests, dont share your bad experience with my requests :P )

Anyway, i am requesting help on a listing of members, i totally forgot about how to fetch the rows from a table and display each row, i thought it was:

$result=mysql_query("SELECT * FROM $usertable ORDER BY id DESC") or die();$num=mysql_num_rows($result);$array=mysql_fetch_array($result);for($i=0;$i<$num;$i++){print "";}

where print "" should display name, username, email, grade(member/mod/admin) and an option to edit. And where the list is categorized on user id, descending
This didn't work out, so ive been experimenting, but so far no good, this is why i am requesting help in this matter.

The current code i have for the list is:
$result=mysql_query("SELECT * FROM $usertable ORDER BY uid DESC");$num=mysql_num_rows($result);$array=mysql_fetch_array($result);$lvl="<img src='./images/level".$put[permit].".png' border='0'>";for(; list(,$listname)=each($array['name']), list(,$listuname)=each($array['username']), list(,$listfunction)=each($array['function']), list(,$listpermit)=each($array['permit']), list(,$listemail)=each($array['email']);)   {	for($i=0;$i<$num;$i++)	{	print "<tr><td align='center'><font class='news_font'>$listname</td><td align='center'><font class='news_font'>$listuname</td><td align='center'><font class='news_font'>$listfunction</td><td align='center'>$lvl</td><td align='center'><font class='news_font'>$listemail</td><td align='center'><a href='manmem.php?user=$listuname&req=edit'>Edit</a></tr>";	}   }

It does not display anything unfortunately and i just cant find a way to get it all displayed right, at one point i did have a result (dont ask me wich method, ive tried/used many methods) but it displayed every row 4 times, wich i have the term 'weird B) ' for B)

Anyway, any help is greatly appreciated :)

Notice from BuffaloHELP:
Topic title changed. Next time using "Requesting Help" as your only title will result in warning adjustment.

Edited by BuffaloHELP (see edit history)

Share this post


Link to post
Share on other sites

Perhaps you could try something like this:

$result=mysql_query("SELECT * FROM $usertable ORDER BY uid DESC");$row = mysql_fetch_array($result);$lvl="<img src='./images/level".$row[permit].".png' border='0'>";while($row){echo "<tr><td align='center'><font class='news_font'>$row[name]</td><td align='center'><font class='news_font'>$row[username]</td><td align='center'><font class='news_font'>$row[function]</td><td align='center'>$row[lvl]</td><td align='center'><font class='news_font'>$row[email]</td><td align='center'><a href='manmem.php?user=$row[username]&req=edit'>Edit</a></tr>";}

I haven't tested it, but I think it should work.

Share this post


Link to post
Share on other sites

I tried it just now, it didnt work ;_;

i got something like the following (endless loop):

Member Real Name	Member Username	Member Function	Member Level	Member E-mail	Optionstester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edittester	tester2	member  tester	Edit
and i dont think it ends anytime soon XD

Share this post


Link to post
Share on other sites

I googled and found this:

WHILE

 

The only difference this construct has with do..while is the possibility of bypassing the loop if the loop condition is not met. This is because truth expressions are checked even before an iteration takes place. The basic syntax is:

 

      while (expr) statement;

 

As you can see, while loop is very simple. In fact, this is the simplest type of loop in PHP. An example of this loop in action is:

 

      $i = 1; // initialize $i

      while ($i <= 3) // set expression where truth will be checked

      {

        echo "Value = $i"; // display current value

        $i++; // increment $i to prevent endless loop

      }

 

There! This ends our section on PHP loops. Remember that loops can be a powerful ally but it can also be a destructive enemy if used in the wrong sense. The general rule on loops is: "Avoid endless loops". As we have seen in the examples above, a possible way to get into this dilema is forgetting to increment (or decrement) a variable which happens to be the control variable for the loop. With your knowledge on loops, you can now create shorter codes and traverse through database tables more effectively. Of course that would be tackled on later lessons.


Unfortunately, it does not solve the problem of only one user being displayed multiple times...how can i make sure each row is equal to each unique user?

Share this post


Link to post
Share on other sites

i found a way to solve it all, it may look weird hehe :)

 

$result=mysql_query("SELECT * FROM $usertable ORDER BY uid DESC");if(mysql_num_rows($result)){while($row=mysql_fetch_row($result)){$lvl="<img src='./images/level".$row[].".png' border='0'>";echo "<tr><td align='center'><font class='news_font'>$row[3]</td><td align='center'><font class='news_font'>$row[]</td><td align='center'><font class='news_font'>$row[]</td><td align='center'>$lvl</td><td align='center'><font class='news_font'>$row[]</td><td align='center'><a href='manmem.php?user=$row[]&req=edit'>Edit</a></tr>";}}
where in row[] is the number of the field and not counting the primary key

(so if your table looks like "id,username,password,email,realname" etc) it would be:

username($row[1]),email($row[3],realname($row[4]), sounds weird but works :P

 

Thank you for trying to help avalon B)

Share this post


Link to post
Share on other sites

*darn*! Sorry about creating the endless loop. :) It was close to being right, but one wrong step and it turned into a disaster. Glad you sorted it out in the end, at least I pointed you in the right direction. :P

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.