I am aware of how to carry out multiple conditions in an if statement (using &&), but I seem to be stuck here. On my website I currently have a subtitle function which appends to the site name in the title bar (i.e. Site Name > About), and there is a part of my website which I used search parameters and am now unable to figure out how to properly sort out the subtitles. Here's the query I have: $searchType='AND'; $conquery =''; $conquery .= (isset($_GET['name']) && !empty($_GET['name']) ? $searchType." `brand`='" . mysql_real_escape_string($_GET['brand']) . "' " : ''); $conquery .= (isset($_GET['color']) && !empty($_GET['color']) ? $searchType." `type`='" . mysql_real_escape_string($_GET['type']) . "' " : ''); $conquery .= (isset($_GET['size']) && !empty($_GET['size']) ? $searchType." `year`='" . mysql_real_escape_string($_GET['year']) . "' " : ''); if(trim($conquery)=="") { $query = "(select * from table_1) union (select * from table_2) union (select * from table_3) order by datetime desc "; } else { $conquery=substr($conquery,strlen($searchType)); $query = "(select * from table_1 WHERE $conquery) union (select * from table_2 WHERE $conquery) union (select * from table_3 WHERE $conquery) order by datetime desc "; } $result = mysql_query($query, $connection) or die ("Could not execute query : $query ." . mysql_error()); PHP: What I wish to do is have the subtitle correspond to the $conquery results. If I have my search results sorted by the color orange, I want my subtitle to be "Orange", and if I have my search results sorted by the size large, I want my subtitle to be "Large", however if I have my search results sorted by the color orange and the size large, I want my subtitle to be "Large > Orange". What is the best way to do this? I have tried something along the lines of (and several variations of): if(trim($conquery)=='') { $subtitle = "Results" ; } elseif($size=='$size' && $color=='$color') { $subtitle = "» $size » $color" ; } elseif($name=='$name' && $size=='$size' && $color=='$color') { $subtitle = "» $name » $size » $color" ; } elseif($name=='$name') { $subtitle = "» $name" ; } elseif($color=='$color') { $subtitle = "» $color" ; } elseif($size=='$size') { $subtitle = "» $size" ; } PHP: Many thanks in advance.
Hi, thanks for replying. Okay, I'll try and explain my problem as clearly as possible. In a file (I'll refer to it as file.php), I have the first query I posted. I'm using $conquery to sort the information that is in the tables in $query via search parameters. Separately, I have subtitles that go in my title bar that come after the site name, like "Site Name > $subtitle", which is used to allow the visitor to know where they are on the website. However, on the file.php page, I want the $subtitle to echo what the visitor searched for ($conquery). For example, if $conquery is $color = "orange", I want $subtitle to be "orange", so it will display "Site Name > Orange" in my title bar. Where my problem is, is that I don't know how to get $subtitle to echo $conquery results. If NOTHING is searched for (as in you go to the plain file.php page), I have it $subtitle = page name, but if I search for something (such as color), I want $subtitle to become the SEARCH terms. If I put $subtitle = "$conquery" it DOES display the search terms, but it displays as "$color = `orange`" instead of just "orange". I hope I explained clearly enough, but if it helps to have an example page, I can provide one, because I know that what I am asking is confusing.
Try this... $subtitle = ""; if ((isset($_GET['name']) && !empty($_GET['name'])) $subtitle .= "» ".$_GET['name']; if ((isset($_GET['size']) && !empty($_GET['size'])) $subtitle .= "» ".$_GET['size']; if ((isset($_GET['color']) && !empty($_GET['color'])) $subtitle .= "» ".$_GET['color']; if($subtitle=='') $subtitle = "Results" ; PHP: