Jump to content

Selecting from tow diffrent tables


franknu

Recommended Posts

Ok, i have tow diffrent tables and  i want to display the values for table name message that

match the value for colum BusinessName on table name business_info and message

 

i have two query the first one works but the second one is not dispalying values

 

here is my code

 

 

 


<?php
session_start(); 
$_SESSION['User_Name'];
$_SESSION['Password']; 
$_SESSION['BusinessName'];

?>
<html>
<head>
<body>
<?

if ( isset($_SESSION['User_Name']) && isset ($_SESSION['Password']) )
{

$query = "SELECT * FROM business_info where User_Name='".$_SESSION['User_Name']."' AND Password='".$_SESSION['Password']."'" ;
$result=mysql_query($query);

}

  if ($result = mysql_query($query)) 
{
  if (mysql_num_rows($result))
{
      $row = mysql_fetch_assoc($result);

      $BusinessName= $row['BusinessName'];
      $Keyword = $row['Keyword'];
      $Picture1 =  $row['Picture1'];
      $Headline = $row['Headline'];
      $Slogan =$row['Slogan'];
      $Slogan2 = $row['Slogan2'];
      $Description1 =$row['Description1'];
      $Description2 = $row['Description2'];
      $Description3= $row['Description3'];
      $Contact2 =  $row['Contact2'];
      $Picture2 = $row['Picture2'];
      $Picture3 = $row['Picture3'];
      $Categories=$row['Categories'];
      $Business_Address= $row['Business_Address'];
      $make=$row['make'];
      $type=$row['type'];
      $Tel= $row['Tel'];
      $Website=$row['Website'];
   } 
else 
{
      echo "<p><b>username and/or password not found. Try
again?

</b></p>";
exit;
    }
  } 
else 
{
  echo "Query failed<br />$query<br />". mysql_error();
exit;
  }



?>



<table width="504" border="1" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC">
  <tr>
    <td width="494">

<table width="497" border="0" bgcolor="#FFFFFF">
      <tr>
        <td width="487">Banner</td>
      </tr>
      <tr>
  


   
<td background="fondo2.jpg">
<? echo " Welcome  <b>$BusinessName </b>"; 
$_SESSION['User_Name'];
$_SESSION['Password']; 
$_SESSION['BusinessName'];
?> 
<?

// This is the query that is not displaying any values any idea how i should fix this
if($BusinessName=$_SESSION['BusinessName'])
{
$sql= "SELECT * FROM messages WHERE $BusinessName='".$_SESSION['BusinessName']."' ";

$result=mysql_query($sql);
}

if ($result = mysql_query($query)) 
{
  if (mysql_num_rows($result))
{
      $row = mysql_fetch_assoc($result);
      $BusinessName= $row['BusinessName'];
      $date = $row['date'];
      $from =  $row['from'];
      $subject = $row['subject'];
      $message =$row['message'];
}
}

?>
   <tr>
                        <td><input type="checkbox" name="checkbox" value="checkbox"></td>
                        <td> </td>
                        <td><? echo"$date"; ?></td>
                        <td>gg</td>
                        <td><? echo"$subject"; ?></td>
                      </tr>
?>

Link to comment
https://forums.phpfreaks.com/topic/56057-selecting-from-tow-diffrent-tables/
Share on other sites

I made some changes to the code maybe i was going to get something diffrent and still, i didnt get anything

 

here is my code

 


<?

if( isset($_SESSION['BusinessName']))
{
$sql= "SELECT * FROM messages WHERE $BusinessName='".$_SESSION['BusinessName']."' ";

$result=mysql_query($sql);
}

if ($result = mysql_query($query)) 
{
  if (mysql_num_rows($result))
{
      $row = mysql_fetch_assoc($result);
      $BusinessName= $row['BusinessName'];
      $date = $row['date'];
      $from =  $row['from'];
      $subject = $row['subject'];
      $message =$row['message'];
}
}

?>

ok i made some changes and some error display

 

here is my new code

 

i am still not getting anything


<?

if( isset($_SESSION['BusinessName']))
{
$sql= "SELECT * FROM messages WHERE $BusinessName='".$_SESSION['BusinessName']."' "; 
mysql_query($sql) or die(mysql_error());


$result=mysql_query($sql);
}

if ($result = mysql_query($sql)) 
{
  if (mysql_num_rows($result))
{
      $row = mysql_fetch_assoc($result);
      $BusinessName= $row['BusinessName'];
      $date = $row['date'];
      $from =  $row['from'];
      $subject = $row['subject'];
      $message =$row['message'];
  }
else 
{
      echo "Query failed<br />$sql<br />". mysql_error();

exit;

}
}


?>

 

 

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.