Senior & Expert PHP Developers Discussion Forum by Nyros Technologies

HIRE PHP Expert Developers Programmers Coders From India
PHP .Net Ruby on Rails Developers Community, Nyros Technologies, Kakinada
 
Log in  or IF not a member please REGISTER
Username:
Password:   


Keyword
Log in | Profile 

Having a problem with JOINS in my code - Help!

 
Post new topic   Reply to topic    Senior & Expert PHP Developers Discussion Forum by Nyros Technologies Index -> Help
View previous topic :: View next topic  
Author Message
CGDesigns



Joined: 19 Jan 2010
Posts: 2
Location: Oklahoma

PostPosted: Tue Jan 26, 2010 8:05 pm    Post subject: Having a problem with JOINS in my code - Help! Reply with quote

I seem to be having a problem trying to join in multiple tables. I was using the INNER JOIN clause since yesterday and it was working great. I had several tables joined in and everything seemed fine. I tried to add in another table and change some of the way the results returned as and then it wouldn't retrieve anything. So, I started rewriting the whole code to the point where it had last worked and now it won't work at all.

It's working fine pulling information from ONE table, but when I try to join in any other table, it doesn't work. What am I doing wrong??? Please help!

Here is the code I was using with all JOINs and it was working fantastic until right now. Do you see anything in it that shouldn't be in it??

<?php
   
   $dbHost = '********';
   $dbUser = '******';
   $dbPass = '********';
   $dbDatabase = '*****';
 

$search = $_POST['search'];

if ($search) // perform search only if a string was entered.
{
   $con = mysql_connect($dbHost, $dbUser, $dbPass) or die("Failed to connect to MySQL Server. Error: " . mysql_error());
   mysql_select_db($dbDatabase) or die("Failed to connect to database {$dbDatabase}. Error: " . mysql_error());
   
   
   $query = "SELECT asmnt_parcel.Account, asmnt_parcel.OwnersName, asmnt_parcel.ParcelID, asmnt_parcel.Township, asmnt_parcel.Range, asmnt_parcel.Section, asmnt_parcel.LotSize, asmnt_parcel.LotSizeType, asmnt_parcel.TaxAreaCode, asmnt_legal.Legal, cmn_name.Address2, cmn_name.City, cmn_name.State, cmn_name.ZipCode, asmnt_situs.Situs
           INNER JOIN asmnt_legal ON asmnt_parcel.Account=asmnt_legal.Account
           INNER JOIN cmn_name ON asmnt_parcel.OwnersName=cmn_name.OwnersName
           INNER JOIN asmnt_situs ON asmnt_parcel.Account=asmnt_situs.Account
             WHERE asmnt_parcel.Account = '{$search}' OR asmnt_parcel.OwnersName = '{$search}' OR asmnt_parcel.ParcelID = '{$search}' OR asmnt_legal.Legal = '{$search}'
             ORDER BY asmnt_parcel.Account";
   $result = mysql_query($query, $con);

   if ($result)
   {
      echo "Results:<br><br>";
      echo "<table width=90% align=center border=1><tr>
      <td align=center bgcolor=#4A6B3F>Account</td>
      <td align=center bgcolor=#4A6B3F>Owners Name</td>
      <td align=center bgcolor=#4A6B3F>Address</td>
      <td align=center bgcolor=#4A6B3F>City</td>
      <td align=center bgcolor=#4A6B3F>State</td>
      <td align=center bgcolor=#4A6B3F>Zip Code</td>
      <td align=center bgcolor=#4A6B3F>Legal</td>
      <td align=center bgcolor=#4A6B3F>Parcel ID</td>
      <td align=center bgcolor=#4A6B3F>Township</td>
      <td align=center bgcolor=#4A6B3F>Range</td>
      <td align=center bgcolor=#4A6B3F>Section</td>
      <td align=center bgcolor=#4A6B3F>Size</td>
      <td align=center bgcolor=#4A6B3F>Type</td>
      <td align=center bgcolor=#4A6B3F>School District</td>
      <td align=center bgcolor=#4A6B3F>Situs</td>
      </tr>";
   
      while ($r = mysql_fetch_array($result))
      { // Begin while
         $act = $r["Account"];
         $nme = $r["OwnersName"];
         $add = $r["Address2"]; 
         $city = $r["City"]; 
         $ste = $r["State"]; 
         $zip = $r["ZipCode"];
         $legal = $r["Legal"];   
         $pid = $r["ParcelID"];
         $tship = $r["Township"];
         $rng = $r["Range"];
         $sctn = $r["Section"];   
         $size = $r["LotSize"]; 
         $type = $r["LotSizeType"];
         $sch = $r["TaxAreaCode"];
         $sit = $r["Situs"];
         echo "<tr>
            <td>$act</td>
            <td>$nme</td>
            <td>$add</td>
            <td>$city</td>
            <td>$ste</td>
            <td>$zip</td>
            <td>$legal</td>
            <td>$pid</td>
            <td>$tship</td>
            <td>$rng</td>
            <td>$sctn</td>
            <td>$size</td>
            <td>$type</td>
            <td>$sch</td>
            <td>$sit</td>
            </tr>";
      } // end while
     
      echo "</table>";
   }
   else
   {
      echo "Sorry, please try your search again.";
   }
}
else
{
   echo "Start your search";
}
?>


