Just after a filter function I think

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!

Moderator: General Moderators

Post Reply
]{ronic
Forum Commoner
Posts: 27
Joined: Thu Mar 04, 2004 10:42 pm

Just after a filter function I think

Post by ]{ronic »

Hey ..

How can I make the below script display only the records that match "air division" in the "division" column of members mysql table..

Code: Select all

<?php
$dbname="####";
$dbtable="####";
$hostserver="####";
$username="####";
$password="####";

$db = @mysql_connect("$hostserver","$username","$password")
or die ("Problems connecting to database server"); 

@mysql_select_db ("$dbname") or die ("Problem selecting database");
$sql = "SELECT * FROM $dbtable";

$result = mysql_query($sql); 
while ($row = mysql_fetch_array($result)) {
$alias = $row["alias"]; 
$datejoined = $row["datejoined"]; 
$rank = $row["rank"]; 
$division = $row["division"]; 
$prefclass = $row["prefclass"]; 
$prefvehicle = $row["prefvehicle"]; 
$speciality = $row["specialty"]; 
$avatar = $row["avatar"];
?>
<table width="90%" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#413723">
<tr> 
<td height="20" colspan="2" valign="middle"><div align="center"><font class=two>Urban Legends Forces Member</font></div></td>
<td width="45%" height="20"><font>Date Joined:</font> <?php echo $row['datejoined']; ?></td>
</tr><tr> 
<td width="14%" rowspan="4"><div align="center"><img src="<?php echo $row['avatar']; ?>"></div></td>
<td width="41%" height="20"><font>Alias:</font> <?php echo $row['alias']; ?></td>
<td height="20"><font>Rank:</font> <?php echo $row['rank']; ?></td>
</tr><tr> 
<td height="20"><font>Wolf Pack</font></td>
<td height="20"><font>Division:</font> <?php echo $row['division']; ?></td>
</tr><tr> 
<td height="20"><font>Pref Class:</font> <?php echo $row['prefclass']; ?></td>
<td height="20"><font>Pref Vehicle:</font> <?php echo $row['prefvehicle']; ?></td>
</tr><tr> 
<td height="20" colspan="2"><font>Specialty:</font> <?php echo $row['specialty']; ?></td>
</tr></table>
<div align="left"><br>
<?php
}
?>

]{ronic
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

just change your query to

Code: Select all

SELECT * FROM $dbtable WHERE division ='air division'
Mark
]{ronic
Forum Commoner
Posts: 27
Joined: Thu Mar 04, 2004 10:42 pm

Post by ]{ronic »

works .. thanks dude ..


]{ronic
]{ronic
Forum Commoner
Posts: 27
Joined: Thu Mar 04, 2004 10:42 pm

Post by ]{ronic »

Hey

With the above code .. how can I display the number of members in a division or total members within that page or any other page in my site?


Thanks

]{ronic
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

SELECT count(*) FROM $dbtable WHERE division = $divName
Post Reply