Counting Record

how to count record from database

Page 1 of 1

3 Replies - 1193 Views - Last Post: 10 April 2009 - 10:44 AM Rate Topic: -----

#1 alfalisyada   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 25-February 09

Counting Record

Posted 09 April 2009 - 10:39 AM

hi...i have problem here where my record number from database is not automatically increase, just display 0 even have 10 records..below is my code and sample is look like..when user select program it will call from database for matric, programme and etc.

 //user select program and will display in table
 <table width="64%" height="545" cellpadding="1" cellspacing="1" align="center">
		<tr >
		  <td  align="left" valign="top" bgcolor="#FFFFFF" ><p>
			  <?php
		if(isset($_GET['resitno']))
			$resitno = $_GET['resitno'];
		else
			$resitno = 0;
			
		if (isset($_POST['programme']))
			$programme = $_POST['programme'];
		else
			$programme = 0;
			
		include 'dbconnect.php';
		
		$query = "SELECT resitno, programme, matric, coursepaid FROM payment WHERE programme = '$programme'";
		$result = mysql_query($query) or die('SQL error');
		?>

<select name="programme" size="1">
						<option value="-"> ---------- Select Course ---------- </option>
						<option value="DMT|17500">Diploma in Multimedia Technology</option>
						<option value="DCS|17500">Diploma in Computer Science</option>
						<option value="DMB|17500">Diploma in Multimedia (Business Computing)</option>
						<option value="DMG|17500">Diploma in Management with Multimedia</option>
						<option value="DMK|17500">Diploma in Marketing with Multimedia</option>
					  </select>
					  <input type="submit" name="submit" value="Search" />



//count record
 	<tr bgcolor="#FFFFFF">
				  <td align="center" bgcolor="#99CCFF"><div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
				  <?php echo ($startRow + $count); ?></font></div></td>
				  <td align="center" bgcolor="#99CCFF"><span class="style8"><?php echo $row['matric']; ?></span></td>
				  <td align="center" bgcolor="#99CCFF"><span class="style8"><?php echo [attachmentid=11293]$row['programme']; ?></span></td>
				  <td align="center" bgcolor="#99CCFF"><span class="style8"><?php echo $row['coursepaid']; ?></span></td>
				  <td align="center" bgcolor="#99CCFF"></td>
				</tr>

Attached image(s)

  • Attached Image
  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: Counting Record

#2 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5552
  • View blog
  • Posts: 14,558
  • Joined: 18-April 07

Re: Counting Record

Posted 09 April 2009 - 07:26 PM

You are missing some code in your example. Where is your PHP insert statement and the start of your actual form (the form tag etc)?

You may also want to make sure that you wrap any updating code inside a check for the $_POST["submit"] if condition...

if (isset($_POST["submit"])) {
     // Do the insert into the database code here
     // And put the whole if statement up high in the document before any select statements
}



So if you can show us where you are doing the insert then we can help more. Another tip for you would be to go into the database and make that record row field a "identity" field that "autoincrements". Almost all databases allow you to setup a row which automatically increments its row number upon each insert into the database. Just look up "database autoincrement field" on Google and find an article that pertains to your database type.

Hope that helps!

"At DIC we be autoincrementing code ninjas... ninja masters++" :snap:
Was This Post Helpful? 0
  • +
  • -

#3 alfalisyada   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 25-February 09

Re: Counting Record

Posted 09 April 2009 - 09:01 PM

hi..actually code below is overall how my page will look like..

<?php session_start();?>
<html>
<head>
<title>Payment Report</title>
<style type="text/css">
body {
	background-image: url();
	background-color: #CCCCCC;
}
body,td,th {
	color: #000000;
}
#Layer1 {
	position:absolute;
	width:799px;
	height:203px;
	z-index:1;
	background-image: url(banner1.jpg);
	left: 127px;
	top: 27px;
}
#Layer2 {
	position:absolute;
	width:200px;
	height:115px;
	z-index:1;
	left: 413px;
	top: 358px;
}
#Layer3 {
	position:absolute;
	width:370px;
	height:209px;
	z-index:1;
	left: 423px;
	top: 299px;
	background-image: url(panel.jpg);
}
#Layer4 {
	position:absolute;
	width:301px;
	height:199px;
	z-index:1;
	left: 468px;
	top: 269px;
}
#Layer5 {
	position:absolute;
	left:220px;
	top:298px;
	width:192px;
	height:61px;
	z-index:1;
}
#Layer6 {
	position:absolute;
	left:472px;
	top:261px;
	width:512px;
	height:320px;
	z-index:2;
	background-color: #ECE9D8;
}
.style8 {
	font-size: 12px;
	font-family: Verdana;
}
#Layer7 {	position:absolute;
	width:170px;
	height:34px;
	z-index:3;
	left: 232px;
	top: 154px;
}
#Layer8 {
	position:absolute;
	width:407px;
	height:231px;
	z-index:4;
	left: 543px;
	top: 297px;
}
#Layer9 {
	position:absolute;
	width:498px;
	height:288px;
	z-index:4;
	left: 487px;
	top: 280px;
	background-color: #FFFFCC;
}
.style10 {font-size: 12px;
	font-family: Verdana;
	color: #FF0000;
	font-weight: bold;
}
.style13 {
	font-family: Verdana;
	font-weight: bold;
	font-size: 12px;
	color: #FFFFFF;
}
.style4 {font-size: 14px}
.style5 {font-weight: bold; font-family: Verdana;}
.style7 {	font-size: 12px;
	font-family: Verdana;
	color: #990000;
	font-weight: bold;
}
</style></head>
<script language="javascript" type="text/javascript" src="datetimepicker.js">
</script>

