vendredi 23 décembre 2016

Generating information based on users chose in php

I have any information stored in a database which is picked up and displayed with radio buttons. I like to display information from the database based on what radio buttons the user has chosen. For example I have a list of activities a user may have done and based on what they have chosen I would like to display other activities they could do. I can get the system to display random information from the database using RAND().

Here is my code.

              <?php 

                $query1 = "SELECT Name FROM activities WHERE ID = 1"
      $result1 = mysqli_query($con, $query1) or die("Invalid Query");

      while($row1 = mysqli_fetch_assoc($result1)){ 
        
        $name = $row1["Name"];


echo "<input type=\"checkbox\" name=\"city\" value=\"$name\" />$name </br>";
        
        }

        $query2 = "SELECT Name FROM activities WHERE ID = 2";

    
      $result2 = mysqli_query($con, $query2) or die("Invalid Query");

      while($row2 = mysqli_fetch_assoc($result2)){ 
        
        $name = $row2["Name"];


echo "<input type=\"checkbox\" name=\"city\" value=\"$name\" />$name </br>";
        
        }

                $query3 = "SELECT Name FROM activities WHERE ID = 3";

    
      $result3 = mysqli_query($con, $query3) or die("Invalid Query");

      while($row3 = mysqli_fetch_assoc($result3)){ 
        
        $name = $row3["Name"];


echo "<input type=\"checkbox\" name=\"city\" value=\"$name\" />$name </br>";
        
        }


$query4 = "SELECT Name FROM activities WHERE ID = 4";

    
      $result4 = mysqli_query($con, $query4) or die("Invalid Query");

      while($row4 = mysqli_fetch_assoc($result4)){ 
        
        $name = $row4["Name"];


echo "<input type=\"checkbox\" name=\"city\" value=\"$name\" />$name </br>";
        
        }

?>
<?php

$query= "SELECT * FROM activities ORDER BY RAND() LIMIT 1";

$result = mysqli_query($con, $query2) or die("Invalid Query");

      while($row2 = mysqli_fetch_assoc($result)){ 

$activities = $row["Name"];

echo "<p>$activities</p>";

        }

?>



Aucun commentaire:

Enregistrer un commentaire