With a lot of help from this site I now have a query that displays pages from several database tables, where $MyURL equals a page URL (e.g. MySite/Crazy_Horse matches the value Crazy_Horse in table people, field URL).
The only remaining problem is the static values (MySite2). I can't echo it on the display page. Yet it must be working, because if I comment out this line - $MySite2 = $row['MySite2']; - I get an error message saying $MySite2 hasn't been defined. But when I restore that line, the error message vanishes, yet echo $MySite2 doesn't display anything.
Can anyone see what I'm doing wrong?
$sql = "SELECT SUM(num) as num FROM (
SELECT 'GZ' AS MySite2, COUNT(Taxon) AS num FROM gz_life WHERE Taxon = :MyURL
UNION ALL
SELECT 'All' AS MySite2, COUNT(Name) AS num FROM gw_geog WHERE Name = :MyURL
UNION ALL
SELECT 'GS' AS MySite2, COUNT(URL) AS num FROM gs WHERE URL = :MyURL
) AS X";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':MyURL',$MyURL,PDO::PARAM_STR);
$stmt->execute();
while ($row = $stmt->fetch())
{
$MySite2 = $row['MySite2'];
$Total = $row['num'];
switch($Total)
{
case 1:
require($BaseINC."/$MyPHP/inc/C/2_Child.php");
break;
case 0:
require_once($BaseINC."/404.php");
break;
default:
require($_SERVER['DOCUMENT_ROOT']."/Dupe.php");
break;
}
}