<form name="budget" method="post" action="OffTgk.php">
<body>
<table width="847" height="60" align="center" cellpadding="0" cellspacing="0" background="bckgnd2.gif">
  <tr>
	<td colspan="2"><div align="center"><img src="images/banner1.jpg" width="845" height="150" /></div></td>
  </tr>
  <tr>
	<td bordercolor="#000000" background="images/bckgnd2.gif">&nbsp;</td>
  </tr>
  <tr>
	<td bordercolor="#000000" background="images/bckgnd2.gif"><table width="200" align="center" cellpadding="0" cellspacing="0">
	  <tr>
		<td><div align="center"><span class="style10">Welcome <?php echo $_SESSION['nama'];?> !! </span></div></td>
	  </tr>
	</table></td>
  </tr>
  <tr>
	<td width="611" bordercolor="#000000" background="images/bckgnd2.gif"><div align="right"><a href="index.php" class="style8">[Logout]</a></div></td>
  </tr>
  <tr>
	<td bordercolor="#000000" background="images/bckgnd2.gif">&nbsp;</td>
  </tr>
  <tr>
	<td bordercolor="#000000" background="images/bckgnd2.gif"><div align="right"></div></td>
  </tr>
  <tr>
	<td bordercolor="#000000" background="images/bckgnd2.gif"><div id = "Layer7" align="center"><b> <? echo "<font color='yellow' face='Arial' size='2'><br>";
		echo date("l",time());
		  echo "<br>";
		echo date("d F Y ");
		//echo "<br>";
		echo date("h:iA");
		echo "</font>";?></b></div>
	  <table width="64%" height="545" cellpadding="1" cellspacing="1" align="center">
		<tr >
		  <td  align="left" valign="top" bgcolor="#FFFFFF" ><p>
			  <?php
		if(isset($_GET['resitno']))
			$resitno = $_GET['resitno'];
		else
			$resitno = 0;
			
		if (isset($_POST['programme']))
			$programme = $_POST['programme'];
		else
			$programme = 0;
			
		include 'dbconnect.php';
		
		$query = "SELECT resitno, programme, matric, coursepaid FROM payment WHERE programme = '$programme'";
		$result = mysql_query($query) or die('SQL error');
		?>
			
		  </p>
			  <hr />
			</hr>
			  <div align="center" class="style4"><img src="images/PH02743G.GIF" alt="11" width="62" height="48" /><span class="style5">Payment Report</span> </div>
			<hr />
			</hr>
			</p>
			  <p class="style8">This payment summary is viewed by Programme. </p>
			<table width="607" align="center">
				<tr>
				  <td width="181"><div align="right" class="style8"><strong>Programme : </strong></div></td>
				  <td width="414"><div align="center">
					  <select name="programme" size="1">
						<option value="-"> ---------- Select Course ---------- </option>
						<option value="DMT|17500">Diploma in Multimedia Technology</option>
						<option value="DCS|17500">Diploma in Computer Science</option>
						<option value="DMB|17500">Diploma in Multimedia (Business Computing)</option>
						<option value="DMG|17500">Diploma in Management with Multimedia</option>
						<option value="DMK|17500">Diploma in Marketing with Multimedia</option>
					  </select>
					  <input type="submit" name="submit" value="Search" />
				  </div></td>
				</tr>
			  </table>
			<p align="center" class="style8">&nbsp;</p>
			<p align="left" class="style7">*** List of students : - </p>
			<table width="94%" border="0" align="center" cellpadding="1" cellspacing="1" bordercolor="#CCCCFF">
				<tr>
				  <th width="7%" align="center" bgcolor="#FFCCCC"><span class="style8">Bil</span></th>
				  <th width="26%" align="center" bgcolor="#FFCCCC"><span class="style8">Matric</span></th>
				  <th width="31%" align="center" bgcolor="#FFCCCC"><span class="style8">Programme</span></th>
				  <th width="17%" align="center" bgcolor="#FFCCCC"><span class="style8">Total Fee (RM) </span></th>
				  <th width="19%" align="center" bgcolor="#FFCCCC"><span class="style8">Balance Fee (RM) </span></th>
				</tr>
				<?php 
			while($row = mysql_fetch_array($result, MYSQL_ASSOC))
			{
			?>
			
				<tr bgcolor="#FFFFFF">
				  <td align="center" bgcolor="#99CCFF"><div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
				  <?php echo ($startRow + $count); ?></font></div></td>
				  <td align="center" bgcolor="#99CCFF"><span class="style8"><?php echo $row['matric']; ?></span></td>
				  <td align="center" bgcolor="#99CCFF"><span class="style8"><?php echo $row['programme']; ?></span></td>
				  <td align="center" bgcolor="#99CCFF"><span class="style8"><?php echo $row['coursepaid']; ?></span></td>
				  <td align="center" bgcolor="#99CCFF"></td>
				</tr>
			
				<?php 
			}
			?>
			</table></td>
		</tr>
		<tr> </tr>
	  </table>
	  <p align="center">
	   
	  </p>
	  <p align="center">&nbsp;</p>
	  <p align="center">&nbsp;</p>
	  <p align="center">&nbsp;</p>
	  <p align="center">&nbsp;</p>
	  <p align="center" class="style13">Copyright &copy; 2009 MMC Kuching </p>
	</td>
  </tr>
</table></form>
</body>
</html>


Was This Post Helpful? 0
  • +
  • -

#4 relic5.2   User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 50
  • Joined: 26-November 08

Re: Counting Record

Posted 10 April 2009 - 10:44 AM

$startRow and $count aren't defined, are they?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1