/    Sign up×
Community /Pin to ProfileBookmark

Selecting from two tables

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

[code=php]

<?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>”; ?>

<?

// 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>&nbsp;</td>
<td><? echo”$date”; ?></td>
<td>gg</td>
<td><? echo”$subject”; ?></td>
</tr>
?>
[/code]

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@legendxJun 18.2007 — SELECT * FROM business_info a INNER JOIN message b

ON a.BusinessName = b.BusinessName

rough idea
Copy linkTweet thisAlerts:
@franknuauthorJun 18.2007 — WEll, I dont understand, My main question is then

is this making any sense here

[code=php]

f($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>&nbsp;</td>
<td><? echo"$date"; ?></td>
<td>gg</td>
<td><? echo"$subject"; ?></td>
</tr>
?>
[/code]
Copy linkTweet thisAlerts:
@legendxJun 18.2007 — wow I was way off.. lol sorry..

try adding this line after the sql query that isn't working:
[code=php]die($sql);[/code]

this will give you an idea of what the query looks like after the variables are rendered.

It's also good practice to add mysql_error() after each query (atleast while you're still developing). So for example for each of your queries change it to mysql_query($sql) or die(mysql_error());

If there is a problem with one of your queries, this will help.
Copy linkTweet thisAlerts:
@poji23Jun 18.2007 — Hi,

I think instead of :

if($BusinessName=$_SESSION['BusinessName'])

maybe it's

if($BusinessName==$_SESSION['BusinessName'])

instead?
Copy linkTweet thisAlerts:
@franknuauthorJun 18.2007 — well i am getting this error now

Welcome MASS -AD Unknown column 'MASS' in 'where clause'

but i dont have colum name MASS anywhere that is just the
Copy linkTweet thisAlerts:
@franknuauthorJun 18.2007 — now i am not even getting any error message here is the new code

[code=php]

<?

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;

}
}


?>
[/code]
×

Success!

Help @franknu spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...