I am populating an HTML table with information from a database and want to trigger it with a button.
Can someone help me with this, and perhaps add some links to relevant website with examples?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div method="GET">
<table>
<thead>
<tr>
<th>ID</th>
<th>Nombre</th>
<th>Usuario</th>
</tr>
<?php
include "php/populate.php";
?>
</thead>
</table>
<input type="button" value="button" id="button">
</div>
</body>
</html>
<?php
$result = mysqli_query($enlace,"SELECT * FROM tb_personas");
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['txt_nombre'] . "</td>";
echo "<td>" . $row['txt_usuario'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($enlace);
?>
You need to use jQuery (the easiest way to use ajax)
take a look at this question on stackoverflow how to call a php script on a html button click
additionally you are including your data at table's header, instead they should be included in table's body.
<table>
<thead>
<tr>
<th>ID</th>
<th>Nombre</th>
<th>Usuario</th>
</tr>
</thead>
<tbody>
<?php include "php/populate.php"; ?>
</tbody>
</table>
Related
I am getting the following validation error, it claims I have "misplaced non-space characters inside the table" I have tried everything and for the life of me cannot fix this error. The error is the following
Here is the PHP/HTML being used for
<?php
$title = "Alter Records";
include('includes/head.php');
include('includes/nav.php');
ini_set('display_errors', 0);
require_once('config.php');
require_once('db_class.php');
$connection = new dbController(HOST,USER,PASS,DB);
$sql = "select id,name, image,location from location";
$results = $connection->getAllRecords($sql);
//var_dump($results);
?>
<table>
<tr>
<th>Id</th>
<th>Name</th>
<th>Location</th>
<th>Image</th>
<th colspan="2">Make Changes</th>
</tr>;
<?php
foreach ($results as $row){
echo "<tr>";
echo "<td>{$row['id']}</td>";
echo "<td>{$row['name']}</td>";
echo "<td>{$row['location']}</td>";
echo "<td><img class='thumb' src='{$row['image']}' alt='{$row['name']}'> </td>";
echo "<td><a href=''>Update</a></td>";
echo "<td><a href='delete_record.php?id={$row['id']}'>Delete</a></td>";
echo "</tr>";
}
echo "</table>";
include('includes/footer.php')
?>
Here is the code inside validator.w3.org
↩
<!DOCTYPE html>↩
<html lang="en">↩
<head>↩
<meta charset="utf-8">↩
<title>Alter Records</title>↩
<link href="https://fonts.googleapis.com/css2?family=Quicksand&display=swap" rel="stylesheet">↩
<link href="https://fonts.googleapis.com/css2?family=Bellota+Text:ital,wght#1,300;1,400&display=swap" rel="stylesheet">↩
<link rel="stylesheet" href="css/style.css">↩
</head>↩
<body>↩
<header><h1> TOURISM VICTORIA</h1></header>↩
<nav>↩
<ul class="flex-nav">↩
<li>Home</li>↩
<li>Add</li>↩
<li>Alter</li>↩
<li>↩
<form class="search-form" action="search.php" method="get">↩
<input type="text" name="search">↩
<button type="submit">Search</button>↩
</form>↩
</li>↩
</ul>↩
</nav>↩
<table>↩
<tr>↩
<th>Id</th>↩
<th>Name</th>↩
<th>Location</th>↩
<th>Image</th>↩
<th colspan="2">Make Changes</th>↩
</tr>;↩
<tr><td>1</td><td>Melbourne ShowGrounds</td><td>Royal Melbourne Showgrounds. Ascot Vale, Victoria, Austra
Any assistance with this would be greatly appreciated. If I am still unclear, please ask for further clarification.
just seeing your last include will also result in an error, you will need to end with ;
My project is about Allergies and I am trying to add the allergies given in one table "List of Allergies" to another table "MyAllergies" with an onclick button "add" for each allergies given. What I want is when the user clicks on add button for one allergy, that specific allergy should automatically be added to the "MyAllergy.php". Please help me. I have been trying for 2 days and I got no where. However, I tried the query and it was almost correct. I would be so grateful. Thank you. Let me know if you want me to attach the other code or any more questions. :)
AddAllergy.php
<?php
include('Session.php');
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Allergen Details</title>
<div align="center">
<h1>Allergen Information</h1>
</div>
</head>
<body>
<?php
$allergysql = 'SELECT Allergy,Description,Symptoms FROM FoodAllergy';
$retrieve = mysqli_query($connection, $allergysql);
if(!$retrieve)
{
die("Could not get data!".mysqli_error($connection));
}
print "
<table border=\"5\" cellpadding=\"7\" style=\"border-collapse: collapse\" bordercolor=\"#85144b\" width=\"100%\" id=\"AutoNumber2\" bgcolor=\"#7FDBFF\"><tr>
<th width=100>Allergy:</th>
<th width=100>Description:</th>
<th width=100>Symptoms:</th>
<th width=100>Status:</th>
</tr>";
while($rowA = mysqli_fetch_assoc($retrieve))
{
print "<tr>";
print "<td>" . $rowA['Allergy'] . "</td>";
print "<td>" . $rowA['Description'] . "</td>";
print "<td>" . $rowA['Symptoms'] . "</td>"; ?>
<td> <div align ="center"> <button type ="button" onclick="addallergy()">Add</button></div></td>
<script>
function addallergy() {
// WHAT SHOULD I ADD HERE?? //
alert ('Added to your profile!');
}
</script>
<?php
print "</tr>";
}
print "</table>";
?>
</body>
</html>
I am trying to send the id from one page to other and i have achieved that but how do i make sure that when the show is pressed of a particular column only that id is sent.Here is my code.
This is index.php.It displays the rows and a show button against each row.
<?php session_start(); ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href="css/bootstrap.min.css" rel="stylesheet">
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<h3>Restaurant Categories</h3>
</div>
<div class="row">
<p> Create </p>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<?php
include 'database.php';
$pdo = Database::connect();
$sql = 'SELECT * FROM Categories';
$result = $pdo->query($sql);
foreach ($pdo->query($sql) as $row) {
echo '<tr>';
echo '<td>'. $row['C_id'] . '</td>';
echo '<td>'. $row['C_name'] . '</td>';
echo '<td>'. $row['C_description'] . '</td>';
echo '<td><a class="btn" href="show_items.php">Shitems</a> </td>';
$_SESSION["id"] = $row['C_id']; <-----I am saving the id here.But it only saves the latest id
echo $_SESSION["id"];
echo '</tr>';
}
Database::disconnect();
?>
</tbody>
</table>
</div>
</div> <!-- /container -->
</body>
</html>
Just embed the ID in the url as a query string:
echo '<td><a class="btn" href="show_items.php?id=' . $row['C_id'] . '">Shitems</a> </td>';
^^^^^^^^^^^^^^^^^^^^
Simple using _GET...
<a class="btn" href="show_items.php">
<a class="btn" href="show_items.php?id=<?=$row['C_id']?>">
Then you can access it via... _GET['id']
First you need from form around button. But you can make this with ajax(if you don't redirect the page) or link
I have this userlist page and i want for users to be able to click the users username and it will send them to there profile page how would i go on doing this ?
This line is where the user clicks the username of a user
echo "<td class='info'><a href=''>". $people_list['username']."</a></td>";
Also in my .htaccess i have a code that makes it so i go to users profile all i do is http://www.example.com/username
<?php
include 'core/int.php';
include 'includes/head.php';
include 'head.php';
include 'includes/body.php';
include 'body.php';
$people_list="SELECT * FROM users";
$people=mysql_query($people_list);
?>
<html>
<head>
<style>
.owner {
color: orange;
}
</style>
</head>
<body>
<pre>
<table class="table table-bordered">
<thead>
<tr>
<th>ID</th>
<th>Username</th>
<th>Email</th>
</tr>
<?php
while($people_list=mysql_fetch_assoc($people)){
echo "<tr>";
if ($people_list['username'] == KillerDucky1){
echo "<td>". $people_list['user_id']."</td>";
echo "<td class='warning'><a class='owner' href=''>". $people_list['username']."</a></td>";
echo "<td>". $people_list['email']."</td>";
} else {
echo "<td>". $people_list['user_id']."</td>";
echo "<td class='info'><a href=''>". $people_list['username']."</a></td>";
echo "<td>". $people_list['email']."</td>";
echo "</tr>";
}
}
?>
</thead>
</pre>
</body>
</html>
You simply need to put the username in the <a> link tag :)
<a href='/".$people_list['username']."'>...</a>
You could try just adding the username to the href of the anchor.
echo '<td class="info">'. $people_list['username'].'</td>';
should give you something like:
<td class="info">username</td>
Hello to everyone I'm new to this and I'm trying to make a simple dynamic HTML. I have written the following code but it seems dose not work. Can someone help me. Because All I get is the following line
$row[name]"); echo (""); echo (""); echo (""); echo (""); } ?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table>
<tr>
<td align="center">EDIT DATA</td>
</tr>
<tr>
<td>
<table border="1">
<?
mysql_connect("localhost","user","pass");
mysql_select_db("Computers");
$order = "SELECT * FROM vnc";
$result = mysql_query($order);
while ($row=mysql_fetch_array($result)){
echo ("<td>$row[name]</td>");
echo ("<td>$row[department]</td>");
echo ("<td>$row[phone]</td>");
echo ("<td>$row[ip]</td>");
echo ("<td>Edit</td></tr>");
}
?>
</table>
</td>
</tr>
</table>
</body>
</html>
Thank you in advance
This should work for you
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table>
<tr>
<td align="center">EDIT DATA</td>
</tr>
<tr>
<td>
<table border="1">
<?php
mysql_connect("localhost","user","pass");
mysql_select_db("Computers");
$order = "SELECT * FROM vnc";
$result = mysql_query($order);
while ($row=mysql_fetch_array($result)){
echo "<td>" . $row[name] . "</td>
<td>" . $row[department] . "</td>
<td>" . $row[phone] . "</td>
<td>" . $row[ip] . "</td>
<td>Edit</td></tr>";
}
?>
</table>
</td>
</tr>
</table>
</body>
</html>
I'm not sure why you used the parenthesis, but what you're looking for is something similar to this:
echo "<td>" . $row[name] . "</td>";
Anything written inside the quotations will be displayed explicitly, which is why you have to end the quotes, add a period, then give the array, followed by another period and opening quotes.
The
<? should be <?php .... It apprears that short tags is turned off on your webserver. also echo does not need parentheses
The correct syntax is this:
echo "<td>".$row['name']."</td>";
If your queries are working well, it should print something.
echo ("<td>Edit</td></tr>");
This line is problematic. You're trying to print double quotes in a double-quoted string. Try using single quotes instead.
There are some sintax error in your code you don't need to use parethesis
echo "<td>$row[name]</td>";
echo "<td>$row[department]</td>";
echo "<td>$row[phone]</td>";
echo "<td>$row[ip]</td>";
Also this line needs to be fixed because of double quotes used in anchor, you can either change to single quote or escape it with a backslash
echo '<td>Edit</td>';
Or
echo "<td>Edit</td>";
I would finally advise you to switch to long tags <?php