PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
franknu
Forum Contributor
Posts: 146 Joined: Sun May 28, 2006 9:29 am
Post
by franknu » Mon Jun 18, 2007 10:35 am
Ok, i have tow diffrent tables and i want to display the values for table named message that
match the value for colum BusinessName on table named 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: Select all
<?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> </td>
<td><? echo"$date"; ?></td>
<td>gg</td>
<td><? echo"$subject"; ?></td>
</tr>
?>
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Mon Jun 18, 2007 10:44 am
What are you trying to achieve with the last three lines of
franknu wrote: <?php
session_start();
$_SESSION['User_Name'];
$_SESSION['Password'];
$_SESSION['BusinessName'];
?
franknu
Forum Contributor
Posts: 146 Joined: Sun May 28, 2006 9:29 am
Post
by franknu » Mon Jun 18, 2007 10:48 am
I am starting a session there which i initially started at another page that is like administration page.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Mon Jun 18, 2007 10:49 am
session_start() is starting the session mechanism, all right.
But what are the three line after session_start() for?
franknu
Forum Contributor
Posts: 146 Joined: Sun May 28, 2006 9:29 am
Post
by franknu » Mon Jun 18, 2007 11:18 am
oh, this is how i know what i am calling, just to remind myself i can eliminate them , it doesnt make any diffrents
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Mon Jun 18, 2007 3:17 pm
franknu wrote: Code: Select all
...
$result=mysql_query($sql);
}
if ($result = mysql_query($query))
{
...
You call your new query, then put the old query back into $result.
Gente
Forum Contributor
Posts: 252 Joined: Wed Jun 13, 2007 9:43 am
Location: Ukraine, Kharkov
Contact:
Post
by Gente » Mon Jun 18, 2007 5:45 pm
You can open the MySQL and read something about LEFT JOIN or INNER JOIN.
And...
Code: Select all
...
// 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']."' ";
...
Be attentive with conditions
alimadzi
Forum Newbie
Posts: 9 Joined: Fri Jun 08, 2007 12:57 pm
Location: Boise, Idaho, USA
Post
by alimadzi » Mon Jun 18, 2007 6:20 pm
Gente wrote: You can open the MySQL and read something about LEFT JOIN or INNER JOIN.
And...
Code: Select all
...
// 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']."' ";
...
Be attentive with conditions
In case you don't catch what he's talking about, you need to replace the "=" with "==" in your if test. A single equal sign is an assignment operator while a double equal sign is a test for equality.
franknu
Forum Contributor
Posts: 146 Joined: Sun May 28, 2006 9:29 am
Post
by franknu » Mon Jun 18, 2007 8:04 pm
well, i made some changes but still not displaying :
here is my new code:
Code: Select all
if( isset($BusinessName))
{
$sql=" SELECT business_info.BusinessName, messages.BusinessName FROM business_info, messages
WHERE business_info.BusinessName=messages.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;
}
}
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Jun 18, 2007 8:57 pm
The query may be executed three times. Why?
$BusinessName isn't used.
franknu
Forum Contributor
Posts: 146 Joined: Sun May 28, 2006 9:29 am
Post
by franknu » Mon Jun 18, 2007 9:08 pm
well, i am selecting from two diffrent tables one called business_info and messages
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Jun 18, 2007 9:11 pm
franknu wrote: well, i am selecting from two diffrent tables one called business_info and messages
That doesn't explain three query executions. Was it supposed to?
franknu
Forum Contributor
Posts: 146 Joined: Sun May 28, 2006 9:29 am
Post
by franknu » Mon Jun 18, 2007 9:19 pm
can you explain better because i dont see what i am doing wrong, i reads good to me. maybe the way , it is set up is not the best for me
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Jun 18, 2007 9:43 pm
You have three mysql_query() back-to-back without any modification of the call. You only need one.