du2986
du2986
2019-03-24 22:38

如何将案例切换mySQL查询的结果回显到span标记内的表中

  • php
  • html
  • mysql

I need to take the users input from the select box for Allergen1 once an option is selected and the user clicks submit a query will run based upon the selected value of the select box. I hope to achieve this via the use of a case and switch to specify which query to run, from this i would like to then echo the results of the query into a table. the table being "tableleft"

-

<?php
 //create connection vars
 $dbhost = '-';
 $dbuser ='-';
 $dbpass = '-';
 $db = '-';
 //create connection
 $con=mysql_connect($dbhost, $dbuser, $dbpass);
 mysql_select_db($db);

 switch($_GET['Allergen1']){
    case 'Wheat':
       mysql_query("SELECT DishName FROM AllergenDishMenu WHERE Wheat = 0");
       break;
    case 'Spelt':
       mysql_query("SELECT DishName FROM AllergenDishMenu WHERE Spelt = 0");
       break;
    case 'Kamut':
       mysql_query("SELECT DishName FROM AllergenDishMenu WHERE Kamut = 0");
       break;
    case 'Rye':
       mysql_query("SELECT DishName FROM AllergenDishMenu WHERE Rye = 0");
       break;
    case 'Barley':
       mysql_query("SELECT DishName FROM AllergenDishMenu WHERE Barley = 0");
       break;
    case 'Oats':
       mysql_query("SELECT DishName FROM AllergenDishMenu WHERE Oats = 0");
       break; 
    case 'Fish':
       mysql_query("SELECT DishName FROM AllergenDishMenu WHERE Fish = 0");
       break;
    case 'Crustaceans':
       mysql_query("SELECT DishName FROM AllergenDishMenu WHERE Crustaceans = 0");
       break;
    case 'Molluscs':
       mysql_query("SELECT DishName FROM AllergenDishMenu WHERE Molluscs = 0");
       break;
    case 'Eggs':
       mysql_query("SELECT DishName FROM AllergenDishMenu WHERE Eggs = 0");
       break;
    case 'Soybeans':
       mysql_query("SELECT DishName FROM AllergenDishMenu WHERE Soybeans = 0");
       break;
    case 'Milk':
       mysql_query("SELECT DishName FROM AllergenDishMenu WHERE Milk = 0");
       break;
    case 'Almonds':
       mysql_query("SELECT DishName FROM AllergenDishMenu WHERE Almonds = 0");
       break;
    case 'Hazelnut':
       mysql_query("SELECT DishName FROM AllergenDishMenu WHERE Hazelnut = 0");
       break;
    case 'Walnut':
       mysql_query("SELECT DishName FROM AllergenDishMenu WHERE Walnut = 0");
       break;
    case 'CashewNut':
       mysql_query("SELECT DishName FROM AllergenDishMenu WHERE CashewNut = 0");
       break;
    case 'PecanNut':
       mysql_query("SELECT DishName FROM AllergenDishMenu WHERE PecanNut = 0");
       break;
    case 'BrazilNut':
       mysql_query("SELECT DishName FROM AllergenDishMenu WHERE BrazilNut = 0");
       break;
    case 'Pistacio':
       mysql_query("SELECT DishName FROM AllergenDishMenu WHERE Pistacio = 0");
       break;
    case 'Macadamia':
       mysql_query("SELECT DishName FROM AllergenDishMenu WHERE Macadamia = 0");
       break;
    case 'Peanuts':
       mysql_query("SELECT DishName FROM AllergenDishMenu WHERE Peanuts = 0");
       break;
    case 'Celery':
       mysql_query("SELECT DishName FROM AllergenDishMenu WHERE Celery = 0");
       break;
    case 'Mustard':
       mysql_query("SELECT DishName FROM AllergenDishMenu WHERE Mustard = 0");
       break;
    case 'Sesame':
       mysql_query("SELECT DishName FROM AllergenDishMenu WHERE Sesame = 0");
       break;
    case 'Sulphites':
       mysql_query("SELECT DishName FROM AllergenDishMenu WHERE Sulphites = 0");
       break;
    case 'Lupin':
       mysql_query("SELECT DishName FROM AllergenDishMenu WHERE Lupin = 0");
       break;
    }
?>


 <!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="Styling.css">
<meta charset="utf-8">
<title>Allergen Menu</title>
</head>
<body>

  <h1>Allergen Menu</h1>


  <div id ="container">
    <span id ="tableleft">
        <!-- NEED TO ECHO RESULT OF THE QUERY HERE BASED UPON THE SELECT OPTION FROM THE FORM BELOW !-->
    </span>
    <span id ="tableright">
        <Form method="post">
            <SELECT name="Allergen1">
                <option value="Wheat">Wheat</option>
                <option value="Spelt">Spelt</option>
                <option value="Kamut">Kamut</option>
                <option value="Rye">Rye</option>
                <option value="Barley">Barley</option>
                <option value="Oats">Oats</option>
                <option value="Fish">Fish </option>
                <option value="Crustaceans">Crustaceans</option>
                <option value="Molluscs">Molluscs</option>
                <option value="Eggs">Eggs</option>
                <option value="Soybeans">Soybeans</option>
                <option value="Milk">Milk</option>
                <option value="Almonds">Almonds</option>
                <option value="Hazelnut">Hazelnut</option>
                <option value="Walnut">Walnut</option>
                <option value="CashewNut">Cashew Nut</option>
                <option value="PecanNut">Pecan Nut</option>
                <option value="BrazilNut">Brazil Nut</option>
                <option value="Pistacio">Pistacio</option>
                <option value="Macadamia">Macadamia</option>
                <option value="Peanuts">Peanuts</option>
                <option value="Celery">Celery</option>
                <option value="Mustard">Mustard</option>
                <option value="Sesame">Sesame</option>
                <option value="Sulphites">Sulphites</option>
                <option value="Lupin">Lupin</option>
            </SELECT>
            <input type="submit">
        </Form>
    </span>
  </div>
  </html> 
</body>

I expect the query once ran to output via an echo to the "table left" any help with this would be appreciated.

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答