replace edit and delete with icon - php

i need to change the edit and delete button on this table with icons
im trying too much with 500 error :(
echo "<tr>";
echo "<td>{$userSet['user_id']}</td>";
echo "<td>{$userSet['username']}</td>";
echo "<td>{$userSet['password']}</td>";
echo "<td><a href='delete_user.php?user_id={$userSet['user_id']}'>Delete</a></td>";
echo "<td><a href='edit_user.php?user_id={$userSet['user_id']}'>Edit</a></td>";
echo "</tr>";

Put img tag inside the a href attribute.
echo "<td><a href='delete_user.php?user_id={$userSet['user_id']}'><img src='path/to/img'></a></td>";
echo "<td><a href='edit_user.php?user_id={$userSet['user_id']}'><img src='path/to/img'></a></td>";

Related

I'd like to retrieve images from phpMyAdmin database and display them on an HTML table

The images are stored as a BLOB type in my database. I want the user to be able to click on a 'View Inventory' button and be taken to a page with an HTML table that displays images for each item.
This is the table in my php file:
echo "<table border='1'>";
echo "<tr>";
echo "<th>Categor</th>";
echo "<th>Description</th>";
echo "<th>Unit Cost</th>";
echo "<th>XS Quantity</th>";
echo "<th>S Quantity</th>";
echo "<th>M Quantity</th>";
echo "<th>L Quantity</th>";
echo "<th>XL Quantity</th>";
echo "<th>XXL Quantity</th>";
echo "<th>XXXL Quantity</th>";
echo "<th>Image</th>";
echo "<th></th>";
echo "</tr>";
while($row=mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>{$row['category']}</td>";
echo "<td>{$row['description']}</td>";
echo "<td>$ {$row['unitCost']}</td>";
echo "<td>{$row['xsQuantity']}</td>";
echo "<td>{$row['sQuantity']}</td>";
echo "<td>{$row['mQuantity']}</td>";
echo "<td>{$row['lQuantity']}</td>";
echo "<td>{$row['xlQuantity']}</td>";
echo "<td>{$row['xxlQuantity']}</td>";
echo "<td>{$row['xxxlQuantity']}</td>";
echo "<td><img src='Downloads/".$row['apparelImage']."'></td>";
echo "<td><a href='#'>Add</a></td>";
echo "</tr>";
}
echo "</table>";
If your image is stored as blob, you can't do echo "<td><img src='Downloads/".$row['apparelImage']."'></td>";
You should print a img tag which will handling your image. Pass row ID in src attribute of this tag and get it in script. Then, get the record from database and set headers to show image.
Like:
echo '<img src="script_to_show_image.php?id=' . $row['id'] . '">';
In script_to_show_image.php, after get record from database, you must set headers to print image correctly:
header("Content-Type: image/jpeg");
Then, print the content:
echo $apparelImage;

Why cannot call the div #popup1?

Why cannot call the div #popup1? I want to pass the $row['staffId'] to div and call the popup to show the information .
$result = mysql_query("SELECT * FROM Staff WHERE companyId='$companyIdResult'");
echo "<div>
<table >";
while($row = mysql_fetch_array($result)){
echo "<tr>";
echo "<td >" . $row['staffName'] . "</td>";
echo "<td>" . $row['staffPhone'] . "</td>";
echo "<td><a class ='editbutton' href=' #popup1?edit_id=".$row['staffId'] ."'>Edit</a></td>";
echo "</tr>";
}
echo "</table>";
echo "</div>";
if($_GET['edit_id'] != ""){
$staffId = $_GET['edit_id'];
$sql2 = mysql_query("SELECT *FROM Staff WHERE staffId='".$staffId."'");
echo '<div id="popup1" class="overlay" >';
echo '<div class="popup">';
echo '<input type="text" name="staffName" value= ".$row['staffName']." ><br>';
echo '<input type="text" name="staffPhone" value=".$row['staffPhone']."><br>';
echo '</div>';
echo '</div>';
}
First of all you cannot append query parameters (?edit_id=...) to an anchor like #popup1, also you seem to misunderstand how PHP and the browser interact, you cannot open a popup and create it dynamically on the server side the way you seem to plan to. You could use AJAX to load the matching form for the staffId into your popup or generate a popup for every staffId beforehand (and create matching links with different anchors), but you try to open a popup1 with values generated on the server side and that doesn't work in this way.

How can I display each record individually into a while loop?

I use this while loop to display events from facebook. I want to add an href link in each record that will open a new tab displaying only this event. I have created links for each record but I can't understand how I can make the link to lead to that event.
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<table class='table table-hover table-responsive table-bordered'>";
echo "<tr>";
echo "<td rowspan='6' style='width:20em;'>";
echo "<img src=". $row["COVER_PHOTO"]." width='200px' />";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td style='width:15em;'>What:</td>";
echo "<td><b>". $row["NAME"]."</b></td>";
echo "</tr>";
//owner
echo "<tr>";
echo "<td>Who:</td>";
echo "<td>". $row["OWNER"]."</td>";
echo "</tr>";
echo "<tr>";
echo "<td>What kind:</td>";
echo "<td>". $row["PAGE_CAT"]."</td>";
echo "</tr>";
echo "<tr>";
echo "<td>When:</td>";
echo "<td>". $row["START_DATE"]." at ". $row["START_TIME"]."</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Where:</td>";
echo "<td>". $row["PLACE"]."</td>";
echo "</tr>";
echo "<tr>";
echo "<td>";
echo "<a href='view.php?more=". $row["EVENT_ID"]."' target='_blank' <?php echo >Λεπτομέρειες</a>";
echo "<tr>";
echo "<td>Description:</td>";
echo "<td>". $row["DESCRIPTION"]."</td>";
echo "</tr>";
Your code for this page is just fine. Now to display each individual event in the view.php file, you will need to access the data (in your case the event ID, stored in more variable) sent via GET method in the view.php page, as thus:
view.php
<?php
if(isset($_GET['more']))
{
$more = $_GET['more'];
}
?>
The value of the more variable sent via the URL will now be saved in the $more PHP variable. For example, if the page called is view.php?view=22, the $more variable will have the value of 22.
You can now use this $more variable - which stores the event ID - to fetch whatever other detail you require.
echo "<a href='view.php?more=". $row["EVENT_ID"]."' target='_blank'> Λεπτομέρειες</a>";

Outputting PHP within a HTML tag in PHP

Kind of stuck on this one issue, tried all the ways of outputting regular HTML in PHP which works fine, but when trying get PHP code and then making that into HTML link where everything is in PHP. Line 17 & 18 is the issue, this maybe very simple to someone, but its proven difficult for me :(
Any help is much appreciated. Thanks in advance
<?php
if($output == true) {
echo "<td>".$id."</td>";
echo "<td>".$fname."</td>";
echo "<td>".$lname."</td>";
echo "<td>".$dob."</td>";
echo "<td>".$gender."</td>";
echo "<td>".$hnumber."</td>";
echo "<td>".$mnumber."</td>";
echo "<td>".$email."</td>";
echo "<td>".$username."</td>";
echo "<td>".$address."</td>";
echo "<td>".$type."</td>";
echo "<td><a href='memberdelete.php?id=".$rows['ID']."'>Delete</a></td>"; echo "<td><a href='memberedit.php?id=".$rows['ID']."'>Edit</a></td>";
echo "</tr>";
echo "</table>";
}
?>
Change it to,
echo "<td><a href='memberdelete.php?id=".$rows['ID']."'>Delete</a></td>";
Useful: How strings work in PHP ?
Try this, I wrote it quickly, hope it work:
echo '<td>Delete</td>';
echo '<td>Edit</td>';
Horrible enclosing of quotes and multiple echo on same line was your problem.
Update to:
echo "<td><a href='memberdelete.php?id=".$rows['ID']."'>Delete</a></td>";
echo "<td><a href='memberedit.php?id=".$rows['ID']."'>Edit</a></td>";
You can do this for the above code:
<?php
if($output == true) {
echo "<td>".$id."</td>";
echo "<td>".$fname."</td>";
echo "<td>".$lname."</td>";
echo "<td>".$dob."</td>";
echo "<td>".$gender."</td>";
echo "<td>".$hnumber."</td>";
echo "<td>".$mnumber."</td>";
echo "<td>".$email."</td>";
echo "<td>".$username."</td>";
echo "<td>".$address."</td>";
echo "<td>".$type."</td>";
echo "<td><a href='memberdelete.php?id=".$rows['ID']."'>Delete</a></td>";
echo "<td><a href='memberedit.php?id=".$rows['ID']."'>Edit</a></td>";
echo "</tr>";
echo "</table>";
}
?>
You have misplaced the quotes and html tags.so
change
echo "<td>".Delete."</td>";
echo "<td>".<a href="memberedit.php<?php echo '?id='.$rows['ID']; ?>"
to
echo "<td><a href='memberdelete.php?id=$rows[ID]'>Delete</a></td>";
echo "<td><a href='memberedit.php'?id='$rows[ID]'>Edit</a></td>";
If you have problem with quotes and assigning values to parameters inside quotes try HEREDOC
You have incorrect strings.
changes those lines:
echo "<td>".Delete."</td>";
echo "<td>".<a href="memberedit.php<?php echo '?id='.$rows['ID']; ?>"
to:
echo "<td>Delete</td>";
echo "<td><a href=\"memberedit.php<?php echo '?id='.$rows['ID']; ?> </td>"

attach hyperlink to dynamic table cell

I have a table in generated using PHP using data collected from MYSQL. How do I append a hyperlink to a row?
Here is the code for the dynamic table I am using:
mydata = mysql_query($sql,$con);
echo "<table id='name',table border=0>
<tr>
<th>Users</th>
<th>Status<th>
</tr>";
while($record = mysql_fetch_array($mydata)){
echo "<tr>";
echo "<td>" . $record['user_id'] . "</td>";
if (strtolower(trim($record['activity']))!=strtolower('LOGIN')){
echo "<td>" . $default1 . "</td>";
}else{
echo "<td>" . $default . "</td>";
}
echo "</tr>";
}
echo "</table>";
;
I have tried appending a href="..." style="display:block;"> but cannot get it to work.
Try echoing out a hyperlink.
echo "<a href='http://www.google.com/'>Google</a>";
If you want other functionality, such as clicking on a table row to work as a hyperlink, you would need to implement that in javascript as a table cell/row is not a hyperlink.

Categories