PHP Transferring id through image - php

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>

Related

Conditional formatting php table

I need help with a simple task, but I am stuck...
I have a database where I pull different data and I am visualizing those data on a web page.
Here is my query for getting the data:
$result = mysqli_query($mysqli, "SELECT *, DATEDIFF(nextcalibration, CURDATE()) AS days FROM tools AS dp ");
Here is my table:
<table id="table_id" class="table table-striped">
<tr>
<th>Nr</th> <th>Status</th> <th>name</th> <th>Serial</th> <th>Used At</th> <th>Owner</th> <th>Calibrated</th> <th>nextcalibration</th> <th>vendor</th> <th>days</th> <th>actions</th>
</tr>
<?php
while($user_data = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>".$user_data['toolnr']."</td>";
echo "<td>".$user_data['status']."</td>";
echo "<td>".$user_data['toolname']."</td>";
echo "<td>".$user_data['serial']."</td>";
echo "<td>".$user_data['usedat']."</td>";
echo "<td>".$user_data['owner']."</td>";
echo "<td>".$user_data['calibrated']."</td>";
echo "<td>".$user_data['nextcalibration']."</td>";
echo "<td>".$user_data['vendors']."</td>";
echo "<td>".$user_data['days']. "</td>";
echo "<td><a href='edit.php?id=$user_data[id]'><img src='img/edit.png' ></a> | <a href='delete.php?id=$user_data[id]' onclick='return checkDelete()'><img src='img/delete.png'></a></td></tr>";
}
?>
</table>
I would like to make conditional formatting only for the last column - "days".
The idea is if the value of "days" <= 30 to become red color text.
I tried with various JS, but honestly, it did not work.
<table id="table_id" class="table table-striped">
<tr>
<th>Nr</th> <th>Status</th> <th>name</th> <th>Serial</th> <th>Used At</th> <th>Owner</th> <th>Calibrated</th> <th>nextcalibration</th> <th>vendor</th> <th>days</th> <th>actions</th>
</tr>
<?php
while($user_data = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>".$user_data['toolnr']."</td>";
echo "<td>".$user_data['status']."</td>";
echo "<td>".$user_data['toolname']."</td>";
echo "<td>".$user_data['serial']."</td>";
echo "<td>".$user_data['usedat']."</td>";
echo "<td>".$user_data['owner']."</td>";
echo "<td>".$user_data['calibrated']."</td>";
echo "<td>".$user_data['nextcalibration']."</td>";
echo "<td>".$user_data['vendors']."</td>";
echo "<td>";
$days=$user_data['days'];
if($days <= 30){
echo "<span style='color:red;'>$days</span>";
}else{
echo $days;
}
echo "</td>";
echo "<td><a href='edit.php?id=$user_data[id]'><img src='img/edit.png' ></a> | <a href='delete.php?id=$user_data[id]' onclick='return checkDelete()'><img src='img/delete.png'></a></td></tr>";
}
?>
</table>
Would something simple like this - without JS- work?
<table id="table_id" class="table table-striped">
<tr>
<th>Nr</th> <th>Status</th> <th>name</th> <th>Serial</th> <th>Used At</th> <th>Owner</th> <th>Calibrated</th> <th>nextcalibration</th> <th>vendor</th> <th>days</th> <th>actions</th>
</tr>
<?php
while($user_data = mysqli_fetch_array($result))
{
$style_days=($user_data['days']<=30)?'style="color:red"':'';
echo "<tr>";
echo "<td>".$user_data['toolnr']."</td>";
echo "<td>".$user_data['status']."</td>";
echo "<td>".$user_data['toolname']."</td>";
echo "<td>".$user_data['serial']."</td>";
echo "<td>".$user_data['usedat']."</td>";
echo "<td>".$user_data['owner']."</td>";
echo "<td>".$user_data['calibrated']."</td>";
echo "<td>".$user_data['nextcalibration']."</td>";
echo "<td>".$user_data['vendors']."</td>";
echo "<td ".$style_days.">".$user_data['days']. "</td>";
echo "<td><a href='edit.php?id=$user_data[id]'><img src='img/edit.png' ></a> | <a href='delete.php?id=$user_data[id]' onclick='return checkDelete()'><img src='img/delete.png'></a></td></tr>";
}
?>
</table>
Of course, apply the necessary guarding for $user_data['days'] (existence, numeric..) :)

instant delete when the button is cliked

