-1

I search all in the internet. I just need to know from other person's suggestions.

This is my code. My problem is I don't know how to send the values in database to the textarea. I want to display the values from my database table data_list

<?php

include('config.php');

This is where I store the values that inputted from the form then use it as a comparison in the sql so that it will select.

$employee_list = $_POST['employee_list']; 
$time_in_out2 = $_POST['time_in_and_out2'];
$timelogs = $_POST['timelogs']; 
$project_list2 = $_POST['project_list2'];

// Check connection

if ($db->connect_error) {
die("Connection failed: " . $db->connect_error);
} 

Here in the query. I use inner join because i have 2 database and it won't work. The result is still zero. I want to display the values from table data_list that has a row name of notes. The notes is the value that i want to display in the text area.

$sql = "SELECT employee.full_name, data_list.time_in_out, data_list.notes 
        FROM data_list WHERE employee.full_name = '$employee_list' AND 
        data_list.time_in_out = '$time_in_out2' AND data_list.notes = 
       '$timelogs' INNER JOIN employee ON data_list.employee_id = 
        employee.employee_id";

$result = $db->query($sql);

if ($result->num_rows > 0) {
echo "<table><tr><th>ID</th><th>Name</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
    echo "<tr><td>".$row["$notes"]."</td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}

This is the html form:

<body>

    <p><h4>Date:</h4> <input type="text" id="datepicker"></p>

    <form action="" method="post">
    <h4>Projects*</h4>
        <select name="project_list2" id="project_list2">
            <option name="Company1" value="Company1">Company1</option>
            <option name="Company2" value="Company2">Company2</option>
            <option name="Company3" value="Company3">Company3</option>

        </select>

        <h4> Employee* </h4>
        <select name="employee_list" id="employee_list">
            <option name="Employee2" value="Employee2">Employee2</option>
            <option name="Employee2" value="Employee2">Employee2</option>
            <option name="Employee3" value="Employee3">Employee3</option>


        </select>

        <h4>TIMEIN/TIMEOUT</h4>

        <select name="time_in_and_out">
            <option name="time_in" value="Time In">Time In</option>
            <option name="time_out" value="Time Out">Time Out</option>
        </select>

        <br><br>
        <br><br>

        <input type="submit" name="generate_button" value="GENERATE">

        <br><br>

    <h4> Timelogs: </H4>
      <textarea readonly="readonly" name="timelogs" rows="10" cols="40"><?
       php ($timelogs);?></textarea>


    <h2><a href = "logout.php">Sign Out</a></h2>

</body>

The point is to generate the notes of what i selected employee, date, projects, time in. So that I can display of the notes of my employee. This page is from the manager. This page is able to read the notes of his employee. I have also a table employee.

johnnyV
  • 1
  • 3

1 Answers1

0

For no ajax use this example:

The example it's for put values in a select html.

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT id, name FROM user";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    // output data of each row
    $option = "";
    while($row = $result->fetch_assoc()) {
       $option .= '<option value = "'.$row["id"].'">'.ech$row["name"].'</option>';
}
    }
$conn->close();
?>
<form>
<select id = "name_of_user" name="users" onchange="showUser(this.value)">
<?php echo $option; ?>     
</select>
</form>

Or this:

<select name="owner">
     <?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT id, name FROM user";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    // output data of each row
    $option = "";
    while($row = $result->fetch_assoc()) {
       echo '<option value = "'.$row["id"].'">'.ech$row["name"].'</option>';
}
    }
$conn->close();
?>
</select>

Code explained

You get the values from the database.

Then with echo you present the values in your html.

For more help use this link:

https://www.w3schools.com/php/php_mysql_select.asp

Presentation of the data in a table

display data from database into html table

Presentation of the data in a form:

Fetching data from MySQL database using PHP, Displaying it in a form for editing

Jose Marques
  • 748
  • 1
  • 6
  • 22