Jump to content

Count similar rows (and an idiot error thats making my brain hurt)


dropfaith

Recommended Posts

this below is the idiot error  it submits everything except baby into my database just fine

baby = select box like all the others html is fine

 

<?php
$gender = $_POST['gender'];
$gender1 = $_POST['gender1'];
$Species1 = $_POST['Species1'];
$Species2 = $_POST['Species2'];
$baby = $_Post['baby'];

$query="insert into breeding (gender, gender1, Species1, Species2, baby) values ('$gender','$gender1','$Species1','$Species2','$baby')";
$result = mysql_query($query);
?>

 

 

 

Okay now for the question the code below im trying to add a counter to it but all the fields need to match  so anytime all gender 1 and 2 species 1 and 2 baby match  it adds to a counter and displays

but only if they all  match. Im not sure where to start on that so tips are awesome or instruction since im new to this

 

<?php $query  = "SELECT * FROM breeding";
$result = mysql_query($query);
if (mysql_num_rows($result) > 0)
{
// iterate through resultset
// print article titles
while($row = mysql_fetch_object($result))
{
?>	
<tr>
	<td><?php echo $row->gender; ?>   <?php echo $row->Species1; ?></td>
	<td><?php echo $row->gender1; ?>   <?php echo $row->Species2; ?></td>
	<td><?php echo $row->baby; ?></td>
<td>HERE ID LIKE TO ECHO TOTAL </td>
	</tr>

									<?php
}
}
// if no records present
// display message
else
{
?>
<p>No press releases currently available</p>
<?php
}



?>

 

 

http://box1.host1free.com/~crimso/breeding.php  theres a test link

1. In PHP variables are case-sensitive. $_POST is not the same as $_Post.

2. Don't use multiple rows with all the same values. Add a column that counts how many there are, then set it to 1 (if the values don't exist yet) or increment it (if the values do exist).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.