Difference between revisions of "PHP 6"

From Ilianko
Line 48: Line 48:
 
   $i = 97;  
 
   $i = 97;  
 
   while($otgovor = mysqli_fetch_array($otgovori)) {
 
   while($otgovor = mysqli_fetch_array($otgovori)) {
     echo  chr($i++).'<input type="radio" name="question['.$row['id'].']" value="'.$otgovor['id'].'">'.$otgovor['answer']."<br /> \n";  
+
     echo  chr($i++).'<input type="radio" name="question['.$row['id'].']"
 +
value="'.$otgovor['id'].'">'.$otgovor['answer']."<br /> \n";  
 
   }
 
   }
 
}
 
}

Revision as of 13:24, 24 October 2013

Връзки с MySQL

Основни функции

  • mysqli_connect();
  • mysqli_query();
  • mysqli_fetch_assoc();
  • mysqli_real_escape_string();


Извличане на информация от база данни

<?php 
  //conection:
  $link = mysqli_connect("localhost","student","3405","student"); 
  mysqli_query($link, "SET NAMES utf8");
  mb_internal_encoding('utf-8');
  
?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8"  />
  </head>
<body>
 <form action="check.php" method="POST">
 <?php

//consultation:
$query = "SELECT * FROM  `Questions`";

//execute the query.
$result = mysqli_query($link, $query);


//display information:
$x = 0;
while($row = mysqli_fetch_array($result)) {
  
  $x++;	
  echo $x.'  -  '.$row['question'].'<br>';
 
  $query = 'SELECT * FROM  `Answers` WHERE  `id_question` = '.$row['id'];
  $otgovori =  mysqli_query($link, $query);
  
  $i = 97; 
  while($otgovor = mysqli_fetch_array($otgovori)) {	
    echo  chr($i++).'<input type="radio" name="question['.$row['id'].']"
 value="'.$otgovor['id'].'">'.$otgovor['answer']."<br /> \n"; 
  }
}
 

?>
  <input type="submit" name='submit' value="Submit">
  </form>
</body>
</html>