Jump to content

Help with a Joined Query


datoshway

Recommended Posts

Below is my query, I have a column called boolActivate in my tblProperties table but I can't figure out how to put in a where clause so it reads something like WHERE boolActivate = 1

 

 

$strQuery = sprintf( "SELECT p.*, a.strAreaName FROM tblProperties p LEFT JOIN tblAreas a ON p.intAreaID = a.intID WHERE p.intID = %d", intval($intPropertyID));

 

Using MYSQL 5

Edited by datoshway
Link to comment
Share on other sites

It's not in my query.  The problem is when I put it in the query like:  

 

$strQuery = sprintf( "SELECT p.*, a.strAreaName FROM tblProperties p LEFT JOIN tblAreas a ON p.intAreaID = a.intID WHERE p.intID = %d AND p.boolActivate = 1", intval($intPropertyID));

 

it doesn't work. 

Link to comment
Share on other sites

“Doesn't work”? Can you be a bit more specific?  ::)

 

What is the problem? What's the expected result, and what's the actual result? We don't know anything about your project or the data you're working with, so if you want us to help you, then we need concrete info.

 

Have you echoed the resulting query and tried it in phpmyadmin?

Edited by Jacques1
Link to comment
Share on other sites

Sure thing.  

 

Below is my full query.  This is for a detail page on a real estate website.  So if boolActivate=0 then the property should not display anything. 

$strQuery = sprintf( "SELECT p.*, a.strAreaName FROM tblProperties p LEFT JOIN tblAreas a ON p.intAreaID = a.intID WHERE p.intID = %d AND p.boolActivate = 1", intval($intPropertyID));
$queryGetProperty = $objDatabase->query($strQuery);

if ($objDatabase->num_rows($queryGetProperty) > 0) {
$arrRow = $objDatabase->fetch_assoc($queryGetProperty);
extract($arrRow);

if (strlen($dtDateAvailable) > 0) {
$dtDateAvailable = date("m/d/y", strtotime($dtDateAvailable));
}
if (strlen($dtDateAvailableSummer) > 0) {
$dtDateAvailable = date("m/d/y", strtotime($dtDateAvailableSummer));
}
if (strlen($dtDateAvailableWinter) > 0) {
$dtDateAvailable = date("m/d/y", strtotime($dtDateAvailableWinter));
}
}

$objDatabase->free_result($queryGetProperty);

$strQuery = sprintf( "SELECT * FROM tblPropertiesPhotos WHERE intPropertyID = %d", intval($intPropertyID));
$queryGetPhotos = $objDatabase->query($strQuery);

Below is a sample echo on the page for part of the content.

<?php 
								if (($dblPriceYearly > 0) && (strlen($dtDateAvailable) > 0)) {
									echo date("m/d/y", strtotime($dtDateAvailable)) . " (Y) ";
								}
								if (($dblPriceSummer > 0) && (strlen($dtDateAvailableSummer) > 0)) {
									echo date("m/d/y", strtotime($dtDateAvailableSummer)) . " (S) ";
								}
								if (($dblPriceWinter > 0) && (strlen($dtDateAvailableWinter) > 0)) {
									echo date("m/d/y", strtotime($dtDateAvailableWinter)) . " (W)";
								}
							?>

What i'm getting is a detail page with all the relaivant info.  I am looking for it to error out and not display any info just as it would if you went to the page and put in an incorrect ?=ID

Edited by datoshway
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.