im trying to delete from a datatable when i click the remove button the data will be removed for a quick action in the admin side but my code dose not work i tried to fix it but i don't see any problem in the code here is my code
<div class="table-responsive">
<table id="datas" class="table table-striped table-bordered fixed" style="width:100%">
<thead style="color:black;" >
<th>id</th>
<th>Company Name</th>
<th>Product Name</th>
<th>Weight</th>
<th>Price Per Gram</th>
<th>Quantity</th>
<th>Type</th>
<th>Category</th>
<th>Product Price</th>
<th>Image</th>
<th>Total Price</th>
<th class="text-center">Actions</th>
</thead>
<?php
$get = mysqli_query($conn,"SELECT * FROM stock;");
?>
<tbody>
<?php
while ($row=mysqli_fetch_array($get)) {
$id=$row['id'];
$company=$row['company_name'];
$name=$row['product_name'];
$weight=$row['weight'];
$price_per_gram=$row['price_per_gram'];
$quantity=$row['quantity'];
$type=$row['type'];
$category=$row['category'];
$price=$row['product_price'];
$img=$row['img'];
$total=$row['total_price'];
?>
<tr>
<td ><?php echo $id;?></td>
<td><?php echo $company;?></td>
<td><?php echo $name;?></td>
<td><?php echo $weight;?> g</td>
<td><?php echo $price_per_gram;?> $</td>
<td><?php echo $quantity;?></td>
<td><?php echo $type;?></td>
<td><?php echo $category;?></td>
<td><?php echo $price;?></td>
<td>
<img src="product_img/<?php echo $img; ?>" style="height:5rem;width:5rem;border-radius:10px;">
</td>
<td><?php echo $total;?></td>
<td style="width: 20px"> Edit
<button class="btn btn-danger" name="delete" type="submit" value="<?php echo "$id" ?>">Delete</button> </td>
</tr>
<?php } ?>
</tbody>
</table>
<?php
if (isset($_POST['delete'])) {
$delete = mysqli_query($conn,"DELETE FROM stock WHERE id= ".$_POST['delete']." ");
header("location:viewstcok.php");
} ?>
i give the delete button a value when clicked so it will delete with that value but it did not seems to work can any one help me
you have to placed table inside <form></form> tag
<div class="table-responsive">
<form>
<table id="datas" class="table table-striped table-bordered fixed" style="width:100%">
<thead style="color:black;" >
<th>id</th>
<th>Company Name</th>
<th>Product Name</th>
<th>Weight</th>
<th>Price Per Gram</th>
<th>Quantity</th>
<th>Type</th>
<th>Category</th>
<th>Product Price</th>
<th>Image</th>
<th>Total Price</th>
<th class="text-center">Actions</th>
</thead>
<?php
$get = mysqli_query($conn,"SELECT * FROM stock;");
?>
<tbody>
<?php
while ($row=mysqli_fetch_array($get)) {
$id=$row['id'];
$company=$row['company_name'];
$name=$row['product_name'];
$weight=$row['weight'];
$price_per_gram=$row['price_per_gram'];
$quantity=$row['quantity'];
$type=$row['type'];
$category=$row['category'];
$price=$row['product_price'];
$img=$row['img'];
$total=$row['total_price'];
?>
<tr>
<td ><?php echo $id;?></td>
<td><?php echo $company;?></td>
<td><?php echo $name;?></td>
<td><?php echo $weight;?> g</td>
<td><?php echo $price_per_gram;?> $</td>
<td><?php echo $quantity;?></td>
<td><?php echo $type;?></td>
<td><?php echo $category;?></td>
<td><?php echo $price;?></td>
<td>
<img src="product_img/<?php echo $img; ?>" style="height:5rem;width:5rem;border-radius:10px;">
</td>
<td><?php echo $total;?></td>
<td style="width: 20px"> Edit
<button class="btn btn-danger" name="delete" type="submit" value="<?php echo "$id" ?>">Delete</button> </td>
</tr>
<?php } ?>
</tbody>
</table>
</form>
<?php
if (isset($_POST['delete'])) {
$delete = mysqli_query($conn,"DELETE FROM stock WHERE id= ".$_POST['delete']." ");
header("location:viewstcok.php");
} ?>

How can I add bid option in table?

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...

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 Table - Different Hyperlink on each row

What I am trying to do is get it so there is a different hyper link address for each row echoed. Code is below:
echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>Product Name</th> <th>Product Description</th> <th>Product Price</th> <th>Product Image</th> <th>View Product Details</th></tr>";
while($row = mysql_fetch_array( $result )) {
echo "<tr>";
echo '<td>' . $row['Product_Name'] . '</td>';
echo '<td>' . $row['Product_Description'] . '</td>';
echo '<td>' . $row['Product_Price'] . '</td>';
echo '<td>Picture Enlarge</td>';
echo '<td>View Details</td>';
echo "</tr>";
}
echo "</table>";
You can put php variables inline in your echo'ed anchors just as you are doing with the other variables.
Assuming that you're using the id field in your database you can do this:
echo '<td>View Details</td>';
If you echo a php variable (e.g. $row['id']) then it will echo out to HTML (not necessarily text). So as this one is contained in an anchor tag (in the HTML) it echos to the anchor tag and builds the id part. :)
<table border='1' cellpadding='10'>
<tr>
<th>Product Name</th>
<th>Product Description</th>
<th>Product Price</th>
<th>Product Image</th>
<th>View Product Details</th>
</tr>
while($row = mysql_fetch_array( $result )) {
<tr>
<td> <?php echo $row['Product_Name']; ?></td>
<td><?php echo $row['Product_Description']; ?></td>
<td><?php $row['Product_Price']; ?></td>
<td>Picture Enlarge</td>
<td>View Details</td>
</tr>
}
</table>
I would probably go for something like that. This assumes that your table returns a unique id, from something like an auto incremented column.
This doesn't include any escaping so could be vulnerable to exploitation. I would also look into templating. It may help you with your presentation, makes it a little easier to read the mixed html and php.
"<td align=\"center\" valign=\"top\"><<") . "</td>\n"

Categories