Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
158 views
in Technique[技术] by (71.8m points)

javascript - Is there a way to create filters for a mysql driven table[PURE PHP]

I have a table that gets its data from a MySQL database... I want to create some filters that filter the table data. I would prefer if the solution was pure PHP or pure JavaScript... Please let me know if this is possible and if it is what I should do or learn about!


Filters:

<?php 
$conn = mysqli_connect(stuff here);
$qm = "Select Name From options Where Type = 'Merchant'";
$qt = "Select Name From options Where Type = 'Type'";
$qs = "Select Name From options Where Type = 'Source'";
?>
<!DOCTYPE html>
<html>
<head>
<style>
input{margin: 10px; padding: 5px; text-align: center}
select{margin: 10px; padding: 5px; text-align: center}
</style>
</head>
<body>
<fieldset id='filters'>
<legend>Filter Transactions</legend>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method='post'>
<input type='date' name='fd'>
<input type='number' name='fa' placeholder='Amount'>
<select name='fm'>
<option value='fm'>Select Merchant</option>
<?php
$result1 = mysqli_query($conn, $qm);
while($row = mysqli_fetch_assoc($result1)){
foreach($row as $value){echo "<option value='$value'>$value</option>";}}
?>
</select>
<select name='ft'>
<option value='ft'>Select Type</option>
<?php
$result1 = mysqli_query($conn, $qt);
while($row = mysqli_fetch_assoc($result1)){
foreach($row as $value){echo "<option value='$value'>$value</option>";}}
?>
</select>
<select name='fs'>
<option value='fs'>Select Source</option>
<?php
$result1 = mysqli_query($conn, $qs);
while($row = mysqli_fetch_assoc($result1)){
foreach($row as $value){echo "<option value='$value'>$value</option>";}}
?>
</select>
<input type='hidden' name='done' value='yes'>
<input type='reset' value='Clear Filters'>
<input type='submit' value='Apply Filters'>
</form>
</fieldset>
</body>
</html>

Table Code

<!DOCTYPE html>
<html>

<head>
<title>View Transactions</title>
<link rel="stylesheet" href="styles.css" type="text/css">
</head>

<body>
<?php
$conn = mysqli_connect(stuff here);

// Run the query.
$result = mysqli_query($conn, "SELECT *  FROM main");
$num = mysqli_num_rows($result);
// Get the result in to a more usable format.
$query = array();
function display($result, $conn){
while($query[] = mysqli_fetch_assoc($result));
array_pop($query);

// Output a dynamic table of the results with column headings.
echo "<form action='modify.php' method='get' style='display: inline-block;'><label class='label' for='id'>Modify Transaction: </label><input type='number' name='id' placeholder='Transaction Id'>&nbsp<input type='submit' value='Modify'></form><br><br>";
echo "<form action='delete.php' method='get' style='display: inline-block;'><label class='label' for='id'>Delete Transaction: </label><input type='number' name='id' placeholder='Transaction Id'>&nbsp<input type='submit' value='Delete'></form><br><br>";
echo '<table>'; 
echo '<tr>';
foreach($query[0] as $key => $value) {
    echo '<th>';
    echo $key;
    echo '</th>';
}
echo '</tr>';
foreach($query as $row) {
    echo '<tr>';
    foreach($row as $column) {
        echo '<td>';
        echo $column;
        echo '</td>';
    }
    
    echo '</tr>';
}
echo '</table>';}
if(mysqli_num_rows($result) > 0){echo "<h1>View Transactions</h1>Number Of Transactions: $num<br><br>"; include('filters.php'); display($result, $conn);}
else{echo '<h1>No Transactions Found</h1><br><br><a href="AddT.php"><button>Add A Transaction</button></a>';}


?>

</body>
</html>

What shall I do... Also, I might have accidentally type something wrong when I was adding the tags so please ignore any weird code! Thanks!!!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...