retrieve data

retrieve from two table

Page 1 of 1

3 Replies - 733 Views - Last Post: 11 May 2009 - 07:30 AM Rate Topic: -----

#1 alfalisyada  Icon User is offline

  • New D.I.C Head

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

retrieve data

Post icon  Posted 11 May 2009 - 01:37 AM

hi..need some help here. i want to display student information from two tables which are student (PK=matric) and payment (PK=paymentid,FK=matric) after insert matric number from search page. but my problem is just display one table not both. i dont know what is wrong with my code, i tried too many time..my code is look like :

	<td bordercolor="#000000"><p><?php
		include 'dbconnect.php';
		
		$matric=$_GET['matric'];
		
		$result = mysql_query("SELECT  * FROM student WHERE matric = '$matric' ");

		
		$Recordset1 = mysql_query("SELECT * FROM payment WHERE matric = '$matric' ");
		$row_Recordset1 = mysql_fetch_assoc($Recordset1);

		
		
		while($row=mysql_fetch_assoc($result)){?>
	</p>
	  <p>&nbsp;</p>
	  <table width="649" height="205" border="0" align="center" cellpadding="0" cellspacing="0" >
		<tr bgcolor="#FFFFFF">
		  <td height="24" colspan="4" bgcolor="#FFFFFF" ><div align="center" class="style21"> <img src="images/holder.gif" width="35" height="32" /> .:: Student's Payment Details ::. </div></td>
		</tr>
		<tr>
		  <td height="19" bgcolor="#FFFF99" >&nbsp;</td>
		  <td colspan="3" bgcolor="#FFFF99" >&nbsp;</td>
		  </tr>
		<tr>
		  <td width="17" height="24" bgcolor="#FFFF99" >&nbsp;</td>
		  <td width="110" bgcolor="#FFFF99" ><span class="style8">Matric</span></td>
		  <td width="20" bgcolor="#FFFF99" ><div align="center" class="style8">:</div></td>
		  <td width="502" bgcolor="#FFFF99"><input name= "matric" type="text" disabled="disabled" id="matric" value="<?php echo $row['matric'] ?>" size="50" />			</td>
		  </tr>
		<tr>
		  <td height="24" bgcolor="#FFFF99">&nbsp;</td>
		  <td bgcolor="#FFFF99"><span class="style8">Name</span></td>
		  <td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
		  <td bgcolor="#FFFF99"><input name= "name" type="text" disabled="disabled" id="name" value="<?php echo $row['name'] ?>" size="50"  /></td>
		  </tr>
		<tr>
		  <td height="24" bgcolor="#FFFF99">&nbsp;</td>
		  <td bgcolor="#FFFF99"><span class="style8">Programme</span></td>
		  <td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
		  <td bgcolor="#FFFF99"><input name="programme" type="text" disabled="disabled" id="programme" value="<?php echo $row['programme'] ?>" size="50" /></td>
		  </tr>
		<tr>
		  <td height="24" bgcolor="#FFFF99">&nbsp;</td>
		  <td bgcolor="#FFFF99"><span class="style8">Course Fee </span></td>
		  <td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
		  <td bgcolor="#FFFF99"><input name="coursefee" type="text" disabled="disabled" id="coursefee" value="<?php echo $row['coursefee'] ?>" size="50" /></td>
		  </tr>
		<tr>
		  <td height="24" bgcolor="#FFFF99">&nbsp;</td>
		  <td bgcolor="#FFFF99"><span class="style8">Sem Fee </span></td>
		  <td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
		  <td bgcolor="#FFFF99"><input name="sem" type="text" disabled="disabled" id="sem" value="<?php echo $row['semfee'] ?>" size="50" /></td>
		  </tr>
		<tr>
		  <td height="24" bgcolor="#FFFF99">&nbsp;</td>
		  <td bgcolor="#FFFF99"><span class="style8">Balance Sem </span></td>
		  <td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
		  <td bgcolor="#FFFF99"><input name="balsem" type="text" disabled="disabled" id="balsem" value="<?php echo $row['balsem'] ?>" size="50" /></td>
		  </tr>
		<tr>
		  <td><div align="center">		  </tr>
	  </table>
	  <p align="center">
	  <?php 
	  }?>
	  </p>



Is This A Good Question/Topic? 0
  • +

Replies To: retrieve data

#2 Wimpy  Icon User is offline

  • R.I.P. ( Really Intelligent Person, right? )
  • member icon

