close ad
WARNING: Do Not Install the DREAMWEAVER CC 2017 or 2018 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Help with inner join query

Thread began 8/12/2010 4:34 am by iainmacdonald331081 | Last modified 8/13/2010 3:40 am by iainmacdonald331081 | 2846 views | 16 replies |

iainmacdonald331081

Help with inner join query

This is probably slightly beyond DA's functionality, but thought I'd ask here anyway, as you guys have been great with support in the past, and hopefully isn't that complicated for the experts!

Basically I have the following table structure :

table : packages

packageID
package
packageDetails
etc

table : destinations

destinationID
destination
destinationDetails
etc

table : packagedestinations

packageID
destinationID

..so nothing that complicated.

So the idea is that I can have a package details page which shows the details of the package, along any destinations linked to that package via the packagedestinations table.

So this is the last part really - to get the page to display the destinations, but I'm missing something along the way, as I can't get the destinations to display on the page here :

packageDetailsTest3.php?packageID=128

This is the PHP from the header, including my INNER JOIN query....

php:
<?php 

$ParampackageID_WADApackages 
"-1"
if (isset(
$_GET['packageID'])) { 
  
$ParampackageID_WADApackages = (get_magic_quotes_gpc()) ? $_GET['packageID'] : addslashes($_GET['packageID']); 

$ParamSessionpackageID_WADApackages "-1"
if (isset(
$_SESSION['WADA_Insert_packages'])) { 
  
$ParamSessionpackageID_WADApackages = (get_magic_quotes_gpc()) ? $_SESSION['WADA_Insert_packages'] : addslashes($_SESSION['WADA_Insert_packages']); 

$ParampackageID2_WADApackages "-1"
if (isset(
$_GET['packageID'])) { 
  
$ParampackageID2_WADApackages = (get_magic_quotes_gpc()) ? $_GET['packageID'] : addslashes($_GET['packageID']); 

mysql_select_db($database_connPackages$connPackages); 
$query_WADApackages sprintf("SELECT packageID, package, costperpax, duration, baselocation, category, dateadded, agerange, hotel, educational_tours, field_trips, corporate_outings, plant_visits, budget_package, rollingtours, teambuilding, description, offer FROM packages WHERE packageID = %s OR ( -1= %s AND packageID= %s)"GetSQLValueString($ParampackageID_WADApackages"int"),GetSQLValueString($ParampackageID2_WADApackages"int"),GetSQLValueString($ParamSessionpackageID_WADApackages"int")); 
$WADApackages mysql_query($query_WADApackages$connPackages) or die(mysql_error()); 
$row_WADApackages mysql_fetch_assoc($WADApackages); 
$totalRows_WADApackages mysql_num_rows($WADApackages); 

$colname_educationalDestinations "1"
if (isset(
$_GET['PackageID'])) { 
  
$colname_educationalDestinations = (get_magic_quotes_gpc()) ? packageID addslashes(packageID); 

mysql_select_db($database_connPackages$connPackages); 
$query_educationalDestinations sprintf("SELECT * FROM destinations INNER JOIN (packages INNER JOIN packagedestinations ON packages.packageID = packagedestinations.packageID) ON destinations.destinationID = packagedestinations.destinationID WHERE packages.packageID = %s ORDER BY destination ASC"GetSQLValueString($colname_educationalDestinations"int")); 
$educationalDestinations mysql_query($query_educationalDestinations$connPackages) or die(mysql_error()); 
$row_educationalDestinations mysql_fetch_assoc($educationalDestinations); 
$totalRows_educationalDestinations mysql_num_rows($educationalDestinations); 
?>



And where I'm trying to display the destinations themselves, I have :

<table>
<tr>
<td>Destinations :</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_educationalDestinations['destination']; ?></td>
</tr>
<?php } while ($row_educationalDestinations = mysql_fetch_assoc($educationalDestinations)); ?>
</table>



If anyone could have a quick look and help me out that would be much appreciated - not sure if its my SQL at the top, or the PHP in the page, but either way it would be good to get it working.

Thanks.

Sign in to reply to this post

CraigRBeta Tester

at first glance, the query with the inner joins looks ok.

what i would do is try 2 things..

echo the select statement to the screen, to ensure it is as it should be, and if it looks ok, try pasting it into the sql window in phpmyadmin.

if this doesn't work, try doing the same thing without any filter criteria, to ensure you are getting some rows returned.

to get your sql statement to the screen, add the line

echo $query_educationalDestinations ;

immediately after

$totalRows_educationalDestinations = mysql_num_rows($educationalDestinations);

Sign in to reply to this post

iainmacdonald331081

OK - I can see where its going wrong, but not sure of the syntax to fix it...

echoing it generated the query :

SELECT * FROM destinations INNER JOIN (packages INNER JOIN packagedestinations ON packages.packageID = packagedestinations.packageID) ON destinations.destinationID = packagedestinations.destinationID WHERE packages.packageID = 1 ORDER BY destination ASC



So the problem is the very last part WHERE packages.packageID = 1

Which should presumably be WHERE packages.packageID = packagedestinationsID

Sign in to reply to this post

iainmacdonald331081

OK - so I changed the obvious, to make it :

SELECT * FROM destinations INNER JOIN (packages INNER JOIN packagedestinations ON packages.packageID = packagedestinations.packageID) ON destinations.destinationID = packagedestinations.destinationID WHERE packages.packageID = packagedestinations.packageID ORDER BY destination ASC



and that returned three of the four records.

If I specify the last packageID as '128' it returns the two correct records.

But if I specify it as 137 it only returns one of the two correct records.

Sign in to reply to this post

Jason ByrnesWebAssist

go back to the original query


the problem is the way the colname parmeter is set up. you have it configured as:
Name: colname
type: Number
default value: 1
Runtime value: $_GET['PackageID']


it should be configured as:
Name: colname
type: Number
default value: 1
Runtime value: $_GET['packageID']


notice the case of the 'p' in packageID.

PHP is a case sensitive language, $_GET['packageID'] is not the same as $_GET['PackageID']

If you would like a tool to help you find the correct INNER JOIN Syntax, Navicat has good visual query builder that help:
mysql_overview.html

Sign in to reply to this post

iainmacdonald331081

Thanks jason - you're a star! Will have a look at the Navicat site too.

Sign in to reply to this post

Jason ByrnesWebAssist

you're welcome.

Sign in to reply to this post

iainmacdonald331081

OK - now I'm going to need your help in getting the destinations on this page to appear in a grid layout as they do on the original page created by DA.

I'm going to assume it'll be reasonably straightforward for you to guide me through it...

Basically, this is the original page created by DA that lists the destinations on their own :

destinationstemp.php

(One issue there is the images extending beyond 182px wide, even though I've specified a width for the image. But that's less of a concern just now - I can add in some code to fix that that I've used in the past).

So I'd like the destinations to appear in that same grid layout on the package details page here :

packageDetailsTest4.php?packageID=140

I assume its just a case of reusing some code from the destinationstemp.php page - I could have a stab at it manually, but I'd likely mess it all up....

Presumably this is the code that sets it all up in the destinationstemp.php page :

<?php
$maxRows_WADAdestinations = 20;
$pageNum_WADAdestinations = 0;
if (isset($_GET['pageNum_WADAdestinations'])) {
$pageNum_WADAdestinations = $_GET['pageNum_WADAdestinations'];
}
$startRow_WADAdestinations = $pageNum_WADAdestinations * $maxRows_WADAdestinations;

mysql_select_db($database_connPackages, $connPackages);
$query_WADAdestinations = "SELECT destinationID, destination, description, shortdesc, image_main, image_2, image_3 FROM destinations ORDER BY destination ASC";
setQueryBuilderSource($query_WADAdestinations,$WADbSearch1,false);
$query_limit_WADAdestinations = sprintf("%s LIMIT %d, %d", $query_WADAdestinations, $startRow_WADAdestinations, $maxRows_WADAdestinations);
$WADAdestinations = mysql_query($query_limit_WADAdestinations, $connPackages) or die(mysql_error());
$row_WADAdestinations = mysql_fetch_assoc($WADAdestinations);

if (isset($_GET['totalRows_WADAdestinations'])) {
$totalRows_WADAdestinations = $_GET['totalRows_WADAdestinations'];
} else {
$all_WADAdestinations = mysql_query($query_WADAdestinations);
$totalRows_WADAdestinations = mysql_num_rows($all_WADAdestinations);
}
$totalPages_WADAdestinations = ceil($totalRows_WADAdestinations/$maxRows_WADAdestinations)-1;
?>
<?php
$queryString_WADAdestinations = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_WADAdestinations") == false &&
stristr($param, "totalRows_WADAdestinations") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_WADAdestinations = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_WADAdestinations = sprintf("&totalRows_WADAdestinations=%d%s", $totalRows_WADAdestinations, $queryString_WADAdestinations);
?>



But I'm not sure how to go about reusing it with the new query in the packageDetailsTest4.php page without messing it up.

I have at least changed the recordset name to WADAdestinations which should help.

I've attached a zip of both pages - if you could advise which code to use in the new page to achieve the grid layout I'd be very grateful.

Attached Files
Archive.zip
Sign in to reply to this post

CraigRBeta Tester

Hi Iain.

I haven't looked at the code posted, but looking at the pages, i think what you want to do is to create a repeating table, (4X3 or 4x2 perhaps)

if the recordset is in place, just go to Insert->WebAssist->DataAssist->Repeating Table, and go through the wizard

Sign in to reply to this post

iainmacdonald331081

Thanks Craig - I hadn't actually registered DA had that functionality - I had in my head it just did its thing creating all the search / results insert / update / delete pages.

So that's pretty much exactly what I'm looking for I think.

Unfortunately it wasn't that easy - I fired it up, but the wizard isn't seeing any recordset to use....

I've started a new thread on this issue rather than have it hidden away in this one, which has now been resolved.

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...