Posts: 175
Location: Wiltshire, England
|
Hi lothop,
Thats cool - I think this will do it.
Change this: -
PHP Code:
/* SQL */
$sqlquery = "SELECT email,username,level_id FROM users";
$result = mysql_query($sqlquery);
$number = mysql_num_rows($result);
/* Display Results */
if($number < 1)
print "<CENTER><P>There Were No Results for Your Search</CENTER>";
else
{
while($data = mysql_fetch_array($result))
{
$username = $data['username'];
$level_id = $data['level_id'];
print ("<table width=\"640\" cellpadding=\"3\" cellspacing=\"0\" border=\"1\" bordercolor=\"#000060\">\n<tr>\n<td>\n<p><b>Username:</b> $username</p></td>\n</tr>\n<tr>\n<td>");
if( $level_id ==1 ) { print("<img src=\"1.gif\">");
} elseif ( $level_id ==3 ) {
print("<img src=\"2.gif\">");
}
print("</td>\n</tr>\n</table>\n<br><br>\n");
}
To this : -
This assumes you have column headings of username, age, bot, country, gender, level_id in your database table
PHP Code:
/* SQL */
$sqlquery = "SELECT username,age,bot,country,gender,level_id FROM users";
$result = mysql_query($sqlquery);
$number = mysql_num_rows($result);
/* Display Results */
if($number < 1)
print "<CENTER><P>There Were No Results for Your Search</CENTER>";
else
{
//The next line starts the table and gives the column headings
print("<table width=\"640\" cellpadding=\"3\" cellspacing=\"0\" border=\"1\" bordercolor=\"#000060\">\n<tr>\n<td>Username</td><td>Age</td><td>Bot</td><td>Country</td><td>Gender</td><td>Rank</td>\n</tr>\n");
//The loop through the array then sorts the data and prints it appropriately
while($data = mysql_fetch_array($result))
{
print ("<tr>\n<td>\n<p>$data[username]</p></td>\n<td>\n<p>$data[age]</p></td>\n<td>\n<p>$data[bot]</p></td>\n<td>\n<p>$data[country]</p></td>\n<td>\n<p>$data[gender]</p></td>\n<td>");
//Checks the User Level ID and prints the correct image
if( $data[level_id] == 1) { print("<img src=\"1.gif\">");
} elseif ( $data[level_id] == 3) {
print("<img src=\"2.gif\">");
}
print("</td>\n</tr>\n");
}
//Close the table
print("</table>\n");
You might want to add some formatting to the table, either by assigning a class to the TD tags and using CSS to dictate the font/colour/background OR just using good old html on them in the above code.
Hope this works, but its about 2-30 am and I am knackered, let me know if I've got it wrong.
Regards
Ian
Last edited by celticbrue : 07-03-2004 at 09:45 PM.
|