Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
this is a code block to load data from database into a table structure in the page. the select statement is used to load data. but in the page it display the following error message mysqli error message
<div class="container">
<div class="row">
<h3>Company Overview </h3>
</div>
<div class="row">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Company</th>
<th>Overview</th>
<th>Address</th>
<th>Contact_Number</th>
<th>Created By</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php include('sessions.php');
$login_session;
$sql = 'SELECT * FROM company_overview where created_by LIKE "' . $login_session . '" '; ?>
<?php $result = mysqli_query($conn, $sql); ?>
<?php while ($row = mysqli_fetch_array($result)) {
?>
<?php echo '<tr>'; ?>
<?php echo '<td>' . $row['company_name'] . '</td>'; ?>
<?php echo '<td>' . $row['company_overview'] . '</td>'; ?>
<?php echo '<td>' . $row['address'] . '</td>'; ?>
<?php echo '<td>' . $row['contact_no'] . '</td>'; ?>
<?php echo '<td>' . $row['created_by'] . '</td>'; ?>
<?php echo '<td width=250>'; ?>
<?php echo '<a class="btn btn-success" href="update_p.php">Update</a>'; ?>
<?php echo ' '; ?>
<?php echo '<a class="btn btn-danger" href="delete_promotion.php?id=' . $row['id'] . '">Delete</a>'; ?>
<?php echo '</td>'; ?>
<?php echo '</tr>'; ?>
<?php include('o_sessions.php'); ?>
<?php } ?>
<?php //mysqli_close($conn); ?>
</tbody>
</table>
</div>
</div> <!-- /container -->
add appropriate column name after WHERE statement and add % in like:
$sql = 'SELECT * FROM company_overview where column_name LIKE "%'.$login_session.'%" ';
Use mysqli_num_rows() to check your query contain result or not.
Use column name with WHERE and use %..% with LIKE.
Your code contains extra open close <?php ?> please correct it.
Please check comments and change your code. I have added mysqli_num_rows() and prevent your code from error. Other things you can do it by yourself.
<?php
include('sessions.php');
$login_session;
$sql = 'SELECT * FROM company_overview where id LIKE "%'.$login_session.'%" ';
$result=mysqli_query($conn,$sql);
if(mysqli_num_rows($result) > 0)
{
while($row=mysqli_fetch_array($result))
{
?>
<?php echo '<tr>';?>
<?php echo '<td>'. $row['company_name'] . '</td>';?>
<?php echo '<td>'. $row['company_overview'] . '</td>';?>
<?php echo '<td>'. $row['address'] . '</td>';?>
<?php echo '<td>'. $row['contact_no'] . '</td>';?>
<?php echo '<td>'. $row['created_by'] . '</td>';?>
<?php echo '<td width=250>';?>
<?php echo '<a class="btn btn-success" href="update_p.php">Update</a>';?>
<?php echo ' ';?>
<?php echo '<a class="btn btn-danger" href="delete_promotion.php?id='.$row['id'].'">Delete</a>';?>
<?php echo '</td>';?>
<?php echo '</tr>';?>
<?php include('o_sessions.php');?>
<?php } }?>
<?php //mysqli_close($conn);?>
</tbody>
Related
I used to pass value from one page to another using session. E.g
page1.php
<?php
session_start();
$_SESSION["id"] = $id;
?>
page2.php
<?php
session_start();
echo $_SESSION["id"];
?>
But for the following case i don't know how can i pass the id to the next page. This code is used to display group of people and the action column have an option to view the people details.
<table>
<thead>
<tr>
<th>Name</th>
<th>Status</th>
<th>Created</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$DBSystemAccess = dbSelectByWhere("SystemAccess", "", "ORDER By Timestamp");
while ($SystemAccessDB = dbFetchArray($DBSystemAccess)) {
?>
<tr>
<?php
echo '<td>' . dbGroupNamebyId($_SESSION['PI_ID']) . '</td>';
echo '<td>' . $Status . '</td>';
echo '<td>' . $SystemAccessDB['timeStamp'] . '</td>';
echo '<td>' . '<a href="adetails.php?ID=' . $SystemAccessDB['id'] . '" >View</a> </td>'
?>
</tr>
<?php } ?>
</tbody>
How can i replace <a href="adetails.php?ID=' . $SystemAccessDB['id'] . '" >View</a> to not showing ID in the URL?
Please try this with the hyper link it is not possible to hide the GET data.We need to use POST method.
<table>
<thead>
<tr>
<th>Name</th>
<th>Status</th>
<th>Created</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$DBSystemAccess = dbSelectByWhere("SystemAccess", "", "ORDER By Timestamp");
while ($SystemAccessDB = dbFetchArray($DBSystemAccess)) {
?>
<tr>
<?php
echo '<td>' . dbGroupNamebyId($_SESSION['PI_ID']) . '</td>';
echo '<td>' . $Status . '</td>';
echo '<td>' . $SystemAccessDB['timeStamp'] . '</td>';
echo '<form name="test" method="post" action="testing.php">';
echo '<input type="hidden" name="hidden_name" value="'.$SystemAccessDB['id'].'"/>';
echo '<button type="submit">View</button>';
echo '</form>';
?>
</tr>
<?php } ?>
</tbody>
When you will click it will redirect to testing.php with hidden value 'hidden_name' on which you can further query according to that value.
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>
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I'm very new to PHP and I'm trying display a table like I did for PHP CRUD Grid(Look at image) but for some reason the foreach statement in index.php that I duplicated doesn't work. I get an error looking like this [
Invalid argument supplied for foreach() in Line 79
]1
I've also created a table using the following code
CREATE TABLE IF NOT EXISTS `category` (
`category_category_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`category_name` VARCHAR( 100 ) NOT NULL
) ENGINE = INNODB;
INSERT INTO `category` (`category_category_id`, `category_name`) VALUES
(1,'Drinks')
My data base looks like this on PHPmyadmin
This is the code that I used for the first grid:
include_once 'database.php';
$pdo = Database::connect();
$sql = 'SELECT * FROM product ORDER BY id DESC';
foreach ($pdo->query($sql) as $row) {
echo '<tr>';
echo '<td>'. $row['id'] . '</td>';
echo '<td>'. $row['category_id'] . '</td>';
echo '<td>'. $row['brand'] . '</td>';
echo '<td>'. $row['name'] . '</td>';
echo '<td>'. $row['barcode'] . '</td>';
echo '<td>'. $row['price'] . '</td>';
and this is the code with the error that I'm trying to duplicate for the second grid
$pdo = Database::connect();
$sql = 'SELECT * FROM category ORDER BY id DESC';
foreach ($pdo->query($sql) as $row) {
echo '<tr>';
echo '<td>'. $row['id'] . '</td>';
echo '<td>'. $row['category_name'] . '</td>';
index.php
<!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>PHP CRUD Grid</h3>
</div>
<div class="row">
<p>
Create
</p>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Id</th>
<th>CategoryId</th>
<th>Brand</th>
<th>Name</th>
<th>Barcode</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<?php
include_once 'database.php';
$pdo = Database::connect();
$sql = 'SELECT * FROM product ORDER BY id DESC';
foreach ($pdo->query($sql) as $row) {
echo '<tr>';
echo '<td>'. $row['id'] . '</td>';
echo '<td>'. $row['category_id'] . '</td>';
echo '<td>'. $row['brand'] . '</td>';
echo '<td>'. $row['name'] . '</td>';
echo '<td>'. $row['barcode'] . '</td>';
echo '<td>'. $row['price'] . '</td>';
echo '<td width=250>';
echo '<a class="btn" href="read.php?id='.$row['id'].'">Read</a>';
echo ' ';
echo '<a class="btn btn-success" href="update.php?id='.$row['id'].'">Update</a>';
echo ' ';
echo '<a class="btn btn-danger" href="delete.php?id='.$row['id'].'">Delete</a>';
echo '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
<div class="container">
<div class="row">
<h3>PHP CRUD Grid</h3>
</div>
<div class="row">
<p>
Create
</p>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>CategoryId</th>
<th>Category Name</th>
</tr>
</thead>
<?php
include_once 'database.php';
$pdo = Database::disconnect();
$pdo = Database::connect();
$sql = 'SELECT * FROM category ORDER BY id DESC';
foreach ($pdo->query($sql) as $row) {
echo '<tr>';
echo '<td>'. $row['id'] . '</td>';
echo '<td>'. $row['category_name'] . '</td>';
echo '<td width=250>';
echo '<a class="btn" href="readCategory.php?id='.$row['id'].'">Read</a>';
echo ' ';
echo '<a class="btn btn-success" href="updateCategory.php?id='.$row['id'].'">Update</a>';
echo ' ';
echo '<a class="btn btn-danger" href="deleteCategory.php?id='.$row['id'].'">Delete</a>';
echo '</td>';
echo '</tr>';
}
Database::disconnect();
?>
</tbody>
</table>
</div>
</div>
</body>
</html>
<!-- <div class="container">
<div class="row">
<h3>PHP CRUD Grid</h3>
</div>
<div class="row">
<p>
Create
</p>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>CategoryId</th>
<th>Catengory Name</th>
</tr>
</thead>
$sql2 = 'SELECT * FROM category ORDER BY id DESC';
foreach ($pdo->query($sql2) as $row) {
echo '<tr>';
echo '<td>'. $row['id'] . '</td>';
echo '<td>'. $row['category_name'] . '</td>';
echo '<td width=250>';
echo '<a class="btn" href="readCategory.php?id='.$row['id'].'">Read</a>';
echo ' ';
echo '<a class="btn btn-success" href="updateCategory.php?id='.$row['id'].'">Update</a>';
echo ' ';
echo '<a class="btn btn-danger" href="deleteCategory.php?id='.$row['id'].'">Delete</a>';
echo '</td>';
echo '</tr>';
</div>
}
Database::disconnect();
?>
</tbody>
</table> -->
I think it's because you don't have an id field in table category ? You have category_category_id
CREATE TABLE IF NOT EXISTS `category` (
`category_category_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`category_name` VARCHAR( 100 ) NOT NULL
) ENGINE = INNODB;
So...
$sql = 'SELECT * FROM category ORDER BY category_category_id DESC';
foreach ($pdo->query($sql) as $row) {
echo '<tr>';
echo '<td>'. $row['category_category_id'] . '</td>';
echo '<td>'. $row['category_name'] . '</td>';
You're trying to order by "id" when it's actually "category_category_id" in your db table. Change all references from id to category_category_id in the code in your loop too.
I am fetching data from Mysql database and populating them in a table.
However, i cannot seem to make the cell autofit to contents. I have tried width as the property of the table but i cant get it to work
Would really appreciate your help. Thanks
Here's what i have done so far
<div id="page-content-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<table class="table table-bordered" style="width:100%">
<thead>
<tr>
<th><center>ID</center></th>
<th>Name</th>
<th><center>Email</center></th>
<th>Number</th>
<th>Package</th>
<th>Flexibility</th>
<th >Date</th>
<th>Departuring From</th>
<th>Departure Date</th>
<th>Destination</th>
<th>Arrival Date</th>
<th>Price</th>
<th>Consolidator</th>
</tr>
</thead>
<tbody>
<?php
$query = 'SELECT * FROM queries';
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
echo '<tr>';
echo '<td>'. $row['id'] . '</td>';
echo '<td>'. $row['name'] . '</td>';
echo '<td>'. $row['email'] . '</td>';
echo '<td>'. $row['contactnumber'] . '</td>';
echo '<td>'. $row['packagedetails'] . '</td>';
echo '<td>'. $row['flexibility'] . '</td>';
echo '<td>'. $row['datetoday'] . '</td>';
echo '<td>'. $row['departure'] . '</td>';
echo '<td>'. $row['dateofdeparture'] . '</td>';
echo '<td>'. $row['destination'] . '</td>';
echo '<td>'. $row['dateofarrival'] . '</td>';
echo '<td>'. $row['price'] . '</td>';
echo '<td>'. $row['vendor'] . '</td>';
echo '<td width=250>';
echo '<a class="btn btn-success" href="readquery.php?id='.$row['id'].'">Read</a>';
echo ' ';
echo '<a class="btn btn-success" href="updatequery.php?id='.$row['id'].'">Update</a>';
echo ' ';
echo '<a class="btn btn-danger" href="deletequery.php?id='.$row['id'].'">Delete</a>';
echo '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
I never see you echo </tr> or </td>. It would be helpful to give us an output of the HTML being generated by your while loop.
The problem was not with my table. To make it work, i increased the width of my container in which my table was inside, and it worked
I have 2 search forms. One is linked to my local db of records and the other one links through an API to another db.
I want to now when my db does not have the required record, have it use the second search form without the user needing to insert the data again.
Is this possible and how do I go about merging the two?
Thanks for all the help guys.
Combination of form functions:
<div class="article">
<h2>
<br>
SEARCH A REFERENCE
<br>
</h2>
</center>
<body>
<div id="formsearch">
<br>
<form method="post" action="" name="form1" id="form1" >
Enter the ID Number
<br><br>
<b>Search Record </b> <input type="text" name="term" /><br />
<br>
<input type="submit" name="submit" value="Search" class="btn" />
</form>
</div>
<h3> <center> Search Result (s) </h3>
<?php
if ($_REQUEST['submit']) {
$term = $_POST['term'];
$row ['employerid'] == $user_data ['user_id'];
$XX = "<br><br><div class='messagebox'><h2> <center> Oops! </h2> <p>We were only to retrieve a partial record on <strong>$term</strong> you have entered. Please make use of our contact form if you would like us to get you your reference. Be sure to enter the three required fields. <a href='Mailforms/refrequest.php' class='lightbox'>Click Here!</a> or to validate the id <a href='idverification.php'> Click here</a></p>
<br />
</div>";
$sql = mysql_query("SELECT idnumber,
firstname,
lastname,
companyname,
jobtitle,
dismissal,
terminationdate,
startdate,
CONCAT(TIMESTAMPDIFF(YEAR,startdate,terminationdate), ' years and ',
MOD(TIMESTAMPDIFF(MONTH,startdate,terminationdate),12), ' months ') AS time_diff
FROM ref_employees
WHERE idnumber= '$term'")
or die('Error in query : $sql. ' .mysql_error());
if (mysql_num_rows($sql) > 0 ) {
while ($row = mysql_fetch_array($sql)){
if ($row ['employed'] == '1') {
echo '<h4>Currently Employed By : '.$row['companyname'];
echo '</h4> ';
echo 'Any doubts? Enquire about this candidate ';
}
if ($row ['employed'] == '0') {
echo ' <h4>Some Available Options For:</h4>';
include 'includes/admenu.php';
echo '<h4>Not Currently employed '.$row['companyname'];
echo '</h4> ';
}
echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>ID Number</th> <th>First Name</th> <th>Last Name</th><th>company</th> <th>Job Title</th> <th>Period</th><th>Reason for dismissal</th><th></th><th></th></tr>";
echo "<tr>";
echo '<td>' . $row['idnumber'] . '</td>';
echo '<td>' . $row['firstname'] . '</td>';
echo '<td>' . $row['lastname'] . '</td>';
echo '<td>' . $row['companyname'] . '</td>';
echo '<td>' . $row['jobtitle'] . '</td>';
echo '<td>' .($row['startdate'] + $row['terminationdate']).'</td>';
echo '<td>' . $row['dismissal'] . '</td>';
echo '<td>Achievements</td>';
echo '<td>training</td>';
echo "</tr>";
}
// close table>
echo "</table>";
}
}
else
{
$id_number = $_POST['term'];
$authenticate = authentication();
$login_message = $authenticate['error_code'];
$session_id = $authenticate['session_id'];
$id_verification = verify_id($session_id, $id_number);
}
if (!empty($id_verification)){
echo '<br/>';
echo '<h3>Search Information</h3>';
echo 'Time Stamp: ';
echo $id_verification['TIME_STAMP'];
echo 'SOAP Result: ';
echo $id_verification['LOGIN-MESSAGE'];
echo ' ';
echo $id_verification['SEARCH-MESSAGE'];
echo ' ';
echo $id_verification['SEARCH-RESULT'];
echo '<br/>';
echo '<h3>Data: </h3>';
echo '<br/>ID Number: ';
echo $id_verification['IDNUMBER'];
echo '<br/>First Names: ';
echo $id_verification['FIRSTNAMES'];
echo '<br/>Last Name: ';
echo $id_verification['SURNAME'];
echo '<br/>Birthday: ';
echo $id_verification['BIRTHDAY'];
echo '<br/>Age: ';
echo $id_verification['AGE'];
echo '<br/>Gender: ';
echo $id_verification['GENDER'];
echo '<br/>Citizen: ';
echo $id_verification['CITIZEN'];
echo '<br/>Death Status: ';
echo $id_verification['DEATH-STATUS'];
echo '<br/>Death Date: ';
echo $id_verification['DEATH-DATE'];
echo '<br/>Death Place: ';
echo $id_verification['DEATH-PLACE'];
unset($_SESSION['id_verification']);
}
mysql_free_result($sql);
mysql_close($connection);
?>
Send both search form into one location.
First you need to search into local if not again search it in API. Mean you need to do the search in single server file.
Hope this clear else post me in detail.