ronnie88 Posted July 30, 2008 Share Posted July 30, 2008 hi im trying to display from multiple tables but having no luck in my header: <?php session_start(); include("database.php"); if($_SESSION['username']) { $query = "SELECT * FROM prequestions, orders"; $result = mysql_query($query); } ?> displaying the data <? while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "Name : {$row['name']} <br>" . "Contact : {$row['email']} <br>" . "Phone : {$row['phone']} <br>" . "Message : {$row['message']} <br>"; } while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "Name : {$row['name2']} <br>" . "Contact : {$row['email2']} <br>" . "Phone : {$row['phone2']} <br>" . "URL TO LOGO : {$row['url']} <br>"; } the first set is to display the info from the prequestions table and the second set is for getting info from the orders table but when I try this everything disappears if i take away the first set it works fine, also when i take away the first set work just fine. thanks! Link to comment https://forums.phpfreaks.com/topic/117280-displaying-from-multiple-tables/ Share on other sites More sharing options...
p2grace Posted July 30, 2008 Share Posted July 30, 2008 Don't user the *, specify the field names. If the field names overlap use the 'AS' command to change the name of the field. Link to comment https://forums.phpfreaks.com/topic/117280-displaying-from-multiple-tables/#findComment-603276 Share on other sites More sharing options...
ronnie88 Posted July 30, 2008 Author Share Posted July 30, 2008 nope header: <?php session_start(); include("database.php"); if($_SESSION['username']) { $query = "SELECT name, email, phone, message, name2, email2, phone2, url FROM prequestions, orders"; $result = mysql_query($query); } ?> display: <?php if($_SESSION['username'] == ronnie) { ?> <form action="reginsert.php" method="post"> <br><tr><td>UserName:</td><td><input type="text" name="name" maxlength="25"></td> <tr><td>Registration Code:</td><td><input type="text" name="regis" maxlength="25"></td><br> <td><input name="add" type="submit" id="add" value="Set Registration Key"></td></form></tr> <br> <td>----------------------------------------------</td><br> <br> <form action="insertproject.php" method="post"> <br><tr><td>UserName:</td><td><input type="text" name="name2" maxlength="25"></td> <tr><td>Project(Only if Payment is processed):</td><td><input type="text" name="project" maxlength="25"></td><br> <td><input name="add2" type="submit" id="add2" value="Send Project"></td> <form></tr> <br><br><strong>Orders & Questions</strong><br><br> <td>----------------------------------------------</td><br> <td><tr><? while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "Name : {$row['name']} <br>" . "Contact : {$row['email']} <br>" . "Phone : {$row['phone']} <br>" . "Message : {$row['message']} <br>"; } while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "Name : {$row['name2']} <br>" . "Contact : {$row['email2']} <br>" . "Phone : {$row['phone2']} <br>" . "URL TO LOGO : {$row['url']} <br>"; } } else{ echo "YOU ARE NOT AN ADMIN!"; } ?> thanks Link to comment https://forums.phpfreaks.com/topic/117280-displaying-from-multiple-tables/#findComment-603277 Share on other sites More sharing options...
ronnie88 Posted July 30, 2008 Author Share Posted July 30, 2008 friendly bump Link to comment https://forums.phpfreaks.com/topic/117280-displaying-from-multiple-tables/#findComment-603372 Share on other sites More sharing options...
p2grace Posted August 1, 2008 Share Posted August 1, 2008 You need to specify the table name in the fields and the relationship in a where statement. <?php session_start(); include("database.php"); if($_SESSION['username']) { $query = "SELECT `p`.`name`, `p`.`email`, `p`.`phone`, `p`.`message`, `o`.`name2`, `o`.`email2`, `o`.`phone2`, `o`.`url` FROM `prequestions` p, `orders` o WHERE `p`.`somefield` = `o`.`somefield`"; $result = mysql_query($query); } ?> Link to comment https://forums.phpfreaks.com/topic/117280-displaying-from-multiple-tables/#findComment-605467 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.