aian04 Posted October 6, 2007 Share Posted October 6, 2007 <?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... Quote Link to comment https://forums.phpfreaks.com/topic/72092-solved-php-retrieve/ Share on other sites More sharing options...
MadTechie Posted October 6, 2007 Share Posted October 6, 2007 what are you trying to do ? also <td><? echo $rows['$p']; ?> should be <td><? echo $rows[$p]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/72092-solved-php-retrieve/#findComment-363319 Share on other sites More sharing options...
aian04 Posted October 6, 2007 Author Share Posted October 6, 2007 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)'"); Quote Link to comment https://forums.phpfreaks.com/topic/72092-solved-php-retrieve/#findComment-363323 Share on other sites More sharing options...
MadTechie Posted October 6, 2007 Share Posted October 6, 2007 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/72092-solved-php-retrieve/#findComment-363324 Share on other sites More sharing options...
aian04 Posted October 6, 2007 Author Share Posted October 6, 2007 yah.. u gave an idea to solve it... use join statement... tnx.. Quote Link to comment https://forums.phpfreaks.com/topic/72092-solved-php-retrieve/#findComment-363415 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.