0

I have a data-table in mySQL and I need help accessing the information to display on an HTML Page.

Here are some details.

Host: 127.0.0.1:8889
username: root
password: root
database-name: gibsonek
table-name: events

Here is my code:

<html>
  <head>
    <meta charset="UTF-8">
    <title>Gibson Ek Schedule</title>

<!--JQuery Add-->    
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>

<!--My JS Add-->
<script src="script.js"></script>

<!--Normalize CSS Add-->
<link rel="stylesheet" href="css/normalize.css">


<!--Google Font - Open Sans - Add -->
<link rel='stylesheet prefetch' href='https://fonts.googleapis.com/css?family=Open+Sans:300,400,600'>

<!--Bootstrap Add-->
<link rel='stylesheet prefetch' href='https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css'>

<!--My CSS Add-->
<link rel="stylesheet" type="text/css" href="style.css">




  </head>




  <body>
    <div class="container">
  <div class="navbar">
    <span>Gibson Ek Schedule</span>
  </div>

  <div class="header">
    <div class="color-overlay">
      <div class="day-number"></div>
      <div class="date-right">
        <div class="day-name"></div>
        <div class="month"></div>
      </div>
    </div>

  </div>

  <div class="timeline">
    <ul id = "l">

<?php

$connection = mysql_connect('127.0.0.1:8889', 'root', 'root');
mysql_select_db('gibsonek');

$query = "SELECT * FROM `events` WHERE 1"; 
$result = mysql_query($query);



while($row = mysql_fetch_array($result)){  


echo "<p>SQL DATA WILL GO IN HERE</p>";  
}





mysql_close(); //Make sure to close out the database connection



?>





    </ul>
  </div>  
</div>




  </body>


</html>
6
  • but i am getting what you want ? which manner you want to display result Sep 8, 2016 at 4:45
  • Is this a question or what? Sep 8, 2016 at 4:46
  • 1) mysql_ should not be used since it was depreciated in older versions of PHP and removed in PHP7. 2) what is your problem?
    – Memor-X
    Sep 8, 2016 at 4:47
  • What is this? Homework? Sep 8, 2016 at 4:51
  • Sorry everybody I am a beginner. I want to do say the data as text. Sep 8, 2016 at 4:54

3 Answers 3

0

Please use PDO (it's more flexible and safe)

$servername = "127.0.0.1:8889";
$username = "root";
$password = "root";
$dbname = "gibsonek";

$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT * FROM `events` WHERE id='1'"); 
$stmt->execute();
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
$result = $stmt->fetchAll();

var_dump($result); // or as you like

There is a good article.
There is a best guide.

8
  • It's not working for me. I want to add a new paragraph with a value from my SQL for every record Sep 8, 2016 at 5:33
  • @JoshFeinsilber All the data from your DB stored in variable $result. You must extract data with cycles Sep 8, 2016 at 5:38
  • Okay, I see. Can you write that so that it will make a new paragraph with the text of a row from SQL. Sorry, first time doing this. Sep 8, 2016 at 5:41
  • This is a very good video. See it and learn it. youtube.com/watch?v=hSS1Ml6YOt8 Sep 8, 2016 at 5:42
  • Ok thanks! So I have this, but it isn't working: <?php $servername = "127.0.0.1:8889"; $username = "root"; $password = "root"; $dbname = "gibsonek"; $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $conn->prepare("SELECT * FROM events WHERE id='1'"); $stmt->execute(); $result = $stmt->setFetchMode(PDO::FETCH_ASSOC); $result = $stmt->fetchAll(); echo($result); ?> Sep 8, 2016 at 5:50
0
<div class="timeline">
    <ul id = "l">
    <?php
        $host = "127.0.0.1:8889";
        $username = "root";
        $password = "root";
        $db_name = "gibsonek"; 

        $mysqli = new mysqli($host, $username, $password, $db_name);

        if ($mysqli->connect_error) {
               die('Error : ('. $mysqli->connect_errno .') '.$mysqli->connect_error);
        }

        $query = "SELECT * FROM `events` WHERE id='1'"; // Here if 1 means id 
        $result = $mysqli->query($query);
        while($row = $result->fetch_assoc()) {
        ?>
        <!-- Here You can add any HTML or css -->
        <li><?php echo $row["column"]; ?> </li> // write your column name what you want to show 

    <?php
      }
    ?>
    </ul>
</div>

I think that would be clear for you, leave a comment if any query. Thanks

-1

I think you missed something here is correct code:

<?php

    $connection = mysql_connect('127.0.0.1:8889', 'root', 'root');
    mysql_select_db('gibsonek');

    $query = "SELECT * FROM `events` WHERE id(or any column as u want)='1'"; 
    $result = mysql_query($query);

    while($row = mysql_fetch_array($result)){  

                   print_r($row);  
    }

    mysql_close(); //Make sure to close out the database connection
    ?>
1
  • It's not working for me. I want to add a new paragraph with a value from my SQL for every record Sep 8, 2016 at 5:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.