DiigIT | IT Community
No Profile Image
Welcome Guest
New User? Register | Login

combining tables

By: | 26 Dec 2010 2:39 am

Dear sir / madam

How do i merge/combine  this query:

"SELECT ".$GLOBALS['pages'].".*, ".$_SESSION['pages_content'].".title, ".$_SESSION['pages_content'].".label FROM ".$GLOBALS['pages'].", ".$_SESSION['pages_content']." WHERE".
        " ".$GLOBALS['pages'].".menu='top' AND ".$_SESSION['pages_content'].".parent = ".$GLOBALS['pages'].".ID AND ".$GLOBALS['pages'].".parent = '".$parent."' order by ".$GLOBALS['pages'].".sequence ASC"      
 

Into this one:
 //"SELECT a.ID, a.parent, a.title, a.label, a.link, a.sequence, Deriv1.Count  FROM ".$GLOBALS['pages']." a  LEFT OUTER JOIN (SELECT parent, COUNT(*) AS Count FROM ".$GLOBALS['pages']." WHERE menu='top' GROUP BY parent) Deriv1 ON a.ID = Deriv1.parent WHERE a.parent=" . $parent1 . " AND menu='top' order by sequence ASC"

The last query works but i need to replace the title and label data form another table (pages_content) as is done in the first query

how on earth can i combine the two or fit in two? left outer joins
Any help would be appreciated.

Sincerly K.
 

Comments

Ive got it

Here u go after hours of pain ive got the query for the following function to print out a list with

values from a main table with data and a language or content tabel with title and urllabel in a session 

Download a copy of ddsmoothmenu and enjoy

$query = "SELECT a.ID, a.parent, (SELECT title FROM ".$_SESSION[\'pages_content\']." WHERE parent = a.ID) as title, (SELECT label FROM ".$_SESSION[\'pages_content\']." WHERE parent = a.ID) as label, a.link, a.sequence, Deriv1.Count  FROM ".$GLOBALS[\'pages\']." a  LEFT OUTER JOIN (SELECT parent, COUNT(*) AS Count FROM ".$GLOBALS[\'pages\']." WHERE menu=\'top\' GROUP BY parent) Deriv1 ON a.ID = Deriv1.parent WHERE a.parent=" . $parent1 . " AND menu=\'top\' order by sequence ASC";
 

This is the function

function menutop($parent1, $id) { 

 $resultmax = mysql_query("SELECT max(sequence) as maxseq FROM ".$GLOBALS[\'pages\']." WHERE (parent=\'$parent1\' AND menu=\'top\') order by sequence ASC")
 or die("Query failed : " . mysql_error());
 $linemax = mysql_fetch_assoc($resultmax);
 $maxseq = $linemax[\'maxseq\'];
 
 $resultcount = mysql_query("SELECT count(ID) as countid FROM ".$GLOBALS[\'pages\']." WHERE (parent=\'$parent1\' AND menu=\'top\' ) order by sequence ASC")
 or die("Query failed : " . mysql_error());
 $linecount = mysql_fetch_assoc($resultcount);
 $countid = $linecount[\'countid\'];
 
 $query = "SELECT a.ID, a.parent, (SELECT title FROM ".$_SESSION[\'pages_content\']." WHERE parent = a.ID) as title, (SELECT label FROM ".$_SESSION[\'pages_content\']." WHERE parent = a.ID) as label, a.link, a.sequence, Deriv1.Count  FROM ".$GLOBALS[\'pages\']." a  LEFT OUTER JOIN (SELECT parent, COUNT(*) AS Count FROM ".$GLOBALS[\'pages\']." WHERE menu=\'top\' GROUP BY parent) Deriv1 ON a.ID = Deriv1.parent WHERE a.parent=" . $parent1 . " AND menu=\'top\' order by sequence ASC";

 $result = mysql_query($query);

 echo "<ul>\\n";

 while ($row = mysql_fetch_assoc($result)) { 

 if(strlen($row[\'title\'])>30){$row[\'title\'] = "".substr($row[\'title\'],0,30)."...";}

 $class = "menuitem";
 if($row[\'parent\']==0 && $row[\'sequence\']==1) {
 $class = "menublanc";
 }elseif($row[\'parent\']==0) {
 $class = "menuwhite"; 
 }elseif($row[\'sequence\']<=1){
 $class = "menutop"; 
 }elseif($row[\'sequence\'] == $maxseq){
 $class = "menubottom";   
 }
 if($countid==1 && $row[\'parent\']!=0){
 $class = "menusingle";   
 } 
 if($id==$row[\'ID\']){
 $row[\'title\']=\'<font color="#A58538">\'.$row[\'title\'].\'</font>\';
 }
 GetTrail($id);
 if (in_array($row[\'ID\'], $GLOBALS[\'trail\'])) {
 $row[\'title\']=\'<font color="#666666">\'.$row[\'title\'].\'</font>\';
 }
 if($row[\'link\']=="leeg"){
 $url = "#";
 } else {
 $url = $GLOBALS[\'abs_url\']. $row[\'label\'] ;
 }

if ($row[\'Count\'] > 0) { 

 
echo "<li><span class=\\"".$class."\\"><a href=\\"" .$url . "\\">" . $row[\'title\'] . "</a></span>\\n";

menutop($row[\'ID\'], $id); 

echo "</li>\\n"; 

} elseif ($row[\'Count\']==0) { 

  echo "<li><span class=\\"".$class."\\"><a href=\\"" .$url . "\\">" . $row[\'title\'] . "</a></span></li>\\n";

} else; 


echo "</ul>\\n"; 
}

By: | 26 Dec 2010

Leave a comment

Enter the text in the image
img
Can't read?
Type the characters you see in the picture below.


Close Move