Jump to content

[SOLVED] php retrieve


aian04

Recommended Posts

<?php
$host="localhost"; 
$username="root"; 
$password="tmc";
$db_name="tgp"; 
$tbl_name="reservation"; 
$id=$_COOKIE['ID'];

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name where Cid ='$id'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

?>
<html>
<head><link href="interface design/css.css" rel="stylesheet" type="text/css"></head>
<body align="center">
<table class="ret"  width="400" border="0" cellpadding="3" cellspacing="1" background="interface design/logo/member.jpg">
<tr>
<td colspan="6" align="center"><strong>Reservatio History</strong> </td>
</tr>
<tr>
<td align="center">Reservation ID</td>
<td align="center"><strong>Check in Date</strong></td>
<td align="center"><strong>No. of nights</strong></td>
<td align="center"><strong>Room Number</strong></td>
<td align="center"><strong>Specials And Packages</strong></td>
<td align="center"><strong>Customer ID</strong></td>
</tr>
<?php
$pac = mysql_query("select pac_name from packages where pac_id ='(select pac_id from reservation)'");
while($rows=mysql_fetch_assoc($pac)){
$p=$row['pac_name'];

while($rows=mysql_fetch_assoc($result)){

?>
<tr>
<td><? echo $rows['Res_id'];?>			</td>
<td><? echo $rows['check_in'];?>		</td>
<td><? echo $rows['night_per_stay'];?>	</td>
<td><? echo $rows['R_no']; ?>			</td>
<td><? echo $rows['$p']; ?>			</td>
<td><? echo $rows['Cid']; ?>			</td>
</tr>
<?php
}
}
?>
</table>
</body>
</html>
<?mysql_close();?>

can i use 2 while?? like this...

coz i nid to rename the pac_id to pac_name which i will get the pac_name from packages table using the pac_id stored in reservation table...

 

Link to comment
https://forums.phpfreaks.com/topic/72092-solved-php-retrieve/
Share on other sites

ok i want to retrieve all the records in reservation table...

then display it in html table...

then i want to change the pac_id in to pac_name which i will get the pac_name in packages table...

u get wat i mean??

this is the code to get the pac name

$pac = mysql_query("select pac_name from packages where pac_id ='(select pac_id from reservation)'");

 

Link to comment
https://forums.phpfreaks.com/topic/72092-solved-php-retrieve/#findComment-363323
Share on other sites

well you could use a JOIN, like this

 

**UNTESTED

<?php
$pac = mysql_query("select packages.* , res.pac_name as PacName from packages LEFT JOIN reservation AS res ON packages.pac_id = res.pac_id");

while($rows=mysql_fetch_assoc($pac))
{
?>
<tr>
<td><? echo $rows['Res_id'];?>			</td>
<td><? echo $rows['check_in'];?>		</td>
<td><? echo $rows['night_per_stay'];?>	</td>
<td><? echo $rows['R_no']; ?>			</td>
<td><? echo $rows['PacName']; ?>			</td>
<td><? echo $rows['Cid']; ?>			</td>
</tr>
<?php
}
?>


Link to comment
https://forums.phpfreaks.com/topic/72092-solved-php-retrieve/#findComment-363324
Share on other sites

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.