OK, I think I basically understand your script, though I'm doing something wrong.
Below is my entire master query, which is actually a series of queries. I'll try to simplify it as I learn more about it. But if you scroll down, you'll see your script at the end.
PHP Code:
<?php
$qry = "SELECT * FROM basics as b, famarea as f
WHERE f.IDArea = b.IDArea AND f.IDArea = '$mycode'";
$result = mysql_query($qry);
// For troubleshooting:
$result = mysql_query($qry) or die('Error: '.mysql_error());
$type = mysql_fetch_array($result);
$mytype = "my" . $type['TypeArea'];
$$mytype = $type['Name'];
if (phpversion() <= "4.1.0") { $vars = array_merge($HTTP_GET_VARS, $HTTP_POST_VARS); } else { $vars = $_REQUEST; }
$area_code_sql = mysql_query("SELECT * FROM basics as b, famarea as f
WHERE f.IDArea = b.IDArea AND f.IDArea = '".$mycode);
$type = mysql_fetch_assoc($result);
$mytype = "my" . $type['TypeArea'];
$data = array();
$data_details = mysql_fetch_assoc(mysql_query("SELECT *
FROM famarea WHERE IDArea = '$mycode'"));
$query = "SELECT famarea.*, basics.* FROM famarea, basics
WHERE famarea.IDArea = basics.IDArea AND famarea.IDArea = '$mycode'";
$data = array();
if ($res = mysql_query($query)) { while ($temp = mysql_fetch_assoc($res)) { $data[] = $temp;} };
$foo = array("us-", "ca-", "jp-");
$mycode = str_replace($foo, "", $mycode);
$SymClass = mysql_fetch_assoc(mysql_query("SELECT F.IDArea, F.Name, S.IDArea, S.DesigGeneral,
S.SymClass, S.Class, S.Order, S.ClassCommon
FROM famarea AS F, symbols as S WHERE F.IDArea = S.IDArea AND SymClass = 'animals' AND S.SymClass LIKE '$mycode%'"));
$Class = mysql_fetch_assoc(mysql_query("SELECT F.IDArea, F.Name, S.IDArea, S.DesigGeneral,
S.SymClass, S.Class, S.Order, S.ClassCommon
FROM famarea AS F, symbols as S WHERE F.IDArea = S.IDArea AND SymClass = 'animals' AND S.Class LIKE '$mycode%'"));
$Order = mysql_fetch_assoc(mysql_query("SELECT * FROM symbols as S
WHERE S.SymClass = 'animals' AND S.Order LIKE '$mycode%' AND S.Class LIKE '$mycode2%'"));
$Family = mysql_fetch_assoc(mysql_query("SELECT F.IDArea, F.Name, S.IDArea, S.DesigGeneral,
S.SymClass, S.Class, S.Order, S.Family, S.Genus, S.Species, S.ClassCommon, S.FamilyCommon
FROM famarea AS F, symbols as S WHERE F.IDArea = S.IDArea AND SymClass = 'animals' AND S.Family LIKE '$mycode%' AND S.Order LIKE '$mycode2%'"));
// YOUR SCRIPT...
$sql = "SELECT * FROM symbols as S
WHERE CONCAT( MID(S.Class, 1,3), '-', MID(S.Order, 1,3), '-', MID(S.Family, 1,3), '-', MID(S.Genus, 1,3))
LIKE '%" . $first . "-" . $second . "%'";
$Animals = mysql_fetch_assoc(mysql_query($sql));
?>
And here's how I'm trying to plug it in. Let's start with a page focusing on the cat family (Felidae), which includes this in the head section:
$mycode = 'Fel';
$mycode2 = 'Car';
Next, here's an included PHP switch that focuses on each row's class (field Class):
PHP Code:
<?php
switch ($Animals['Class']) {
case 'Mammalia':
include($_SERVER['DOCUMENT_ROOT'] . '/a1/articles/ani/mammals.php');
break;
case 'Reptilia':
include($_SERVER['DOCUMENT_ROOT'] . '/a1/articles/ani/reptiles.php');
break;
default:
break;
}
?>
I try to connect to a row by matching the first three letters of two successive table fields. After I get a match, I link that row's value in the Class field to the PHP switch above, so everything that's class Mammalia is linked to the mammals page at mammals.php.
$mycode = 'Fel'; + $mycode2 = 'Car'; combines to form CarFel, which belongs to class Mammalia.
I suspect your script isn't working for me for one of two reasons:
1) I haven't plugged in $mycode2 + $mycode...
PHP Code:
$sql = "SELECT * FROM symbols as S
WHERE CONCAT( MID(S.Class, 1,3), '-', MID(S.Order, 1,3), '-', MID(S.Family, 1,3), '-', MID(S.Genus, 1,3))
LIKE '%" . $first . "-" . $second . "%'";
$Animals = mysql_fetch_assoc(mysql_query($sql));
I think the script should look something like this:
PHP Code:
$sql = "SELECT * FROM symbols as S
WHERE CONCAT( MID(S.Class, 1,3), '-', MID(S.Order, 1,3), '-', MID(S.Family, 1,3), '-', MID(S.Genus, 1,3))
LIKE '%" . $first . "-" . $second . "%'
// Here's what I added...
AND the resulting six-letter code = $mycode2 + $mycode [e.g. "felcar"]";
$Animals = mysql_fetch_assoc(mysql_query($sql));
2) The other possible reason may be this '-' Does this insert a hyphen between the two abbreviations, like this?: car-fel? Actually, it may not matter; I think the most important thing now is simply connecting your script to $mycode2 + $mycode.
Thanks.
Bookmarks