How can I add bid option in table? - php

I am beginner in php...
How to create a bids option from the table:
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Current Location</th>
<th>Country</th>
<th>State</th>
<th>City</th>
<th>Preferred Treatment Location</th>
<th>Country</th>
<th>State</th>
<th>City</th>
<th>Treatment & Surgery</th>
<th>Enter date</th>
<th>Medical Condition of Patient</th>
<th>BIDS</th>
</tr>
<?php
//Create Connection with MySQL Database
$con = mysqli_connect('localhost','root','root123');
//Select Database
if(!mysqli_select_db($con,'medical'))
{
echo "Database Not Selected";
}
//Select Query
$sql = "SELECT * FROM user_detail";
//Execute the SQL query
$records = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($records))
{
echo "<tr>";
echo "<td>".$row['id']."</td>";
echo "<td>".$row['fname']."</td>";
echo "<td>".$row['lname']."</td>";
echo "<td>".$row['clocation']."</td>";
echo "<td>".$row['country']."</td>";
echo "<td>".$row['state']."</td>";
echo "<td>".$row['city']."</td>";
echo "<td>".$row['treatment']."</td>";
echo "<td>".$row['country1']."</td>";
echo "<td>".$row['state1']."</td>";
echo "<td>".$row['city1']."</td>";
echo "<td>".$row['surgery']."</td>";
echo "<td>".$row['date']."</td>";
echo "<td>".$row['medicond']."</td>";
}
?>
</table>
Can you please help...

Related

PHP Transferring id through image

Hello the id that im getting is "$id" instead of the int id what i would like to happen is that basically it will go to the full size of the image in the "showImage.php"
<?php
while($row = mysqli_fetch_array($result)) {
$id = $row[0];
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[7]."</td>";
echo "<td>".$row[8]."</td>";
echo "<td>".$row[9]."</td>";
echo "<td>".$row[10]."</td>";
echo '<td>
<img id="$id" src="data:image/jpeg;base64,'.base64_encode($row[11] ).'" height="200" width="200" />
</td> ';
?>
in case you're wondering this is the html
<tr>
<th>ID</th>
<th>Voter's ID</th>
<th>Username</th>
<th>Password</th>
<th>Email</th>
<th>Confirmation Code</th>
<th>UserType </th>
<th>Age</th>
<th>Gender</th>
<th>Birthday</th>
<th>Action</th>
<th>Image</th>
<tr>

Column name field showing multiple time in php?

I am searching records and records are displaying from database, but column name is repeating.Please check below images.
<table border="1" align="center">
<thead>
<tr>
<th>User id</th>
<th>First Name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM newrecords_1 WHERE CONCAT( First_name, ' ',Last_name ) LIKE '%$name%' ORDER BY `First_name` ASC";
$result = $conn->query($query);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {?>
<tr>
<td><?php echo $row['ID'];?></td>
<td><?php echo $row['First_name'];?></td>
<td><?php echo $row['Last_name'];?></td>
</tr>
</tbody>
</table>
<?php
}
} else {
echo "0 results";
}
What i am getting
What i need
after added html code on header getting output
Put your table code outside of the loop like below :-
<table border="1" align="center">
<thead>
<tr>
<th>User id</th>
<th>First Name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM newrecords_1 WHERE CONCAT( First_name, ' ',Last_name ) LIKE '%$name%' ORDER BY `First_name` ASC";
$result = $conn->query($query);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {?>
<tr>
<td><?php echo $row['ID'];?></td>
<td><?php echo $row['First_name'];?></td>
<td><?php echo $row['Last_name'];?></td>
</tr>
<?php } } else { echo "0 results";}?>
</tbody>
</table>
You are getting header part after every fetching because you are using header part also in loop. Place header part above loop and keep only
below code in loop.
<tr>
<td><?php echo $row['ID'];?></td>
<td><?php echo $row['First_name'];?></td>
<td><?php echo $row['Last_name'];?></td>
</tr>

PHP - How can I nest a while loop inside an if isset condition?