This is what I've got with only pulling from one table right now that is working:

<?php
   
   $dbHost = '***********';
   $dbUser = '*******';
   $dbPass = '*********';
   $dbDatabase = '*********';
 

$search = $_POST['search'];

if ($search) // perform search only if a string was entered.
{
   $con = mysql_connect($dbHost, $dbUser, $dbPass) or die("Failed to connect to MySQL Server. Error: " . mysql_error());
   mysql_select_db($dbDatabase) or die("Failed to connect to database {$dbDatabase}. Error: " . mysql_error());
   
   
   $query = "SELECT OwnersName
             FROM asmnt_parcel
             WHERE asmnt_parcel.OwnersName = '{$search}'
             ORDER BY asmnt_parcel.OwnersName ASC";
   $result = mysql_query($query, $con);

   if ($result)
   {
      echo "Results:<br><br>";
      echo "<table width=90% align=center border=1><tr>
      <td align=center bgcolor=#4A6B3F>Owners Name</td>
      </tr>";
   
      while ($r = mysql_fetch_array($result))
      { // Begin while
         $name = $r["OwnersName"]; 
         echo "<tr>
            <td>$name</td>
            </tr>";
      } // end while
     
      echo "</table>";
   }
   else
   {
      echo "Sorry, please try your search again.";
   }
}
else
{
   echo "Start your search";
}
?>

Thanks!
Qadoshyah
Back to top
View user's profile Send private message Send e-mail Visit poster's website
rajkumar



Joined: 13 May 2008
Posts: 137

PostPosted: Wed Jan 27, 2010 10:07 am    Post subject: Reply with quote

Hi Qadoshyah,

I checked your sql query and code, I think there is a problem with sql query.

Query:
--------
$query = "SELECT asmnt_parcel.Account, asmnt_parcel.OwnersName, asmnt_parcel.ParcelID, asmnt_parcel.Township, asmnt_parcel.Range, asmnt_parcel.Section, asmnt_parcel.LotSize, asmnt_parcel.LotSizeType, asmnt_parcel.TaxAreaCode, asmnt_legal.Legal, cmn_name.Address2, cmn_name.City, cmn_name.State, cmn_name.ZipCode, asmnt_situs.Situs
INNER JOIN asmnt_legal ON asmnt_parcel.Account=asmnt_legal.Account
INNER JOIN cmn_name ON asmnt_parcel.OwnersName=cmn_name.OwnersName
INNER JOIN asmnt_situs ON asmnt_parcel.Account=asmnt_situs.Account
WHERE asmnt_parcel.Account = '{$search}' OR asmnt_parcel.OwnersName = '{$search}' OR asmnt_parcel.ParcelID = '{$search}' OR asmnt_legal.Legal = '{$search}'
ORDER BY asmnt_parcel.Account";

This is the query which you sent.

In this query there is no "FROM <TABLE NAME>".
I think you miss this statement .

Please add this "FROM" statement and check it, you can find the solution.

I hope this is the problem with this query. If not just post it what is the correct requirement.

Thank You,
Rajkumar
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Senior & Expert PHP Developers Discussion Forum by Nyros Technologies Index -> Help
Page 1 of 1

 latest topics 
 Topics   Replies   Author   Views   Last Post 
No new posts music portal script
0 realcoder 0 Thu Mar 11, 2010 8:42 pm
realcoder View latest post
No new posts DataExporter.php anybody make or tell
0 realcoder 3 Thu Mar 11, 2010 8:33 pm
realcoder View latest post
No new posts Email sending through PHP program
1 kumar1116 50 Thu Mar 11, 2010 10:29 am
AnilKumar View latest post
No new posts Php script to display the days between two dates?
1 Thirupathi 55 Thu Mar 11, 2010 9:09 am
Mike View latest post
No new posts display the date in given range
4 Mike 53 Thu Mar 11, 2010 5:31 am
Mike View latest post
No new posts how to add 20 minutes in past date
2 Mike 33 Wed Mar 10, 2010 1:29 pm
Mike View latest post
No new posts Get the random values from mysql
0 AnilKumar 14 Wed Mar 10, 2010 4:43 am
AnilKumar View latest post
No new posts About Expression Engine
1 Thirupathi 72 Mon Mar 08, 2010 2:31 pm
nih View latest post
No new posts content type=text/html and and image/jpeg in same php file?
3 Mike 79 Fri Mar 05, 2010 5:16 am
AnilKumar View latest post
No new posts how to create xls file using mysql and php?
4 AnilKumar 2799 Fri Mar 05, 2010 5:08 am
AnilKumar View latest post





Hire an expert PHP developer / coder / programmer or development team from India now!!

Other Forums : Ruby on Rails   ::   .Net   |   Free unlimited HTML CSS Joomla Wordpress Drupal templates download

Nyros Technologies   |   Developers Blog   |   Kakinada City Portal   |   About PHP Experts   |   More