Hi i want to href after user click a button
This is my current code but it's not working. After I click, the confirmation will come out but it doesn't go to PHadmin_approveHospital.php after I click on.
echo "<input type=\"submit\" value=\"Approve\">";
Full Function
public function displayAllHospital() {
$sql = "SELECT * FROM hospital";
$result = #mysqli_query($this->conn, $sql);
echo "<table class='table table-bordered'>";
echo "<thead>";
echo "<tr>";
echo "<th>ID # <i class='fa fa-sort'></i></th>";
echo "<th>Name </th>";
echo "<th>Email </th>";
echo "<th>Contact Number <i class='fa fa-sort'></i></th>";
echo "<th>Status </th>";
echo "<th>Actions</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while($row = mysqli_fetch_assoc($result)){
echo "<tr>";
echo "<td>" . $row["HospitalID"] . "</td>";
echo "<td>" . $row["Hospitalname"] . "</td>" ;
echo "<td>" . $row["email"] . "</td>" ;
echo "<td>" . $row["contactno"] . "</td>" ;
echo "<td>" . $row["status"] . "</td>" ;
echo "<td>";
echo "<a href=\"PHadmin_editHospital.php?id=".$row["HospitalID"]."\" class='view' title='View' data-toggle='tooltip'><i class='material-icons'></i></a>";
echo "<a href=\"PHadmin_editHospital.php?id=".$row["HospitalID"]."\" class='edit' title='Edit' data-toggle='tooltip'><i class='material-icons'></i></a>";
echo "<a href=\"PHadmin_deleteHospital.php?id=".$row["HospitalID"]."\" onclick=\"return confirm('do you want to delete Y/N')\" class='delete' title='Delete' data-toggle='tooltip'><i class='material-icons'></i></a>";
echo "</td>";
echo "<td>";
if($row["status"] == "pending"){
echo "<input type=\"submit\" value=\"Approve\">";
}
echo "</td>";
echo "</tr>";
echo "</tbody>";
echo "</form>";
echo "</tr>";
}
echo "</table>";
}
Thanks for helping.
You may call a javascript function when you click the button, and then display the confirmation message, so that the user can confirm or not (if confirmed, jump to the url)
You may use the following code :
<input type="button" value='Approve' onclick="javascript:check1();">
<script>
function check1() {
if(confirm("Do you want to approve?")) {
window.location.href="PHadmin_approveHospital.php?id=<?php echo $row["HospitalID"]. '\'; ?>";
}
}
</script>
So , for your updated code, it will be:
<?php
public function displayAllHospital() {
echo '
<script>
function check1(var1) {
if(confirm("Sure to delete ?")) {
window.location.href="PHadmin_deleteHospital.php?id=" +var1;
}
}
function check2(var2) {
if(confirm("Sure to approve ?")) {
window.location.href="PHadmin_approveHospital.php?id=" + var2;
}
}
</script>';
$sql = "SELECT * FROM hospital";
$result = #mysqli_query($this->conn, $sql);
echo "<table class='table table-bordered'>";
echo "<thead>";
echo "<tr>";
echo "<th>ID # <i class='fa fa-sort'></i></th>";
echo "<th>Name </th>";
echo "<th>Email </th>";
echo "<th>Contact Number <i class='fa fa-sort'></i></th>";
echo "<th>Status </th>";
echo "<th>Actions</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while($row = mysqli_fetch_assoc($result)){
echo "<tr>";
echo "<td>" . $row["HospitalID"] . "</td>";
echo "<td>" . $row["Hospitalname"] . "</td>" ;
echo "<td>" . $row["email"] . "</td>" ;
echo "<td>" . $row["contactno"] . "</td>" ;
echo "<td>" . $row["status"] . "</td>" ;
echo "<td>";
echo "<a href=\"PHadmin_editHospital.php?id=".$row["HospitalID"]."\" class='view' title='View' data-toggle='tooltip'><i class='material-icons'></i></a>";
echo "<a href=\"PHadmin_editHospital.php?id=".$row["HospitalID"]."\" class='edit' title='Edit' data-toggle='tooltip'><i class='material-icons'></i></a>";
echo "<input type=button value=Delete onclick='javascript:check1(". $row["HospitalID"] . ")';>";
echo "</td>";
echo "<td>";
if($row["status"] == "pending"){
echo "<input type=button value=Approve onclick='javascript:check2(". $row["HospitalID"] . ")';>";
}
echo "</td>";
echo "</tr>";
echo "</tbody>";
echo "</form>";
echo "</tr>";
}
echo "</table>";
}
?>
Related
Currently, I create a table that displays data from the database (JSON). In that table, I want to check is the data exists or not. Let's say if data is empty, I want to display "No booking data available at these moments".
The problem is, I don't know how to check the existing data. For now, if the data is empty, the table appears with <th> only and no words "No booking data available at these moments".
Below is my current code:
<?php
//retrieve json
$url = "http://172.20.0.45/TGWebService/TGWebService.asmx/displayAdminBookingDashboard?adminEmail=$Email";
$data = file_get_contents($url);
$json = json_decode($data);
if(empty($json)){
echo "<div class='card bg-light'>";
echo "<div class='card-body double' style='height: 400px;>";
echo "<h4 class='card-title'><i>No booking data available at this moments</i></h4>";
}else{
echo "<div class='card bg-light'>";
echo "<div class='card-body double' style='height: 400px; overflow-y: scroll;'>";
echo "<h4 class='card-title'>All Booking</h4>";
echo "<table>";
echo "<thead>";
echo "<tr>";
echo "<th>#</th>
<th>Requester</th>
<th>Factory</th>
<th>Room</th>
<th>Purpose</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody >";
foreach ($json->bookingList as $row) {
$status=$row->status;
if($status=="Approve"){
$color="color:green";
}else if($status=="Pending"){
$color="color:blue";
}else{
$color="color:red";
}
echo "<tr>";
echo "<td>" . $row->bookNo. "</td>";
echo "<td>" . $row->requestedBy. "</td>";
echo "<td>" . $row->facID. "</td>";
echo "<td>" . $row->roomName. "</td>";
echo "<td>" . $row->desc. "</td>";
echo "<td style='$color'><strong>" . $status ."</strong></td>";
echo "<td>";
echo "<a class='btn-view btn-primary btn-sm' href='../../view_booking/admin/view_booking_admin.php?Book_No=". $row->bookNo ."' data-toggle='tooltip'>View</a>";
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table><br>";
echo "</div>";
echo "<div>";
}
?>
Try the following code:
<?php
//retrieve json
$url = "http://172.20.0.45/TGWebService/TGWebService.asmx/displayAdminBookingDashboard?adminEmail=$Email";
$data = #file_get_contents($url);
$json = json_decode($data);
if($json === FALSE && empty($json)){
echo "<div class='card bg-light'>";
echo "<div class='card-body double' style='height: 400px;>";
echo "<h4 class='card-title'><i>No booking data available at this moments</i></h4>";
}else{
echo "<div class='card bg-light'>";
echo "<div class='card-body double' style='height: 400px; overflow-y: scroll;'>";
echo "<h4 class='card-title'>All Booking</h4>";
echo "<table>";
echo "<thead>";
echo "<tr>";
echo "<th>#</th>
<th>Requester</th>
<th>Factory</th>
<th>Room</th>
<th>Purpose</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody >";
foreach ($json->bookingList as $row) {
$status=$row->status;
if($status=="Approve"){
$color="color:green";
}else if($status=="Pending"){
$color="color:blue";
}else{
$color="color:red";
}
echo "<tr>";
echo "<td>" . $row->bookNo. "</td>";
echo "<td>" . $row->requestedBy. "</td>";
echo "<td>" . $row->facID. "</td>";
echo "<td>" . $row->roomName. "</td>";
echo "<td>" . $row->desc. "</td>";
echo "<td style='$color'><strong>" . $status ."</strong></td>";
echo "<td>";
echo "<a class='btn-view btn-primary btn-sm' href='../../view_booking/admin/view_booking_admin.php?Book_No=". $row->bookNo ."' data-toggle='tooltip'>View</a>";
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table><br>";
echo "</div>";
echo "<div>";
}
?>
I already solved my question. I just add "bookingList" at the empty json
<?php
//retrieve json
$url = "http://172.20.0.45/TGWebService/TGWebService.asmx/displayAdminBookingDashboard?adminEmail=$Email";
$data = file_get_contents($url);
$json = json_decode($data);
if(empty($json->bookingList)){
echo "<div class='card bg-light'>";
echo "<div class='card-body double' style='height: 400px;>";
echo "<h4 class='card-title'><i>No booking data available at this moments</i></h4>";
}else{
echo "<div class='card bg-light'>";
echo "<div class='card-body double' style='height: 400px; overflow-y: scroll;'>";
echo "<h4 class='card-title'>All Booking</h4>";
echo "<table>";
echo "<thead>";
echo "<tr>";
echo "<th>#</th>
<th>Requester</th>
<th>Factory</th>
<th>Room</th>
<th>Purpose</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody >";
foreach ($json->bookingList as $row) {
$status=$row->status;
if($status=="Approve"){
$color="color:green";
}else if($status=="Pending"){
$color="color:blue";
}else{
$color="color:red";
}
echo "<tr>";
echo "<td>" . $row->bookNo. "</td>";
echo "<td>" . $row->requestedBy. "</td>";
echo "<td>" . $row->facID. "</td>";
echo "<td>" . $row->roomName. "</td>";
echo "<td>" . $row->desc. "</td>";
echo "<td style='$color'><strong>" . $status ."</strong></td>";
echo "<td>";
echo "<a class='btn-view btn-primary btn-sm' href='../../view_booking/admin/view_booking_admin.php?Book_No=". $row->bookNo ."' data-toggle='tooltip'>View</a>";
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table><br>";
echo "</div>";
echo "<div>";
}
?>
I am trying to visualise variables in PHP using isset(), when I am not using it, a notice comes out saying that the index is undefined.
I am trying to output variables in the tabled using the aforementioned function, but with it, the tables do not output any values.
[
<?php
// Include config file
require_once "config.php";
// Attempt select query execution
$sql = "SELECT * FROM courses";
if($result = $pdo->query($sql)){
if($result->rowCount() > 0){
echo "<table class='table table-bordered table-striped'>";
echo "<thead>";
echo "<tr>";
echo "<th>#</th>";
echo "<th>Enquiry ID</th>";
echo "<th>Course Name</th>";
echo "<th>Course Level</th>";
echo "<th>Action</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while($row = $result->fetch()){
echo "<tr>";
echo "<td>" . isset($row\['courseid'\]) . "</td>";
echo "<td>" . isset($row\['enquiryid'\]) . "</td>";
echo "<td>" . isset($row\['coursename'\]) . "</td>";
echo "<td>" . isset($row\['courselevel'\]) . "</td>";
echo "<td>";
echo "<a href='read.php?id=". isset($row\['courseid'\]) ."' title='View Record' data-toggle='tooltip'><span class='glyphicon glyphicon-eye-open'></span></a>";
echo "<a href='update.php?id=". isset($row\['courseid'\]) ."' title='Update Record' data-toggle='tooltip'><span class='glyphicon glyphicon-pencil'></span></a>";
echo "<a href='delete.php?id=". isset($row\['courseid'\]) ."' title='Delete Record' data-toggle='tooltip'><span class='glyphicon glyphicon-trash'></span></a>";
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
// Free result set
unset($result);
} else{
echo "<p class='lead'><em>No records were found.</em></p>";
}
} else{
echo "ERROR: Could not able to execute $sql. " . $mysqli->error;
}
// Close connection
unset($pdo);
?>
]1
I expect the output of the values included in the database tables, but the fields still continue blank.
isset() returns true or false. You can't echo it out directly. You need a conditional that uses isset() to check a variable and display it when true.
On the assumption you're running PHP 7, you can use the null coalescing operator. This acts as a shorthand for a ternary that either results in the variable or a blank string depending on whether the variable is set:
echo "<td>" . $row['courseid'] ?? '' . "</td>";
Documentation: https://php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op
This is the equivalent of:
echo "<td>" . isset($row['courseid']) ? $row['courseid'] : '' . "</td>";
If you were forced to use that ternary method however, I'd probably wrap it in a function for convenience.
This isset() Function Returns True/False, So you can not echo out the value directly.
So it's better to use single line condition with isset()
Like i've written below
echo "<td>" . isset($row['courseid']) ? $row['courseid'] : 'Not Set' . "</td>";
I rewrote your while loop as an example:
while($row = $result->fetch()){
echo "<tr>";
if (isset($row['courseid'])){
echo "<td>" . $row['courseid']) . "</td>";
} else {
echo "<td>" . 'NOT SET' . "</td>";
}
if (isset($row['enquiryid'])){
echo "<td>" . $row['enquiryid'] . "</td>";
} else {
echo "<td>" . 'NOT SET' . "</td>";
}
if (isset($row['coursename'])){
echo "<td>" . $row['coursename']. "</td>";
} else {
echo "<td>" . 'NOT SET' . "</td>";
}
if (isset($row['courselevel'])){
echo "<td>" . $row['courselevel']) . "</td>";
} else {
echo "<td>" . 'NOT SET' . "</td>";
}
echo "<td>";
echo "<a href='read.php?id=". $row['courseid'] ."' title='View Record' data-toggle='tooltip'><span class='glyphicon glyphicon-eye-open'></span></a>";
echo "<a href='update.php?id=". $row['courseid'] ."' title='Update Record' data-toggle='tooltip'><span class='glyphicon glyphicon-pencil'></span></a>";
echo "<a href='delete.php?id=". $row\'courseid'] ."' title='Delete Record' data-toggle='tooltip'><span class='glyphicon glyphicon-trash'></span></a>";
echo "</td>";
echo "</tr>";
}
Hope that helps
I want to add "book" button to each car product.But it only display only one button for first car only.
$sql = "SELECT * FROM car";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table>";
echo "<tr>";
echo "<th>Id</th>";
echo "<th>Name</th>";
echo "<th>Price(RM)</th>";
echo "<th>Colour</th>";
echo "<th>Mode</th>";
echo "<th>Image</th>";
echo "<th>Status</th>";
echo "<td><button onclick=\"book_car('" . $row['car_id'] .
"')\">Book</button></td>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['car_id'] . "</td>";
echo "<td>" . $row['car_name'] . "</td>";
echo "<td>" . $row['car_price'] . "</td>";
echo "<td>" . $row['car_colour'] . "</td>";
echo "<td>" . $row['car_mode'] . "</td>";
echo "<td><img src='" . $row['car_image'] . "' height='100'
width='100'></td>";
echo "<td>" . $row['car_status'] . "</td>";
echo "</tr>";
}
There is no error.But i just want "book" button display for each car products.
This is simply because your button is out of the while loop !
Also you did not close first tr tag .
Correct code :
$sql = "SELECT * FROM car";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table>";
echo "<tr>";
echo "<th>Id</th>";
echo "<th>Name</th>";
echo "<th>Price(RM)</th>";
echo "<th>Colour</th>";
echo "<th>Mode</th>";
echo "<th>Image</th>";
echo "<th>Status</th>";
echo "<th>action</th>";<!-- Added this line -->
echo "</tr>";<!-- Added this line -->
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['car_id'] . "</td>";
echo "<td>" . $row['car_name'] . "</td>";
echo "<td>" . $row['car_price'] . "</td>";
echo "<td>" . $row['car_colour'] . "</td>";
echo "<td>" . $row['car_mode'] . "</td>";
echo "<td><img src='" . $row['car_image'] . "' height='100'
width='100'></td>";
echo "<td>" . $row['car_status'] . "</td>";
echo "<td><button onclick=\"book_car('" . $row['car_id'] .
"')\">Book</button></td>";<!-- Replaced This line -->
echo "</tr>";
}
echo "</table>";
I hope this helps you :)
Hi i am trying to submit the multiple form values only from one button i have 10 records and one record has one button of submit and 10 records have 10 buttons of submit what i want there should be only one button of submit and i can submit he whole 10 records from one button:
echo "<table class='table table-hover table-responsive table-bordered'>";
// our table heading
echo "<tr>";
echo "<th class='textAlignLeft'>Product Name</th>";
echo "<th>Price</th>";
echo "<th style='width:5em;'>Quantity</th>";
echo "<th>Image</th>";
echo "<th>Action</th>";
echo "</tr>";
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
extract($row);
//creating new table row per record
echo "<tr>";
echo "<td>";
echo "<div class='product-id' style='display:none;'>{$id}</div>";
echo "<div class='product-name'>{$name}</div>";
echo "</td>";
echo "<td>$" . number_format($price, 2, '.' , ',') . "</td>";
if(isset($quantity)){
echo "<td>";
echo "<input type='text' name='quantity' value='{$quantity}' disabled class='form-control' />";
echo "</td>";
echo "<td>";
echo "<td>";
echo "<button class='btn btn-success' disabled>";
echo "<span></span> Submitted!";
echo "</button>";
echo "</td>";
echo "</td>";
}else{
echo "<td>";
echo "<input type='number' name='quantity[]' value='1' class='form-control'/>";
echo "</td>";
echo "<td><img src='product-images/{$image}' width='60' height='60'</td>";
echo "<td>";
echo "<button class='btn btn-primary add-to-cart'>";
echo "<span></span>Submit to cart";
echo "</button>";
echo "</td>";
}
echo "</tr>";
}
echo "</table>";
}
what i want only one button from i can submit all my values: Any help would be high appreciated:
$action = isset($_GET['action']) ? $_GET['action'] : "";
$product_id = isset($_GET['product_id']) ? $_GET['product_id'] : "1";
$name = isset($_GET['name']) ? $_GET['name'] : "";
$quantity = isset($_GET['quantity']) ? $_GET['quantity'] : "1";
$image = isset($_GET['image']) ? $_GET['image'] : "1";
if($action=='added'){
echo "<div class='alert alert-info'>";
echo "<strong>{$name}</strong> added to your cart!";
echo "</div>";
}
else if($action=='failed'){
echo "<div class='alert alert-info'>";
echo "<strong>{$name}</strong> failed to add to your cart!";
echo "</div>";
}
// left join to select products
$query = "SELECT p.id, p.name, p.price, p.image, ci.quantity
FROM products p
LEFT JOIN cart_items ci
ON p.id = ci.product_id
ORDER BY p.name";
$stmt = $con->prepare( $query );
$stmt->execute();
// count number of products returned
$num = $stmt->rowCount();
HTML CODE
<?php
// connect to database
include 'config/db_connect.php';
// page headers
$page_title="Cart";
include 'layout_head.php';
// parameters
$action = isset($_GET['action']) ? $_GET['action'] : "";
$name = isset($_GET['name']) ? $_GET['name'] : "";
$image = isset($_GET['image']) ? $_GET['image'] : "";
// display a message
if($action=='removed'){
echo "<div class='alert alert-info'>";
echo "<strong>{$name}</strong> was removed from your cart!";
echo "</div>";
}
else if($action=='quantity_updated'){
echo "<div class='alert alert-info'>";
echo "<strong>{$name}</strong> quantity was updated!";
echo "</div>";
}
else if($action=='failed'){
echo "<div class='alert alert-info'>";
echo "<strong>{$name}</strong> quantity failed to updated!";
echo "</div>";
}
else if($action=='invalid_value'){
echo "<div class='alert alert-info'>";
echo "<strong>{$name}</strong> quantity is invalid!";
echo "</div>";
}
// select products in the cart
$query="SELECT p.id, p.name, p.price, p.image, ci.quantity, ci.quantity * p.price AS subtotal
FROM cart_items ci
LEFT JOIN products p
ON ci.product_id = p.id";
$stmt=$con->prepare( $query );
$stmt->execute();
// count number of rows returned
$num=$stmt->rowCount();
if($num>0){
//start table
echo "<table class='table table-hover table-responsive table-bordered'>";
// our table heading
echo "<tr>";
echo "<th class='textAlignLeft'>Product Name</th>";
echo "<th>Price</th>";
echo "<th style='width:15em;'>Quantity</th>";
echo "<th>Sub Total</th>";
echo "<th>Action</th>";
echo "</tr>";
$total=0;
while( $row = $stmt->fetch(PDO::FETCH_ASSOC)){
extract($row);
echo "<tr>";
echo "<td>";
echo "<div class='product-id' style='display:none;'>{$id}</div>";
echo "<div class='product-name'>{$name}</div>";
echo "</td>";
echo "<td>$" . number_format($price, 2, '.', ',') . "</td>";
echo "<td>";
echo "<div class='input-group'>";
echo "<input type='number' name='quantity[]' value='{$quantity}' class='form-control'>";
echo "<span class='input-group-btn'>";
echo "<button class='btn btn-default update-quantity' type='button'>Update</button>";
echo "</span>";
echo "</div>";
echo "</td>";
echo "<td>$" . number_format($subtotal, 2, '.', ',') . "</td>";
echo "<td>";
echo "<a href='remove_from_cart.php?id={$id}&name={$name}' class='btn btn-danger'>";
echo "<span></span> Delete from cart";
echo "</a>";
echo "</td>";
echo "</tr>";
$total += $subtotal;
}
echo "<tr>";
echo "<td><b>Total</b></td>";
echo "<td></td>";
echo "<td></td>";
echo "<td>$" . number_format($total, 2, '.', ',') . "</td>";
echo "<td>";
echo "</a>";
echo "</td>";
echo "</tr>";
echo "</table>";
}else{
echo "<div class='alert alert-danger'>";
echo "<strong>No products found</strong> in your cart!";
echo "</div>";
}
include 'layout_foot.php';
?>
Use name quantity[] instead of quantity.By this way you can receive post data as an array. After the loop use only one submit button.
echo "<input type='number' name='quantity[]' value='1' class='form-control'/>";
Then receive it by using foreach
foreach($_POST['quantity'] as $qty)
{
echo $qty;
//Here you will receive all the quantities one by one.
}
Form the code
<?php
echo "<table class='table table-hover table-responsive table-bordered'>";
// our table heading
echo "<tr>";
echo "<th class='textAlignLeft'>Product Name</th>";
echo "<th>Price</th>";
echo "<th style='width:5em;'>Quantity</th>";
echo "<th>Image</th>";
echo "</tr>";
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
extract($row);
//creating new table row per record
echo "<tr>";
echo "<td>";
echo "<div class='product-id' style='display:none;'>{$id}</div>";
echo "<div class='product-name'>{$name}</div>";
echo "</td>";
echo "<td>$" . number_format($price, 2, '.' , ',') . "</td>";
if(isset($quantity)){
echo "<td>";
echo "<input type='text' name='quantity[]' value='{$quantity}' disabled class='form-control' />";
echo "</td>";
echo "<td>";
echo "</td>";
echo "<td>";
echo "</td>";
}else{
echo "<td>";
echo "<input type='number' name='quantity[]' value='1' class='form-control'/>";
echo "</td>";
echo "<td><img src='product-images/{$image}' width='60' height='60'</td>";
echo "<td>";
echo "</td>";
}
echo "</tr>";
}
echo "<tr><td colspan='4'>";
echo "<button class='btn btn-primary add-to-cart' type='submit'>";
echo "<span></span>Submit to cart";
echo "</button>";
echo "</td></tr>";
echo "</table>";
I have a mysql table with a row that is either going to be a 0 or a 1. However, I want to be able to display the table with PHP and have 0 show up as no, and 1 show up as yes. I am still a beginner with PHP and have been searching for a way to do it, but have had no luck. The row in question is the 'masterwork' row. The line of code I thought would do it is
$row['masterwork'] = ( intval( $row['masterwork']) == 1) ? "YES" : "NO";
Here is the code that displays the table:
<?php
$con=mysqli_connect("localhost","username","password","database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM weapons");
$row['masterwork'] = ( intval( $row['masterwork']) == 1) ? "YES" : "NO";
while($row = mysqli_fetch_array($result))
{
echo "<center>";
echo "<table border='1' class='display'>";
echo "<tr>";
echo "<td>Weapon Name: </td>";
echo "<td>" . $row['weaponName'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Creator: </td>";
echo "<td>" . $row['creator'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Weapon Category: </td>";
echo "<td>" . $row['weaponCategory'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Weapon Sub-Category: </td>";
echo "<td>" . $row['weaponSubCategory'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Cost: </td>";
echo "<td>" . $row['costAmount'] . " " . $row['costType'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Damage(S): </td>";
echo "<td>" . $row['damageS'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Damage(M): </td>";
echo "<td>" . $row['damageM'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Critical: </td>";
echo "<td>" . $row['critical'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Range Increment: </td>";
echo "<td>" . $row['rangeIncrement'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Weight: </td>";
echo "<td>" . $row['weight'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Weapon Type: </td>";
echo "<td>" . $row['weaponType'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Masterwork: </td>";
echo "<td>" . $row['masterwork'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Special Abilities: </td>";
echo "<td>" . $row['specialAbilities'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Additional Info: </td>";
echo "<td>" . $row['additionalInfo'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo "</center>";
mysqli_close($con);
?>
try this --
$result = mysqli_query($con,"SELECT * FROM weapons");
while($row = mysqli_fetch_array($result))
{
$row['masterwork'] = ( intval( $row['masterwork']) == 1) ? "YES" : "NO";
echo "<center>";
echo "<table border='1' class='display'>";
echo "<tr>";
echo "<td>Weapon Name: </td>";
echo "<td>" . $row['weaponName'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Creator: </td>";
echo "<td>" . $row['creator'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Weapon Category: </td>";
echo "<td>" . $row['weaponCategory'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Weapon Sub-Category: </td>";
echo "<td>" . $row['weaponSubCategory'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Cost: </td>";
echo "<td>" . $row['costAmount'] . " " . $row['costType'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Damage(S): </td>";
echo "<td>" . $row['damageS'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Damage(M): </td>";
echo "<td>" . $row['damageM'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Critical: </td>";
echo "<td>" . $row['critical'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Range Increment: </td>";
echo "<td>" . $row['rangeIncrement'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Weight: </td>";
echo "<td>" . $row['weight'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Weapon Type: </td>";
echo "<td>" . $row['weaponType'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Masterwork: </td>";
echo "<td>" . $row['masterwork'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Special Abilities: </td>";
echo "<td>" . $row['specialAbilities'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Additional Info: </td>";
echo "<td>" . $row['additionalInfo'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo "</center>";
mysqli_close($con);
?>