heres my full script, i use it to get all information for registered members for a profiling system
Code: Select all
<?php
// database variables for connections
$host = "localhost";
$user = "malcolmboston";
$password = "xxxxxxx";
$DBname = "xxxxxxx";
$tablename = "login";
//connection variables completed
// establishing connections
$link = mysql_connect ($host, $user, $password);
//connection established
//the query defined
$query = "SELECT * FROM login WHERE show_profile = 'yes' AND access_level = 'Admin' ORDER BY 'access_level' ASC";
// select the database
mysql_select_db($DBname);
// query the database
$result = mysql_query($query);
// display all the results for all the admin
$data = mysql_fetch_array($result, MYSQL_ASSOC);
print "
<form name=$data[username] method=post action=profile_details.php target=_blank><tr bgcolor=#46B5FF>
<td width=30%><strong> $data[username]</strong></td>
<td width=20%><a class=main-nav href=mailto:$data[email]>E-Mail Me</a></td>
<td width=20%><font face=arial>$data[access_level]</font></td>
<td width=20%><input class=push name=$data[username] type=submit id=$data[username] value=View Profile>
<input name=username2pass type=hidden id=username2pass value=$data[username]>
</td>
</tr></form>";
while ($row = mysql_fetch_assoc($result))
print "
<form name=$row[username] method=post action=profile_details.php target=_blank>
<tr bgcolor=#46B5FF>
<td><strong> $row[username]</strong></td>
<td><a class=main-nav href=mailto:$row[email]>E-Mail Me</a></td>
<td><font face=arial>$row[access_level]</font></td>
<td><input class=push name=$row[username] type=submit id=$row[username] value=View Profile>
<input name=username2pass type=hidden id=username2pass value=$row[username]></td>
</tr><form>";
//fetch all the results for all the members
$query2 = "SELECT * FROM login WHERE show_profile = 'yes' AND access_level = 'Member' ORDER BY 'access_level' ASC";
// select the database
mysql_select_db($DBname);
// query the database
$result2 = mysql_query($query2);
// display all the results for all the admin
$data2 = mysql_fetch_array($result2, MYSQL_ASSOC);
print "
<form name=$data2[username] method=post action=profile_details.php target=_blank>
<tr bgcolor=#D2EDFF>
<td width=30%><strong> $data2[username]</strong></td>
<td width=20%><a class=main-nav href=mailto:$data2[email]>E-Mail Me</a></td>
<td width=20%>$data2[access_level]</td>
<td width=20%><input class=push name=$data2[username] type=submit id=$data2[username] value=View Profile>
<input name=username2pass type=hidden id=username2pass value=$data2[username]></td>
</tr></form>";
now lets break down my script
you will notice that on my script that i make sure it inserts my first result and then the loop is created thereafter
for eg in my administrators
Code: Select all
$link = mysql_connect ($host, $user, $password);
//connection established
//the query defined
$query = "SELECT * FROM login WHERE show_profile = 'yes' AND access_level = 'Admin' ORDER BY 'access_level' ASC";
// select the database
mysql_select_db($DBname);
// query the database
$result = mysql_query($query);
// display all the results for all the admin
$data = mysql_fetch_array($result, MYSQL_ASSOC);
print "
<form name=$data[username] method=post action=profile_details.php target=_blank><tr bgcolor=#46B5FF>
<td width=30%><strong> $data[username]</strong></td>
<td width=20%><a class=main-nav href=mailto:$data[email]>E-Mail Me</a></td>
<td width=20%><font face=arial>$data[access_level]</font></td>
<td width=20%><input class=push name=$data[username] type=submit id=$data[username] value=View Profile>
<input name=username2pass type=hidden id=username2pass value=$data[username]>
</td>
</tr></form>";
while ($row = mysql_fetch_assoc($result))
print "
<form name=$row[username] method=post action=profile_details.php target=_blank>
<tr bgcolor=#46B5FF>
<td><strong> $row[username]</strong></td>
<td><a class=main-nav href=mailto:$row[email]>E-Mail Me</a></td>
<td><font face=arial>$row[access_level]</font></td>
<td><input class=push name=$row[username] type=submit id=$row[username] value=View Profile>
<input name=username2pass type=hidden id=username2pass value=$row[username]></td>
</tr><form>";
the first record is created here
Code: Select all
$link = mysql_connect ($host, $user, $password);
//connection established
//the query defined
$query = "SELECT * FROM login WHERE show_profile = 'yes' AND access_level = 'Admin' ORDER BY 'access_level' ASC";
// select the database
mysql_select_db($DBname);
// query the database
$result = mysql_query($query);
// display all the results for all the admin
$data = mysql_fetch_array($result, MYSQL_ASSOC);
print "
<form name=$data[username] method=post action=profile_details.php target=_blank><tr bgcolor=#46B5FF>
<td width=30%><strong> $data[username]</strong></td>
<td width=20%><a class=main-nav href=mailto:$data[email]>E-Mail Me</a></td>
<td width=20%><font face=arial>$data[access_level]</font></td>
<td width=20%><input class=push name=$data[username] type=submit id=$data[username] value=View Profile>
<input name=username2pass type=hidden id=username2pass value=$data[username]>
</td>
</tr></form>";
and then looped here straight after
Code: Select all
while ($row = mysql_fetch_assoc($result))
print "
<form name=$row[username] method=post action=profile_details.php target=_blank>
<tr bgcolor=#46B5FF>
<td><strong> $row[username]</strong></td>
<td><a class=main-nav href=mailto:$row[email]>E-Mail Me</a></td>
<td><font face=arial>$row[access_level]</font></td>
<td><input class=push name=$row[username] type=submit id=$row[username] value=View Profile>
<input name=username2pass type=hidden id=username2pass value=$row[username]></td>
</tr><form>";
hope this helps you out, i know this works because ive just taken it from my site