I have this table element with the following code:
<?php
if(isset($_POST["submit"])){
if (strlen($cIdMsg = 0) && strlen($cFirstNameMsg = 0) && strlen($cLastNameMsg = 0) && strlen($pCodeMsg = 0)) {
require_once("conn.php");
$sql2 = "SELECT * FROM customer;";
$results = mysqli_query($conn, $sql2)
or die ('Problem with query' . mysqli_error($conn));
echo "no errors found";
}
}
?>
<table>
<tr>
<th>Customer ID</th>
<th>FIrst Name</th>
<th>Last Name </th>
</tr>
<?php
while ($row = mysqli_fetch_array($results)) { ?>
<tr>
<td><?php echo $row["customerID"]?></td>
<td><?php echo $row["firstName"]?></td>
<td><?php echo $row["lastName"]?></td>
</tr>
<?php } ?>
</table>
Above this table I have the php code that makes the sql queries inside an if isset condition so that it only loads after pressing submit on the form. I would like to do the same to the table. That is to only make it load after pressing submit. because on page load it is trying to do the mysqli_fetch_array on a non existent $result yet
Wrap the whole table inside:
<?php if (isset($result)) { ?>
<table>
<tr>
<th>Customer ID</th>
<th>FIrst Name</th>
<th>Last Name </th>
</tr>
<?php
while ($row = mysqli_fetch_array($results)) { ?>
<tr>
<td><?php echo $row["customerID"]?></td>
<td><?php echo $row["firstName"]?></td>
<td><?php echo $row["lastName"]?></td>
</tr>
<?php } ?>
</table>
<?php } ?>
I have used isset($result) based on what you have said. You can check for the POST values by checking for count($_POST), or something similar (not a good idea to check for isset($_POST["submit"])). If you are fetching for AJAX Response, it is always better to use a different separate file for this.
<?php if(mysqli_num_rows($result)!=0) { ?>
<table>
<tr>
<th>Customer ID</th>
<th>FIrst Name</th>
<th>Last Name </th>
</tr>
<?php
while ($row = mysqli_fetch_array($results)) { ?>
<tr>
<td><?php echo $row["customerID"]?></td>
<td><?php echo $row["firstName"]?></td>
<td><?php echo $row["lastName"]?></td>
</tr>
<?php } ?>
</table>
<?php } ?>

Put dropdown box and image link in table

<html>
<style>
table {
border-collapse: collapse;
}
table,th,td{
border: 1px solid black;
border-collapse: collapse;
}
tr:hover {background-color: #f5f5f5}
th,tr {
text-align: center;
}
table {
margin-left: auto;
margin-right: auto;
width: 75%;
}
th, td {
padding: 15px;
}
</style>
</html>
<?php
include 'dbLink.php';
include 'navi.php';
$sql = "SELECT * FROM employee";
$query = "SELECT * FROM employeerole ORDER BY role_id";
$result = mysqli_query($link, $sql);
$result1 = mysqli_query($link, $query);
$rowcount = mysqli_num_rows($result);
if ($rowcount > 0)
{?>
How do I input a drop down list and a image link in each table row? Also, when i run this page, only the data in the first row is reflected in the table. The rest of the data is not in the table. Any fixes?
<table>
<tr>
<th>Employee ID</th>
<th>First name</th>
<th>Last Name</th>
<th>Username</th>
<th>Employee Role</th>
<th>Edit role</th>
<th>Delete User</th>
</tr>
<?php
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
{?>
<tr>
<td><?php echo $row["id"];?></td>
<td><?php echo $row["first_name"];?></td>
<td><?php echo $row["last_name"];?></td>
<td><?php echo $row["username"];?></td>
<td><?php echo $row["role"];?></td>
<td>//dropdwon list with data from employeerole table</td>
<td>//image link</td>
</tr>
</table>
<?php}?>
<?php
}
}
else
{
echo "0 results";
}
?>
Screenshot
You have mixed Object Oriented Style & Procedural Style for writing query. So, be particular about Object Oriented or Procedural way of writing query.
I've written a code for you in both way. Go Ahead.
1) Object Oriented Style
dbLink.php
<?
$link = new mysqli("localhost", "my_user", "my_password", "world");
?>
Edited Code
$sql = "SELECT * FROM employee";
$query = "SELECT * FROM employeerole ORDER BY role_id";
$result = $link->query($sql);
$result1 = $link->query($query);
$rowcount = $result->num_rows;
if ($rowcount > 0)
{?>
<table>
<tr>
<th>Employee ID</th>
<th>First name</th>
<th>Last Name</th>
<th>Username</th>
<th>Employee Role</th>
<th>Edit role</th>
<th>Delete User</th>
</tr>
<?php
while ($row = $result->fetch_array(MYSQLI_ASSOC))
{?>
<tr>
<td><?php echo $row["id"];?></td>
<td><?php echo $row["first_name"];?></td>
<td><?php echo $row["last_name"];?></td>
<td><?php echo $row["username"];?></td>
<td><?php echo $row["role"];?></td>
<td></td>
<td></td>
</tr>
<?php}?>
</table>
<?php }
else
{
echo "0 results";
}
?>
2) Procedural Style
dbLink.php
<?
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
?>
Edited Code
$sql = "SELECT * FROM employee";
$query = "SELECT * FROM employeerole ORDER BY role_id";
$result = mysqli_query($link, $sql);
$result1 = mysqli_query($link, $query);
$rowcount = mysqli_num_rows($result);
if ($rowcount > 0)
{?>
<table>
<tr>
<th>Employee ID</th>
<th>First name</th>
<th>Last Name</th>
<th>Username</th>
<th>Employee Role</th>
<th>Edit role</th>
<th>Delete User</th>
</tr>
<?php
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
{?>
<tr>
<td><?php echo $row["id"];?></td>
<td><?php echo $row["first_name"];?></td>
<td><?php echo $row["last_name"];?></td>
<td><?php echo $row["username"];?></td>
<td><?php echo $row["role"];?></td>
<td></td>
<td></td>
</tr>
<?php }?>
</table>
<?php }
else
{
echo "0 results";
}
?>
User's Requirement : Updated Code
<?
$result = mysqli_query($link, $sql);
$result1 = mysqli_query($link, $query);
$rowcount = mysqli_num_rows($result);
if ($rowcount > 0)
{?>
<table>
<tr>
<th>Employee ID</th>
<th>First name</th>
<th>Last Name</th>
<th>Username</th>
<th>Employee Role</th>
<th>Edit role</th>
<th>Delete User</th>
</tr>
<?php
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
{?>
<tr>
<td><?php echo $row["id"];?></td>
<td><?php echo $row["first_name"];?></td>
<td><?php echo $row["last_name"];?></td>
<td><?php echo $row["username"];?></td>
<td><?php echo $row["role"];?></td>
<td>//dropdwon list with data from employeerole table</td>
<td>//image link</td>
</tr>
<?php }?>
</table>
<?php
} else {
echo "0 results";
}
?>

