Jump to content

Creating a query using case statement


ibright

Recommended Posts

Here is what I have and I don't understand why it is not working. Have search the internet for two nights can't seem to fix it. ANY HELP, would be greatly appreciated.

 

// Make a MySQL Connection

mysql_connect($host, $user, $password) or die(mysql_error());

mysql_select_db($database) or die(mysql_error());

 

$pageType = $_GET['variable'];

 

switch($pageType)

{

 

case "Stallion" or "Mare":

// Retrieve all the data from the "Horses" table and joins Sire & Dam Table.

$query = "SELECT * FROM Horses, SirePedigree, DamPedigree WHERE Horses.sireId=SirePedigree.sireId AND Horses.damId=DamPedigree.damId AND Horses.sex= '$pageType'";

break;

 

case "Owned":

$query = "SELECT * FROM Horses, SirePedigree, DamPedigree WHERE Horses.sireId=SirePedigree.sireId AND Horses.damId=DamPedigree.damId AND Horses.status= '$pageType'";

break;

 

default:

echo "You are at Eyebright farm";

break;

}

 

$result = mysql_query($query)

or die(mysql_error());

Link to comment
https://forums.phpfreaks.com/topic/184497-creating-a-query-using-case-statement/
Share on other sites

What error are you getting?

Is it a problem with the switch?

 

How about:

 

case "Stallion":
case "Mare":
// Retrieve all the data from the "Horses" table and joins Sire & Dam Table.
$query = "SELECT * FROM Horses, SirePedigree, DamPedigree WHERE Horses.sireId=SirePedigree.sireId AND Horses.damId=DamPedigree.damId AND Horses.sex= '$pageType'";
break;

Archived

This topic is now archived and is closed to further replies.

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