Question

I've tried a million different ways, and this is probably something super simple, but I can't get it figured out.

I have a database that displays several different columns (name, age, gender, breed, player, etc.)

What I would like is to include a line that states "We have ___ number of female characters."

Here is my entire page where I want it displayed:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <title>AUSUS --- mythical equine RPG</title>
 <link rel="stylesheet" type="text/css" href="/css/evolution2.css" />
<link href='http://fonts.googleapis.com/css?family=Vollkorn:400,400italic,700,700italic|Kreon:400,700,300|La+Belle+Aurore|Stalemate|IM+Fell+English:400,400italic|Mrs+Saint+Delafield' rel='stylesheet' type='text/css'>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>

<h1>Character Database</h1>


<p>
We currently have <b>

<?php

$link = mysql_connect("***", "***", "***");
mysql_select_db("tarb89_characters", $link);
$result = mysql_query("SELECT * FROM characters", $link);
$num_rows = mysql_num_rows($result);
echo "$num_rows";

?>

</b>
characters listed in the database.  You may search the character database by character name or player name.  Dams and sires marked with an asterisk (*) are from <b>outside</b> Ausus.<br><br>




 <br><br>
<form action="searchchars.php" method="GET"/>
<input type="text" name="searchchars" />
<input type="submit" name="submit" value="Character Name Search" /><br>
</form>
<br>
<form action="searchplays.php" method="GET"/>
<input type="text" name="searchplays" />
<input type="submit" name="submit" value="Player Name Search" />
</form>
</p>

<p>
<br><br>
<?php
/// In order to use this script freely
/// you must leave the following copyright
/// information in this file:
/// Copyright 2012 www.turningturnip.co.uk
/// All rights reserved.

include("connect.php");

if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; };
$start_from = ($page-1) * 20; 
$result = mysql_query("SELECT * FROM characters ORDER BY name ASC LIMIT $start_from, 20");
$num = mysql_num_rows ($result);

if ($num > 0 ) {
$i=0;
while ($i < $num) {

$id = stripslashes(mysql_result($result,$i,"id"));
$name = stripslashes(mysql_result($result,$i,"name"));
    $breed = stripslashes(mysql_result($result,$i,"breed"));
    $gender = stripslashes(mysql_result($result,$i,"gender"));
    $color = stripslashes(mysql_result($result,$i,"color"));
    $markings = stripslashes(mysql_result($result,$i,"markings"));
    $genetics = stripslashes(mysql_result($result,$i,"genetics"));
    $player = stripslashes(mysql_result($result,$i,"player"));
    $traits = stripslashes(mysql_result($result,$i,"traits"));
    $defects = stripslashes(mysql_result($result,$i,"defects"));
    $extras = stripslashes(mysql_result($result,$i,"extras"));
    $profile = stripslashes(mysql_result($result,$i,"profile"));
    $dam = stripslashes(mysql_result($result,$i,"dam"));
    $sire = stripslashes(mysql_result($result,$i,"sire"));
    $status = stripslashes(mysql_result($result,$i,"status"));

$row .= '

<h5>'.$name.'</h5>

<table width="550px" cellpadding="5" cellspacing="20" style="background: #eeeeee; border-radius: 15px; border: 1px solid #5067be;">
<tr>
<td width="50%"><p>
    <b>ID Number:</b>  '.$id.'<br>
    <b>Breed:</b>  '.$breed.'<br>
    <b>Gender:</b>  '.$gender.'<br>
    <b>Dam:  </b>'.$dam.'<br>
    <b>Sire:  </b>'.$sire.'<br>
    <b>Status:  </b>'.$status.'<br>
    <b>Profile:</b>  <a href="'.$profile.'">Click Here</a><br>
    <b>Player:</b>  '.$player.'</p></td>
<td width="50%"><p>        
    <b>Color:</b>  '.$color.'<br>
    <b>Genetics: </b>'.$genetics.'<br>
    <b>Markings:</b>  '.$markings.'<br>
    <b>Traits:</b>  '.$traits.'<br>
    <b>Defects:</b>  '.$defects.'<br>
    <b>Extras:</b>  '.$extras.'</p></td>
    </table><br>

    ';






++$i; }} else { $row = '<tr><td colspan="2" align="center">Database empty.</td></tr>'; }

mysql_close();
?>

<? echo $row ?>
</p><center>
<font face="tahoma" style="font-size: 12px;">Pages: 
<?php
include("connect.php");
$result = mysql_query("SELECT COUNT(name) FROM characters");
$row = mysql_fetch_row($result);
$total_records = $row[0];
$total_pages = ceil($total_records / 20);

for ($i=1; $i<=$total_pages; $i++) {
        echo "<a href='index.php?page=".$i."'>".$i."</a> | ";
};
?>
</center></font> 
</body>
</html>
Was it helpful?

Solution

Here is example for the same you can edit this

<?php
$cnt = 0;
$query = "select * from table";
$resulr = mysql_query($query);
while($var = mysql_fetch_array($result)){
  if($var['gender']=='female'){
    $cnt++;
  }
}
echo "We have ".$cnt." female characters";
?>

OTHER TIPS

SELECT COUNT(id) FROM characters where gender = 'female'

That will get you the count of characters which have 'female' as the value for gender. Is that what you want?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top