Currently the following code displays the filters for the individual publishers ie if I select DC I will only see the DC titles.
The issue is that from the current code I cannot get it to display all publishers from the dropdown menu.
<div id="main">
<form method="post" action="">
<div id="search_query" >
<select name="make" size="0">
<option value="all">All Publishers</option>
<option value="DC">DC</option>
<option value="Marvel">Marvel</option>
<option value="Image">Image</option>
</select>
<input type="submit" name="submit" value="submit">
</div>
</form>
<div id="main_container">
<?php
$db_con = mysql_connect('127.0.0.1','root','root');
if (!$db_con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('work', $db_con);
if(isset($_POST['submit']))
{
$make = mysql_real_escape_string($_POST['make']);
$sql = sprintf("SELECT * FROM products WHERE publisher= '$make' ");
$result = mysql_query($sql);
echo "<table width= 970 border=1>
<tr>
<th width='120' scope='col'>Title</th>
<th width='170' scope='col'>Publisher</th>
<th width='185' scope='col'>Price</th>
<th width='126' scope='col'>Desc</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>".$row['title']."</td>";
echo "<td>". $row['publisher'] . "</td>";
echo "<td>". $row['price'] ."</td>";
echo "<td>". $row['desc'] ."</td>";
echo "</tr>";
}
echo "</table>";
}
else
{
$sql = sprintf("SELECT * FROM products");
$result = mysql_query($sql);
echo "<table width= 970 border=1>
<tr>
<th width='120' scope='col'>Title</th>
<th width='170' scope='col'>Publisher</th>
<th width='185' scope='col'>Price</th>
<th width='126' scope='col'>Desc</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>".$row['title']. "</td>";
echo "<td>". $row['publisher'] . "</td>";
echo "<td>". $row['price'] ."</td>";
echo "<td>". $row['desc'] ."</td>";
echo "</tr>";
}
echo "</table>";
}
mysql_close($db_con);
?>
In your query, it's searching for publisher = $make where $make = "all".
Your database table probably doesn't have any record with publisher = "make".
I'd suggest you to add an if else condition here:
if (isset($_POST['submit'])) {
$make = mysql_real_escape_string($_POST['make']);
if ($make != "all") {
$sql = sprintf("SELECT * FROM products WHERE publisher= '$make' ");
} else {
$sql = sprintf("SELECT * FROM products");
}
/* Other code */
}
Related
I already show the list of names from the database, but the problem is I don't know how to show the information each user, once I click some user in my list her/his information will appear.
html
<div class="member_list">
<div class="list-unstyled">
<?php require_once "../function/admin_function.php"; ?>
</div>
</div>
<div class="information" id="table_information">
<table class="table_information">
<tr>
<th colspan="4">Information</th>
</tr>
<tr>
<th>lastname</th>
<th>address</th>
<th>contact</th>
</tr>
<tr>
<td>
<?php include "../function/information_function.php"; ?>
</td>
</tr>
</table>
</div>
information_function - php
<?php
include "../connection/connection.php";
$sql = "SELECT * FROM registration";
$result = mysqli_query($dbconn, $sql);
while ($row = mysqli_fetch_array ($result)){
echo "<tr>";
echo "<td>" . $row['lname'] . "</td>";
echo "<td>" . $row['address'] . "</td>";
echo "<td>" . $row['contact'] . "</td>";
echo "</tr>";
}
?>
user list - php
<?php
include "../connection/connection.php";
$sql = "SELECT * FROM registration";
$result = mysqli_query ($dbconn, $sql);
while($row = mysqli_fetch_array ($result)) {
echo "<ul class='table_php'>";
echo "<li>";
echo "<a href='#table_information' class='friends_link'>";
echo "<span class='chat-img pull-left'>";
echo "<img src='user.png' class='img-circle'>";
echo "</span>" . $row['lname'] . "</a>";
echo "</li>";
echo "</ul>";
}
?>
Put your code inside a function and just call that function after include statement.
//information_function//
<?php
include "../connection/connection.php";
function get_information(){
$sql = "SELECT * FROM registration";
$result = mysqli_query($dbconn, $sql);
while ($row = mysqli_fetch_array ($result)){
echo "<tr>";
echo "<td>" . $row['lname'] . "</td>";
echo "<td>" . $row['address'] . "</td>";
echo "<td>" . $row['contact'] . "</td>";
echo "</tr>";
}
}
?>
//html//
<div class="member_list">
<div class="list-unstyled">
<?php require_once "../function/admin_function.php"; ?>
</div>
</div>
<div class="information" id="table_information">
<table class="table_information">
<tr>
<th colspan="4">Information</th>
</tr>
<tr>
<th>lastname</th>
<th>address</th>
<th>contact</th>
</tr>
<?php include "../function/information_function.php"; ?>
<?php get_information(); ?>
</table>
</div>
If I write something in search box and press search , it should only return matched rows and hide other rows.
Here is my code, it works perfects only issue is it gives me searched record + all record list of table.
What can I do to show only searched data in table.?
<div id="pageContent"><br />
<div class="search" align="right">
<form action="" method="post">
Search: <input type="text" name="term" /><br />
<input type="submit" value="Submit" />
</form>
</div>
<div class="container">
<table id="employee-grid" width="auto" cellpadding="1" cellspacing="1" border="1" class="table table-hover">
<?php
include_once '../storescripts/connect_to_mysql.php';
$num_rec_per_page=5;
if (isset($_GET["page"]))
{
$page = $_GET["page"];
}
else
{
$page=1;
}
$start_from = ($page-1) * $num_rec_per_page;
$result= mysql_query("SELECT * FROM products LIMIT $start_from, $num_rec_per_page");
?>
<thead>
<tr class="success">
<th>Id</th>
<th>Product Name</th>
<th>Price</th>
<th>Status</th>
<th>Quantity</th>
<th>Details</th>
<th>Category</th>
<th>Subcategory</th>
<th>Date Added</th>
<th colspan="2">Functions</th>
</tr>
</thead>
<?php
if (!empty($_REQUEST['term'])) {
$term = mysql_real_escape_string($_REQUEST['term']);
$sql = "SELECT * FROM products WHERE product_name LIKE '%".$term."%' or price LIKE '%".$term."' or details LIKE '%".$term."'";
$r_query = mysql_query($sql);
if($r_query>1)
{
while ($row = mysql_fetch_array($r_query)){
echo "<tr bgcolor='red'>";
echo "<td>".$row['id']."</td>";
echo "<td>".$row['product_name']."</td>";
echo "<td>".$row['price']."</td>";
echo "<td>".$row['status']."</td>";
echo "<td>".$row['quantity']."</td>";
echo "<td>".$row['details']."</td>";
echo "<td>".$row['category']."</td>";
echo "<td>".$row['subcategory']."</td>";
echo "<td>".$row['date_added']."</td>";
echo "<td><a href='product_listing_edit.php?id=".$row['id']."'>Edit</a></td>";
echo "<td><a name='delete' href='product_listing_delete.php?id=".$row['id']."'>Delete</a></td><tr>";
echo "</tr>";
}
}
else{
echo "Nothing should be displayed";
}
}
?>
<?php
while($row=mysql_fetch_array($result))
{
echo "<tr class='danger'>";
echo "<td>".$row['id']."</td>";
echo "<td>".$row['product_name']."</td>";
echo "<td>".$row['price']."</td>";
echo "<td>".$row['status']."</td>";
echo "<td>".$row['quantity']."</td>";
echo "<td>".$row['details']."</td>";
echo "<td>".$row['category']."</td>";
echo "<td>".$row['subcategory']."</td>";
echo "<td>".$row['date_added']."</td>";
echo "<td><a href='product_listing_edit.php?id=".$row['id']."'>Edit</a></td>";
echo "<td><a name='delete' href='product_listing_delete.php?id=".$row['id']."'>Delete</a></td><tr>";
echo "</tr>";
}
?>
</table>
Just keep single while loop and run the query and search query as shown below it will solve the issue:
<div id="pageContent"><br />
<div class="search" align="right">
<form action="" method="post">
Search: <input type="text" name="term" /><br />
<input type="submit" value="Submit" />
</form>
</div>
<div class="container">
<table id="employee-grid" width="auto" cellpadding="1" cellspacing="1" border="1" class="table table-hover">
<?php
include_once '../storescripts/connect_to_mysql.php';
$num_rec_per_page = 5;
if (isset($_GET["page"])) {
$page = $_GET["page"];
} else {
$page = 1;
};
$start_from = ($page - 1) * $num_rec_per_page;
$sql = "SELECT * FROM products LIMIT $start_from, $num_rec_per_page";
?>
<thead>
<tr class="success">
<th>Id</th>
<th>Product Name</th>
<th>Price</th>
<th>Status</th>
<th>Quantity</th>
<th>Details</th>
<th>Category</th>
<th>Subcategory</th>
<th>Date Added</th>
<th colspan="2">Functions</th>
</tr>
</thead>
<?php
if (!empty($_REQUEST['term'])) {
$term = mysql_real_escape_string($_REQUEST['term']);
$sql = "SELECT * FROM products WHERE product_name LIKE '%" . $term . "%' or price LIKE '%" . $term . "' or details LIKE '%" . $term . "'";
}
$r_query = mysql_query($sql);
if ($r_query > 1) {
while ($row = mysql_fetch_array($r_query)) {
echo "<tr bgcolor='red'>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['product_name'] . "</td>";
echo "<td>" . $row['price'] . "</td>";
echo "<td>" . $row['status'] . "</td>";
echo "<td>" . $row['quantity'] . "</td>";
echo "<td>" . $row['details'] . "</td>";
echo "<td>" . $row['category'] . "</td>";
echo "<td>" . $row['subcategory'] . "</td>";
echo "<td>" . $row['date_added'] . "</td>";
echo "<td><a href='product_listing_edit.php?id=" . $row['id'] . "'>Edit</a></td>";
echo "<td><a name='delete' href='product_listing_delete.php?id=" . $row['id'] . "'>Delete</a></td><tr>";
echo "</tr>";
}
} else {
echo "Nothing should be displayed";
}
?>
</table>
I'm retrieving a table from database as result of a search action, but when I try to display the result I see the table and the data, but the image returned in each row is not render, I think my problem is in the $('#search').html(data), I'm not sure please someone knows what is the problem?
this is the result
http://s9.postimg.org/mro5qn46n/search_result.jpg
****This is the search page, where result table is displayed****
<table align="center">
<tr>
<td>
<label for="criteria">Select Criteria</label>
</td>
<td>
<select name="select" id="criteria">
<option selected="true" style="display:none;"></option>
<option value="value1">name</option>
<option value="value2">apartment</option>
</select>
</td>
<td>
<input type="text" name="value" size="40" maxlength="60" id="value"\>
</td>
</tr>
<tr>
<td>
<input name="name-submit" type="button" id="submit" value="Search"\>
</td>
</tr>
<tr>
<td >
<div id="search"></div>
</td>
</tr>
</table>
<script type="text/javascript" src="../js/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$('#submit').click(function(){
var criteria = $("#criteria option:selected").text();
var value = $("#value").val();
$.post("search_r.php",{criteria:criteria,value:value},function(data){
$('#search').html(data);
});
});
</script>
****This is the Page that calls $.post() in the main seach page ****
<?php
$criteria = $_POST['criteria'];
$value = $_POST['value'];
$con = mysqli_connect("localhost","root","");
mysqli_select_db($con,"gables");
$query = "SELECT * FROM residents WHERE $criteria = '$value'";
$result = mysqli_query($con,$query);
echo "<table border='1'>
<tr>
<th>Id</th>
<th>Name</th>
<th>Last Name</th>
<th>Apartment</th>
<th>Parking</th>
<th>Phone1</th>
<th>Phone2</th>
<th>image</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['0'] . "</td>";
echo "<td>" . $row['1'] . "</td>";
echo "<td>" . $row['2'] . "</td>";
echo "<td>" . $row['3'] . "</td>";
echo "<td>" . $row['4'] . "</td>";
echo "<td>" . $row['5'] . "</td>";
echo "<td>" . $row['6'] . "</td>";
echo "<td><img src=get_image.php?id=".$row['0']." width=160 height=120/></td>";
echo "</tr>";
}
echo "</table>";
?>
***Here the get_image.php****
<?php
$con = mysqli_connect("localhost","root","");
mysqli_select_db($con,"gables");
$id = $_GET['id'];
$query = "SELECT * FROM residents WHERE id='$id'";
$result = mysqli_query($con,$query);
if($result)
$picture = mysqli_fetch_array($result);
header('Content-Type: image/jpg');
echo $picture['11'];
?>
You can chage the get_image.php file as this. Then this work will work.
<?php
function get_image($id){
$con = mysqli_connect("localhost","root","");
mysqli_select_db($con,"gables");
$query = "SELECT * FROM residents WHERE id='$id'";
$result = mysqli_query($con,$query);
if($result)
$picture = mysqli_fetch_array($result);
return $picture['11'];
}
?>
Then use require_once(); function and in image src like this.echo "<td><img src='".get_image($row['0'])."' width=160 height=120/></td>";. In your code check how the src path will print and it will be print like as echo string, not as a execute the file.
echo
"<table border='1'>
<tr>
<th>Id</th>
<th>Name</th>
<th>Last Name</th>
<th>Apartment</th>
<th>Parking</th>
<th>Phone1</th>
<th>Phone2</th>
<th>image</th>
</tr>";
require_once('search_r.php');
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['0'] . "</td>";
echo "<td>" . $row['1'] . "</td>";
echo "<td>" . $row['2'] . "</td>";
echo "<td>" . $row['3'] . "</td>";
echo "<td>" . $row['4'] . "</td>";
echo "<td>" . $row['5'] . "</td>";
echo "<td>" . $row['6'] . "</td>";
echo "<td><img src='".get_image($row['0'])."' width=160 height=120/></td>";
echo "</tr>";
}
echo "</table>";
every time user insert information and click add button, new data will store to database and echo into this table
table
<tr>
<td colspan="4" align="right">
<input type="image" value="image" src="images/btn_add.gif" onclick="action_1()">
</td>
</tr>
<tr>
<td colspan="2" class="title_all_u">Family Member Summary</td>
</tr>
<tr>
<td>
<?php
$query = "SELECT * FROM family_child WHERE LAS_login_id = ($emp_id)";
$result = mysql_query($query) or die(mysql_error());
echo "<table border='1'>
<tr>
<th>Family Type</th>
<th>Name</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['family_child_type'] . "</td>";
echo "<td>" . $row['family_child_name'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
</td>
</tr>
and this is insert query
if ( $action ==3 ) {
$spouse_type = $_POST['spouse_type'];
$spouse_name = $_POST['spouse_name'];
$sql1 = "INSERT INTO family_spouse (LAS_login_id, spouse_type, spouse_name) VALUES ('$LAS_login_id', '".strtoupper($spouse_type)."','".strtoupper($spouse_name)."')";
this 2 code is working for insert into database and echo in the page.
How can I add delete button below echo "<td>" . $row['family_child_name'] . "</td>"; for each row that I echo so user can delete the wrong row in the display table.
echo "<td>" . $row['family_child_name'] . " <a href='page.php&action=delete&id=family_name_id'>Delete</a></td>
Then in your page get (if action == delete) > execute your query to delete the row where the ID is the id of the family child name table.
$query = "SELECT * FROM family_child WHERE LAS_login_id = ($emp_id)";
$result = mysql_query($query) or die(mysql_error());
echo "<table border='1'>
<tr>
<th>Family Type</th>
<th>Name</th>
<th>Action</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>
<td>" . $row['family_child_type'] . "</td>
<td>" . $row['family_child_name'] . "</td>
<td>
<a href='../path/process.php?action=delete&id=".$row['family_child_id']."'>
DELETE RECORD
</a>
</td>
</tr>";
}
echo "</table>";
?>
on process page check action = delete and write query for delete there
family_child_id = ur primary key of table change according to ur table details
EDIT
PROCESS PAGE:
if($_GET["action"] == "delete")
{
$sql3="DELETE FROM family_child WHERE LAS_login_id =".$_GET["LAS_login_id"];
$result3 = mysql_query($sql3);
if (mysql_affected_rows() > 0)
{
header("location:dashboard.php?tab=1");
}
}
this coding working perfectly. i tried in my pc and posted this code here. it will insert the delete button automatically when u insert the new record. and then if u click delete button it will delete the row details in mysql db..
<body>
<?
echo "<tr>
<td>";
// your database connection
// select database
$query = ("SELECT * FROM family_child");
$result = mysql_query($query) or die(mysql_error());
echo "<table border=1>
<tr>
<th>Family Type</th>
<th>Name</th>
<th>Delete Record</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['family_child_type'] . "</td>";
echo "<td>" . $row['family_child_name'] . "</td>";
echo "<td><form method=post>
<input name=id type=hidden value='".$row['family_child_name']."';>
<input type=submit name=submit value=Delete>
</form></td>";
echo "</tr>";
}
echo "</table>";
echo "</td>
</tr>";
// delete record
if($_SERVER['REQUEST_METHOD'] == "POST")
{
if(isset($_POST['id']))
{
$id = mysql_real_escape_string($_POST['id']);
$sql = mysql_query("DELETE FROM family_child WHERE family_child_name ='$id'");
if(!$sql)
{
echo ("Could not delete rows" .mysql_error());
}
}
}
?>
I have a drop down list box with Veg,Non Veg and Senior Veg mess options.As soon as i select one type, the corresponding Hostel Admissionnumber,Student Name and Number of Days ( Text field which has to be enterd by the User) are displayed(From registration table). I want the displayed fields to Inserted into a table called 'student_month'.When i tried to insert, i get null values inserted into student_month table.I have pasted my code below, pls have a look.Any help would be appreciated. Thanks a lot.
<?php
$q=$_GET['messtype'];
echo "<html>
<head>
<form action='testbill.php' method='GET'>
<p><select name='messtype' id='Select1'>
<option value='1'>VEG</option>
<option value='2'>NON-VEG</option>
<option value='3'>SENIOR VEG MESS</option>
<p></select> </b>
<p><input type='submit'style='width:100;height:35' name='submit' value='Display details'>
</form>";
print "<div id='txtHint' align='center'><b>List of Student Details</b></div>";
if($q=='1')
{
$a=$_POST['hosteadmissionno'];
$b=$_POST['student_name'];
$con = mysql_connect('localhost', 'root', '');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("hostel", $con);
$a1="SELECT hosteladmissionno,student_name,semester FROM registration WHERE mess_type = 'VEG' AND status_flag=1";
$a2="INSERT into student_month(hosteladmissionno,student_name) values('$a','$b')";
$result = mysql_query($a1,$con);
$final=mysql_query($a2,$con);
echo "<table border='1' width=80%>
<tr>
<th width=5%> S.No</th>
<th width=10%>H.Admin No</th>
<th width=10%>Student Name</th>
<th width=5%>No of Days</th>
</tr>";
$i=0;
while($row = mysql_fetch_array($result))
{
$i=$i+1;
echo "<form action='testbill.php' method='POST'>";
echo "<tr>";
echo "<td align=center>" .$i."</td>";
echo "<td size=10 align=center>" . $row['hosteladmissionno'] . "</td>";
echo "<td size=35 align=center>" . $row['student_name'] . "</td>";
echo "<td align=center>"."<input type='text' name='days_mess' size=2>".$row['days_mess']. "</td> ";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
}
if($q=='2')
{
$con = mysql_connect('localhost', 'root', '');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("hostel", $con);
$a1="SELECT hosteladmissionno,student_name,semester FROM registration WHERE mess_type = 'NON-VEG' AND status_flag=1";
$a2="INSERT into student_month(hosteladmissionno,student_name) values('$a','$b')";
$result = mysql_query($a1,$con);
$final=mysql_query($a2,$con);
echo "<table border='1' width=80%>
<tr>
<th width=5%> S.No</th>
<th width=10%>H.Admin No</th>
<th width=10%>Student Name</th>
<th width=5%>No of Days</th>
</tr>";
$i=0;
while($row = mysql_fetch_array($result))
{
$i=$i+1;
echo "<form action='testbill.php' method='POST'>";
echo "<tr>";
echo "<td align=center>" .$i."</td>";
echo "<td size=10 align=center>" . $row['hosteladmissionno'] . "</td>";
echo "<td size=35 align=center>" . $row['student_name'] . "</td>";
echo "<td align=center>"."<input type='text' name='days_mess' size=2>".$row['days_mess']. "</td> ";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
}
if($q=='3')
{
$con = mysql_connect('localhost', 'root', '');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("hostel", $con);
$a1="SELECT hosteladmissionno,student_name,semester FROM registration WHERE mess_type = 'SENIOR-VEG-MESS' AND status_flag=1";
$a2="INSERT into student_month(hosteladmissionno,student_name) values('$a','$b')";
$result = mysql_query($a1,$con);
$final=mysql_query($a2,$con);
echo "<table border='1' width=80%>
<tr>
<th width=5%> S.No</th>
<th width=10%>H.Admin No</th>
<th width=10%>Student Name</th>
<th width=5%>No of Days</th>
</tr>";
$i=0;
while($row = mysql_fetch_array($result))
{
$i=$i+1;
echo "<form action='testbill.php' method='POST'>";
echo "<tr>";
echo "<td align=center>" .$i."</td>";
echo "<td size=10 align=center>" . $row['hosteladmissionno'] . "</td>";
echo "<td size=35 align=center>" . $row['student_name'] . "</td>";
echo "<td align=center>"."<input type='text' name='days_mess' size=2>".$row['days_mess']. "</td> ";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
}
if($result!='')
{
echo "<form action='testbill.php'>
<input type='submit' style='width:100;height:35'name='submit' value='calculate' /> </form>";
}
print "</html>";
?>
The variables '$a' and '$b' aren't escaped from the query string:
$a2="INSERT into student_month(hosteladmissionno,student_name) values('$a','$b')";
should be:
$a2="INSERT into student_month(hosteladmissionno,student_name) values('".$a."','".$b."')";
Use your IDE's syntax highlighting to help you (see difference above). ;)