[Help] Echo all Username

Status
Not open for further replies.

Janzeer

Headmaster Of Hogwart's
Apr 30, 2012
522
47
Hey! i was trying to echo sql results and manage to do it. However the code only echo's 1 username while i have 3 username's in database, Can anyone help me with echo-ing the complete amount of username's in the database?
You must be registered for see images attach

You must be registered for see images attach

PHP:
<!DOCTYPE html>
<html>
    <head>
   
    </head>

    <body>
    Applied Applicants :
    <?php
    $Applicant = mysql_fetch_array(mysql_query("SELECT UserName FROM staffapps"));
        echo '<a style="color: black;text-decoration: none;" href="viewapplication?id='.$Applicant['UserName'].'">'.$Applicant['UserName'].'</a>';
    
    ?>
    </body>
    </html>
 

DarkXIDE

Member
Oct 3, 2011
72
10
First of all, run mysqli or pdo instead of mysql. It is outdated.

Anyway. Use while-loops.
Code:
<!DOCTYPE html>
<html>
    <head>
  
    </head>

    <body>
    Applied Applicants :
    <?php
    while($Applicant = mysql_fetch_assoc(mysql_query("SELECT UserName FROM staffapps"))) {
        echo '<a style="color: black;text-decoration: none;" href="viewapplication?id='.$Applicant['UserName'].'">'.$Applicant['UserName'].'</a>';
   }
    ?>
    </body>
    </html>
 

Janzeer

Headmaster Of Hogwart's
Apr 30, 2012
522
47
First of all, run mysqli or pdo instead of mysql. It is outdated.

Anyway. Use while-loops.
Code:
<!DOCTYPE html>
<html>
    <head>
 
    </head>

    <body>
    Applied Applicants :
    <?php
    while($Applicant = mysql_fetch_assoc(mysql_query("SELECT UserName FROM staffapps"))) {
        echo '<a style="color: black;text-decoration: none;" href="viewapplication?id='.$Applicant['UserName'].'">'.$Applicant['UserName'].'</a>';
   }
    ?>
    </body>
    </html>
The page takes ages to load in the end come up with server doesn't respond, I presume it create a lot of while loops.
 

DarkXIDE

Member
Oct 3, 2011
72
10
The page takes ages to load in the end come up with server doesn't respond, I presume it create a lot of while loops.
Try like this then
Code:
<!DOCTYPE html>
<html>
    <head>
    </head>

    <body>
    Applied Applicants :
    <?php
$SQL = mysql_query("SELECT UserName from staffapps") or die(mysql_error());
    while($Applicant = mysql_fetch_assoc($SQL)) {
        echo '<a style="color: black;text-decoration: none;" href="viewapplication?id='.$Applicant['UserName'].'">'.$Applicant['UserName'].'</a>';
   }
    ?>
    </body>
    </html>
 

Janzeer

Headmaster Of Hogwart's
Apr 30, 2012
522
47
Try like this then
Code:
<!DOCTYPE html>
<html>
    <head>
    </head>

    <body>
    Applied Applicants :
    <?php
$SQL = mysql_query("SELECT UserName from staffapps") or die(mysql_error());
    while($Applicant = mysql_fetch_assoc($SQL)) {
        echo '<a style="color: black;text-decoration: none;" href="viewapplication?id='.$Applicant['UserName'].'">'.$Applicant['UserName'].'</a>';
   }
    ?>
    </body>
    </html>
It works, however it arrays in a straight line, how do I stack them up? Would a <br /> work?
 
Last edited:
Status
Not open for further replies.

Users who are viewing this thread

Top