Display database table in PHP array

I am trying to display my table from my MySQL database. It doesn't seem to work, I guess it's most likely something simple. If possible I would like to have the table look like just a normal table with no frills; just a border and to be able to fit in a normal sized page. This is what I have so far:
<html>
<head>
<title>Profile Database </title>
</head>
<body>
<?
$connection = "connect.php";
require $connection;
mysql_select_db("bank");
$sql = "SELECT * FROM profiles";
$result = mysql_query($sql);
?>
<table border="2" style= "background-color: #84ed86; color: #761a9b; margin: 0 auto;" >
<thead>
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>E-Mail</th>
<th>DOB</th>
<th>Age</th>
<th>City</th>
<th>State</th>
<th>Zip Code</th>
<th>Offence</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
<?php
while( $row = mysql_fetch_assoc( $result ))
{
echo <tr>
<td>{$row\['id'\]}</td>
<td>{$row\['fname'\]}</td>
<td>{$row\['lname'\]}</td>
<td>{$row\['email'\]}</td>
<td>{$row\['dob'\]}</td>
<td>{$row\['age'\]}</td>
<td>{$row\['city'\]}</td>
<td>{$row\['state'\]}</td>
<td>{$row\['zip'\]}</td>
<td>{$row\['offence'\]}</td>
<td>{$row\['notes'\]}</td>
</tr>\n;
}
?>
</tbody>
</table>
<?php
mysql_close($connection);
?>
</body>
</html>
Give this a go:
<table>
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>E-Mail</th>
<th>DOB</th>
<th>Age</th>
<th>City</th>
<th>State</th>
<th>Zip Code</th>
<th>Offence</th>
<th>Notes</th>
</tr>
<?php
require "connect.php";
mysql_select_db("bank");
$result = mysql_query("SELECT * FROM profiles");
while($row = mysql_fetch_array($result, MYSQL_NUM)) {
echo '<tr>';
foreach($row as $column) {
echo '<td>', $column, '</td>';
}
echo '</tr>';
}
?>
</table>
WHILE($row = mysql_fetch_array($result))
should be either
WHILE($row = mysql_fetch_array($result, MYSQL_ASSOC))
OR
WHILE($row = mysql_fetch_assoc($result))
Also the mysql_* functions have been deprecated and relying on them is HIGHLY discouraged.
Kindly check the below discussions :-
Deprecated MySql Functions
How to successfully rewrite old mysql-php code with deprecated mysql_* functions?
http://php.net/manual/en/migration55.deprecated.php
Use either MySQLi or PDO.
<center><table border="1">
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>E-Mail</th>
<th>DOB</th>
<th>Age</th>
<th>City</th>
<th>State</th>
<th>Zip Code</th>
<th>Offence</th>
<th>Notes</th>
</tr>
<?
$connection = "connect.php";
require $connection;
mysql_select_db("bank");
$sql = "SELECT * FROM profiles";
$result = mysql_query($sql);
WHILE($row = mysql_fetch_array($result))
{
$id = $row ['id'];
$firstname = $row ['fname'];
$lastname = $row ['lname'];
$email = $row ['email'];
$dob = $row ['dob'];
$age = $row ['age'];
$city = $row ['city'];
$state = $row ['state'];
$zip = $row ['zip'];
$offence = $row ['offence'];
$nots = $row ['notes'];
echo '<tr>'; // change here
echo '<td>'.$id.'</td>';
echo '<td>'.$firstname.'</td>';
echo '<td>'.$lastname.'</td>';
echo '<td>'.$email.'</td>';
echo '<td>'.$dob.'</td>';
echo '<td>'.$age.'</td>';
echo '<td>'.$city.'</td>';
echo '<td>'.$state.'</td>';
echo '<td>'.$zip.'</td>';
echo '<td>'.$offence.'</td>';
echo '<td>'.$notes.'</td>';
echo '</tr>'; // change here
}
mysql_close();
?>
</table></center>
Try this code:
<?php
$username = "your_name";
$password = "your_password";
$hostname = "localhost";
$dbconnect = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
$select=mysql_select_db("bank",$dbconnect) or die("Could not select bank");
$sql = "SELECT * FROM profiles";
$result = mysql_query($sql);
?>
<center><table border="1">
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>E-Mail</th>
<th>DOB</th>
<th>Age</th>
<th>City</th>
<th>State</th>
<th>Zip Code</th>
<th>Offence</th>
<th>Notes</th></tr>
<?php
while($row = mysql_fetch_array($result))
{
$id = $row ['id'];
$firstname = $row ['fname'];
$lastname = $row ['lname'];
$email = $row ['email'];
$dob = $row ['dob'];
$age = $row ['age'];
$city = $row ['city'];
$state = $row ['state'];
$zip = $row ['zip'];
$offence = $row ['offence'];
$nots = $row ['notes'];
echo '<tr>';
echo '<td>'.$id.'</td>';
echo '<td>'.$firstname.'</td>';
echo '<td>'.$lastname.'</td>';
echo '<td>'.$email.'</td>';
echo '<td>'.$dob.'</td>';
echo '<td>'.$age.'</td>';
echo '<td>'.$city.'</td>';
echo '<td>'.$state.'</td>';
echo '<td>'.$zip.'</td>';
echo '<td>'.$offence.'</td>';
echo '<td>'.$notes.'</td>';
echo '</tr>';
}
?>
</table></center>
<?php
mysql_close();
?>
Corrected Code:
<html>
<head>
<title>Profile Database </title>
</head>
<body>
<?php
$connection = "connect.php";
require $connection;
mysql_select_db("bank");
$sql = "SELECT * FROM profiles";
$result = mysql_query($sql);
?>
<table border="2" style= "background-color: #84ed86; color: #761a9b; margin: 0 auto;" >
<thead>
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>E-Mail</th>
<th>DOB</th>
<th>Age</th>
<th>City</th>
<th>State</th>
<th>Zip Code</th>
<th>Offence</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
<?php
while( $row = mysql_fetch_assoc( $result ))
{
?>
<tr>
<td><?php echo $row['id'];?></td>
<td><?php echo $row['fname'];?></td>
<td><?php echo $row['lname'];?></td>
<td><?php echo $row['email'];?></td>
<td><?php echo $row['dob'];?></td>
<td><?php echo $row['age'];?></td>
<td><?php echo $row['city'];?></td>
<td><?php echo $row['state'];?></td>
<td><?php echo $row['zip'];?></td>
<td><?php echo $row['offence'];?></td>
<td><?php echo $row['notes'];?></td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php
mysql_close($connection);
?>
</body>
</html>

Categories