Reputation: 159
  • View blog
  • Posts: 1,038
  • Joined: 02-May 09

Re: retrieve data

Posted 11 May 2009 - 04:16 AM

I don't really get what your problem is but if it is that you get more than one table it's probably because you have the '<table>'-part inside your while-loop:
<?php while($row=mysql_fetch_assoc($result)){?>
	...
	<table width="649" height="205" border="0" align="center" cellpadding="0" cellspacing="0" >
		....
	</table>
	...
<?php 
}?>


if you only want one table you should do it like this:
<table width="649" height="205" border="0" align="center" cellpadding="0" cellspacing="0" >
<?php while($row=mysql_fetch_assoc($result)){?>
	...
	...
<?php 
}?>
</table>


Hope it helps! :)

View Postalfalisyada, on 11 May, 2009 - 10:37 AM, said:

hi..need some help here. i want to display student information from two tables which are student (PK=matric) and payment (PK=paymentid,FK=matric) after insert matric number from search page. but my problem is just display one table not both. i dont know what is wrong with my code, i tried too many time..my code is look like :

	<td bordercolor="#000000"><p><?php
		include 'dbconnect.php';
		
		$matric=$_GET['matric'];
		
		$result = mysql_query("SELECT  * FROM student WHERE matric = '$matric' ");

		
		$Recordset1 = mysql_query("SELECT * FROM payment WHERE matric = '$matric' ");
		$row_Recordset1 = mysql_fetch_assoc($Recordset1);

		
		
		while($row=mysql_fetch_assoc($result)){?>
	</p>
	  <p></p>
	  <table width="649" height="205" border="0" align="center" cellpadding="0" cellspacing="0" >
		<tr bgcolor="#FFFFFF">
		  <td height="24" colspan="4" bgcolor="#FFFFFF" ><div align="center" class="style21"> <img src="images/holder.gif" width="35" height="32" /> .:: Student's Payment Details ::. </div></td>
		</tr>
		<tr>
		  <td height="19" bgcolor="#FFFF99" ></td>
		  <td colspan="3" bgcolor="#FFFF99" ></td>
		  </tr>
		<tr>
		  <td width="17" height="24" bgcolor="#FFFF99" ></td>
		  <td width="110" bgcolor="#FFFF99" ><span class="style8">Matric</span></td>
		  <td width="20" bgcolor="#FFFF99" ><div align="center" class="style8">:</div></td>
		  <td width="502" bgcolor="#FFFF99"><input name= "matric" type="text" disabled="disabled" id="matric" value="<?php echo $row['matric'] ?>" size="50" />			</td>
		  </tr>
		<tr>
		  <td height="24" bgcolor="#FFFF99"></td>
		  <td bgcolor="#FFFF99"><span class="style8">Name</span></td>
		  <td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
		  <td bgcolor="#FFFF99"><input name= "name" type="text" disabled="disabled" id="name" value="<?php echo $row['name'] ?>" size="50"  /></td>
		  </tr>
		<tr>
		  <td height="24" bgcolor="#FFFF99"></td>
		  <td bgcolor="#FFFF99"><span class="style8">Programme</span></td>
		  <td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
		  <td bgcolor="#FFFF99"><input name="programme" type="text" disabled="disabled" id="programme" value="<?php echo $row['programme'] ?>" size="50" /></td>
		  </tr>
		<tr>
		  <td height="24" bgcolor="#FFFF99"></td>
		  <td bgcolor="#FFFF99"><span class="style8">Course Fee </span></td>
		  <td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
		  <td bgcolor="#FFFF99"><input name="coursefee" type="text" disabled="disabled" id="coursefee" value="<?php echo $row['coursefee'] ?>" size="50" /></td>
		  </tr>
		<tr>
		  <td height="24" bgcolor="#FFFF99"></td>
		  <td bgcolor="#FFFF99"><span class="style8">Sem Fee </span></td>
		  <td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
		  <td bgcolor="#FFFF99"><input name="sem" type="text" disabled="disabled" id="sem" value="<?php echo $row['semfee'] ?>" size="50" /></td>
		  </tr>
		<tr>
		  <td height="24" bgcolor="#FFFF99"></td>
		  <td bgcolor="#FFFF99"><span class="style8">Balance Sem </span></td>
		  <td bgcolor="#FFFF99"><div align="center" class="style8">:</div></td>
		  <td bgcolor="#FFFF99"><input name="balsem" type="text" disabled="disabled" id="balsem" value="<?php echo $row['balsem'] ?>" size="50" /></td>
		  </tr>
		<tr>
		  <td><div align="center">		  </tr>
	  </table>
	  <p align="center">
	  <?php 
	  }?>
	  </p>


