24 thg 9, 2015

Code PHP từ bài 115-117



https://www.youtube.com/watch?v=z1yhd2DmMkE&list=PL442FA2C127377F07&index=117




trang index.php

<?php
require 'connect.inc.php' ;

$query =" SELECT `food`, `calories` FROM `food` WHERE `healthy_unhealthy`='u' AND `calories` = '7000' ORDER BY `id` DESC";


if ($query_run = mysql_query($query))   {

   if (mysql_num_rows($query_run) ==NULL)   {
     echo 'No results found.';
   } else {

  while  ($query_row = mysql_fetch_assoc($query_run))   {
    $food  = $query_row['food']  ;
    $calories = $query_row['calories'];

    echo $food . '  has ' . $calories . '  calories.<br> ';
    }
   }

} else  {
 echo mysql_error();
}

?>

trang connec.inc.php

<?php
$conn_error = 'could not connect. ';
$mysql_host = 'localhost';
$mysql_user = 'root';
$mysql_pass ='';

$mysql_db = 'a_database';

if (!@mysql_connect($mysql_host, $mysql_user, $mysql_pass)  || !@mysql_select_db($mysql_db))  {
   die($conn_error);
}
?>

Code PHP từ bài 115-117 Rating: 4.5 Diposkan Oleh: http://pdunoteit.blogspot.com/