Jump to content

displaying from multiple tables


ronnie88

Recommended Posts

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

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

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);
}
?>

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.