Was This Post Helpful? 0
  • +
  • -

#3 alfalisyada  Icon User is offline

  • New D.I.C Head

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

Re: retrieve data

Posted 11 May 2009 - 07:06 AM

hi..thanks wimpy for your reply....actually what i want to do is joining information of two table after admin done searching using student's matric number...first table is (studentinfo) and second table is (payment). i want to display information from both table...but my problem here its only display infromation from table studentinfo. i'm also attached the result page.

//php code
<? 
include('dbconnect.php');

$matric=$_POST["matric"];

$result=mysql_query("SELECT * FROM studentinfo WHERE matric='$matric'");
$Recordset1 = mysql_query("SELECT * FROM payment WHERE matric = '$matric' ");
$row_Recordset1 = mysql_fetch_assoc($Recordset1);			

while($row=mysql_fetch_assoc($result))
{
?>



//display interface 
<table width="529" align="center" bordercolor="#FF0000" bgcolor="#FFFF99">
		  <tr>
			<th width="130" scope="row"><div align="left" class="style8 style16 style17">Matric</div></th>
			<th width="10" scope="row"><span class="style8">:</span></th>
			<td width="377"><?php echo $row['matric']; ?>
				<input name="hide_stock" type="hidden" id="hide_stock" value="<?php echo $row['matric']; ?>"></td>
		  </tr>
		  <tr>
			<th scope="row"><div align="left" class="style8">Name </div></th>
			<th scope="row">:</th>
			<td><?php echo $row['name']; ?></td>
		  </tr>
		  <tr>
			<th width="130" scope="row"><div align="left" class="style8">Programme</div></th>
			<th width="10" scope="row"><span class="style8">:</span></th>
			<td width="377"><?php echo $row['programme']; ?></td>
		  </tr>
		  <tr>
			<th scope="row"><div align="left" class="style8">Year</div></th>
			<th scope="row"><span class="style8">:</span></th>
			<td><?php echo $row['coursefee']; ?></td>
		  </tr>
		  <tr>
			<th scope="row"><div align="left" class="style8">Intake</div></th>
			<th scope="row"><span class="style8">:</span></th>
			<td><?php echo $row['statussem']; ?></td>
		  </tr>
		  <tr>
			<th scope="row"><div align="left" class="style8">Sem</div></th>
			<th scope="row"><span class="style8">:</span></th>
			<td><?php echo $row['sem']; ?></td>
		  </tr>
		  <tr>
			<th scope="row"><div align="left" class="style8">Course Fee </div></th>
			<th scope="row"><span class="style8">:</span></th>
			<td><?php echo $row['coursefee']; ?></td>
		  </tr>
		  <tr>
			<th scope="row"><div align="left" class="style8">Hostel Fee </div></th>
			<th scope="row"><span class="style8">:</span></th>
			<td><?php echo $row['hostelfee']; ?></td>
		  </tr>
		  <tr>
			<th scope="row"><div align="left" class="style8">Status Fee (Sem) </div></th>
			<th scope="row"><span class="style8">:</span></th>
			<td><?php echo $row['statussem']; ?></td>
		  </tr>
		  <tr>
			<th scope="row"><div align="left" class="style8">Room Type </div></th>
			<th scope="row"><span class="style8">:</span></th>
			<td><?php echo $row['roomtype']; ?></td>
		  </tr>
		</table>

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#4 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: retrieve data

Posted 11 May 2009 - 07:30 AM

This while($row=mysql_fetch_assoc($result)) only uses the results from this $result=mysql_query("SELECT * FROM studentinfo WHERE matric='$matric'");

This$Recordset1 = mysql_query("SELECT * FROM payment WHERE matric = '$matric' "); is never submitted to be made into a array ... so thats why your not getting the info from the second table

You can TRY ( this is untested and may need to be worked on ) a inner join query

SELECT * 
FROM studentinfo as S1 
INNER JOIN 
payment as P2
ON (S1.matric = '$matric' AND P2.matric = '$matric')



Again this is what you want whether or not this particular query will work is another story lol ... need more coffee!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1