Difference between revisions of "PHP 6"

From Ilianko
Line 7: Line 7:
 
*mysqli_fetch_assoc();
 
*mysqli_fetch_assoc();
 
*mysqli_real_escape_string();
 
*mysqli_real_escape_string();
 +
 +
 +
 +
== Извличане на информация от база данни ==
 +
 +
<code><pre>
 +
<?php
 +
  $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
 +
  //conection:
 +
 +
//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>
 +
 +
</pre></code>

Revision as of 13:23, 24 October 2013

Връзки с MySQL

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

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


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

<?php
  $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
  //conection:

//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>