Thursday, 31 January 2019

PHP : Connect PHP with mysql SUCCESS


<!-- use this if want to include connection from saperate file

 <?php
 //include 'dbh.php';
 
?> -->

<!-- php below is the copy from dbh.php. Use php include if you want to saperate connector with index file -->
<?php

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "ajax";

$conn = mysqli_connect($servername, $username, $password,$dbname);

?>


<!DOCTYPE html>
<html>
<head>
 <title>Jquery Ajax</title>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
 //jquery code here
</script>
</head>
<body>


<div id="comment">
 
 <!-- coding here -->

 <?php
$sql = "SELECT * FROM comments LIMIT 3"; //change LIMIT number to show up how many data to echo
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0){
 while ($row = mysqli_fetch_assoc($result)) {
  echo "<p>";
  echo $row['author'];
  echo "<br/>";
  echo $row['message'];
  echo "<br/>";
  echo "</p>";
 }

   

  } else {
   echo "Tak ada comments!";

  }

 ?>

</div>


<button>Show comment</button>

</body>
</html>
...

change to this to display latest or newer data from mysql

$sql = "SELECT * FROM comments order by id DESC LIMIT 4"

in this case data select latest by id. If there are date row on mysql change into that string.

Auto select after redirect to the contact page SELECT JAVASCRIPT

 https://domain.my/contact/?startup_package=UltimateImpact         <select name="startup_package" class="form-select"...