PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Im somewhat of a n00bie at PHP but what i came here for was....
Im making my own login Script and well i cant seem to get my users put on a page where only admins can view all of them like a list or something i would like to have it as a table and well every time i do a script for it.. it gives me a blank page or i get errors or i only get 1 user and i want to show all users if you can help me please email me at webmaster@hauntedgraveyard.southsidedesigns.net i dont have much time to get back here im usually scripting alot of codes for my game im building please help me
I want to post everything like id, username, and email in a table on a page on my website so only admins can see on admin page
Just create a single table below your while loop with $row['username'] etc in the fields you want .. Just put a <br> or two after the table if you want to break each record into a seperate table .. It will then duplicate the table for each record it brings back ..
Here is what I use to list my members .. It also has pagination and an option that shows edit user level link if admin is logged in .. It should be enough to get you started .. Pull it to bits to suit your own needs ..
<div align="center">
<fieldset>
<legend><strong> <span class="txt2">MEMBER PROFILES</span></strong></legend><br>
<?php
// Database Connection
include 'db.php';
// If current page number, use it
// if not, set one!
if(!isset($_GETї'page'])){
$page = 1;
} else {
$page = $_GETї'page'];
}
// Define the number of results per page
$max_results = 15;
// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);
// Perform MySQL query on only the current page number's results
$sql = mysql_query("SELECT * FROM users LIMIT $from, $max_results");
while($row = mysql_fetch_array($sql)){
$userid = $rowї'$userid'];
$first_name = $rowї'first_name'];
$last_name = $rowї'last_name'];
$user_name = $rowї'user_name'];
$email_address = $rowї'email_address'];
$location = $rowї'location'];
$msn = $rowї'msn'];
$icq = $rowї'icq'];
$show_email = $rowї'show_email'];
$show_msn = $rowї'show_msn'];
$show_icq = $rowї'show_icq'];
?>
<table width="100%" cellspacing="1" cellpadding="3">
<tr>
<td width="16%" class="txt"><strong>Name</strong></td>
<td width="26%" class="txt"><?php echo $rowї'first_name']; ?> <?php echo $rowї'last_name']; ?>
</td>
<td width="11%" class="txt"><strong>Email</strong></td>
<td width="47%"> <span class="txt">
<?php if($rowї"show_email"] == 1){
echo $rowї'email_address'];
}else{
echo "undisclosed";
}
?>
</span></td>
</tr>
<tr>
<td class="txt"><strong>User Name</strong></td>
<td class="txt"><?php echo $rowї'user_name']; ?> </td>
<td class="txt"><strong>MSN</strong></td>
<td> <span class="txt">
<?php if($rowї"show_msn"] == 1){
echo $rowї'msn'];
}else{
echo "undisclosed";
}
?>
</span></td>
</tr>
<tr>
<td class="txt"><strong>Location</strong></td>
<td class="txt"><?php echo $rowї'location']; ?> </td>
<td class="txt"><strong>ICQ</strong></td>
<td> <span class="txt">
<?php if($rowї"show_icq"] == 1){
echo $rowї'icq'];
}else{
echo "undisclosed";
}
?>
</span></td>
</tr>
<tr>
<td colspan="4" class="txt"><div align="center">
<?php
// Show only if user is = to admin
if($_SESSIONї'user_level'] == 3) {
echo "<a href="../login/userlevel.php?userid=$userid">UPDATE USER LEVEL</a>";
}else{
echo " ";
}
?>
</div></td>
</tr>
</table>
<hr width="98%" size="1" noshade>
<?php
}
?>
<br>
<?php
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM users"),0);
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
// Build Page Number Hyperlinks
echo "<center>";
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo "<font class="txt"><< <a href="".$_SERVERї'PHP_SELF']."?pages=members&page=$prev">Previous</a> | </font>";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "<font class="txt" color="#FF0000">$i </font>";
} else {
echo "<font class="txt"><a href="".$_SERVERї'PHP_SELF']."?pages=members&page=$i">$i</a> </font>";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo "<font class="txt"> | <a href="".$_SERVERї'PHP_SELF']."?pages=members&page=$next">Next</a> >></font>";
}
echo "</center>";
?>
</fieldset>
</div>
I need to get a search function in there somewhere as well, got to many members .. havnt got that far yet .. not sure how to get it all in one page .. bla bla