delete mysql_array_fetch - mysql

I have the following code and the plan is to display the data from the database but allow for the administrator of the site to delete a row if a job is no longer available. I have put "Delete" where I would like a link to delete the row.I have tried using <a href='delete1.php?del=$row[JobID]'>Delete</a> but that just throws an error up on the page.
<?php
include_once('db.php');
$result = mysqli_query($con,"SELECT * FROM Job ORDER BY JobID");
echo "<table border='1'>
<tr>
<th>Job ID</th>
<th>Job Title</th>
<th>Job Description</th>
<th>Industry</th>
<th>Job Type</th>
<th>Salary</th>
<th>County</th>
<th>Town</th>
<th>Delete</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['JobID'] . "</td>";
echo "<td>" . $row['JobTitle'] . "</td>";
echo "<td>" . $row['JobDescription'] . "</td>";
echo "<td>" . $row['Industry'] . "</td>";
echo "<td>" . $row['JobType'] . "</td>";
echo "<td>" . $row['Salary'] . "</td>";
echo "<td>" . $row['County'] . "</td>";
echo "<td>" . $row['Town'] . "</td>";
echo "<td>" . "Delete" . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>

You should put this in the the listing code:
echo "<a href='delete1.php?del={$row['JobID']}'>Delete</a>";
(documentation)
Then, in your delete1.php you should have something like:
$jobid = intval($_GET['JobID']);
if ($jobid > 0) {
mysqli_query($con, "DELETE FROM Job WHERE JobID=$jobid LIMIT 1");
}
(note: this is untested and can be quite insecure; it only shows the concept on how to do this)

Related

Display specific number of rows inside an HTML table

I have included some javascript above the setup of my table that I thought would allow me to choose the number of rows but I can't seem to figure out why it doesn't work. The scroll function works but that is the only responsive part of the table.
<script type="text/javascript">
$(document).ready(function() {
$('#example').DataTable( {
responsive: true,
"pageLength": 10
} );
} );
</script>
<div style="height:700px; overflow-y: scroll;">
<table id = "example">
<tr>
<th align="center"> ID</th>
<th>Item Name</th>
<th>Suggested Quantity</th>
<th>Order Quantity</th>
</tr>
<?php
while ($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $row['item_id'] ."</td>";
echo "<td>" . $row['ITEM_NAME'] . "</td>";
echo "<td>" . $row['suggested_qty'] . "</td>";
echo "<td>" . $row['suggested_qty'] . "</td>";
echo "</tr>";
}
?>
</table>
</div>

echoing out # symbol when pulling emails from mysql database in WP page

Here is the code I'm using that is pulling all data fields nicely from mysql database. But email addresses are being displayed as user%40domainname.com instead of standard email output of user#domainname.com.
$myData = mysql_query($sql);
echo "<table class='table table-hover table-bordered table-striped'>
<tr>
<th>Username</th>
<th>Email</th>
<th>Score</th>
</tr>";
while($record = mysql_fetch_array($myData)) {
echo "<tr>";
echo "<td>" . $record['id'] . "</td>";
echo "<td>" . $record['email'] . "</td>";
echo "<td>" . $record['score'] . "</td>";
echo "</tr>";
}
echo "</table>";
You can use urldecode to solve this:
$email = 'user%40domainname.com';
echo urldecode($email); //user#domainname.com
demo: http://ideone.com/hEdpxk
... or in your case you can use the following while loop:
while($record = mysql_fetch_array($myData)) {
echo "<tr>";
echo "<td>" . $record['id'] . "</td>";
echo "<td>" . urldecode($record['email']) . "</td>";
echo "<td>" . $record['score'] . "</td>";
echo "</tr>";
}

How can I echo out a variable from a script in database row

I have a div layer with a voting script, how can I print it out in a row echo?
SELECT `image`,`Name`,`item`, (`totalrate` / `nrrates`) AS `rank` FROM `rtgitems` WHERE item
REGEXP 'Total'
ORDER BY (`totalrate` / `nrrates`)
echo "<td align='center' width='200'>" . $row['Name'] . "</td>";
echo "<td align='center' width='200'>" . "<img src=\"{$row['image']}\">" . "</td>";
echo "<td align='center' width='200'>" . $row['rank'] . "</td>";
echo "<td align='center' width='200'>" . <div class="srtgs" id="$row['item']"></div> . "</td>";
The variable srtgs is called in the <script src="../ratingfiles/ratings.js" type="text/javascript"></script> in the head
What am I missing?
Your div needs to be echoed as a literal, just like the tds.
echo "<td align='center' width='200'><div class='srtgs' id=" . $row['item'] . "></div</td>";

connect mysql link to bootstrap button

I've made a button, here is the piece of code (bootstrap):
<span class="glyphicon glyphicon-download-alt"></span> Download
And this piece of mysql code, which contains a few links:
<?php
$con=mysqli_connect("localhost","admin","admin133","kernel");
if (mysqli_connect_errno())
{
echo "Error bij connecten: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM hack ORDER BY ID DESC ");
echo "<table border='0'>
<tr>
<th>Name</th>
<th>Status</th>
<th>Retepreter</th>
<th>Kwikie</th>
<th>Nevermind</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['kakatoeee'] . "</td>";
echo "<td>" . $row['kakatoe2'] . "</td>";
echo "<td>" . $row['kakatoe'] . "</td>";
echo "<td>" . $row['papaja'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
Now, my question is, how do I make it so that the links connect to the bootstrap buttons? (Sorry if I'm a bit unclear, I'm Dutch an it's pretty hard to type in English)
papaja, kakatoe etc. is my http!

fill textbox with mysql data

How do I fill an inputbox with mysql data. So that I can update the database?
I have this code that will show the table corresponding to the users request. But I don't know the syntax on how I can fill an inputbox with mysql data.
$result = mysql_query("SELECT * FROM t2 WHERE STAT='{$_POST["stat1"]}'");
echo "<table border='1'>
<tr>
<th>HospNum</th>
<th>RoomNum</th>
<th>LastName</th>
<th>FirstName</th>
<th>MidName</th>
<th>Address</th>
<th>TelNum</th>
<th>Status</th>
<th>Nurse</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['HOSPNUM'] . "</td>";
echo "<td>" . $row['ROOMNUM'] . "</td>";
echo "<td>" . $row['LASTNAME'] . "</td>";
echo "<td>" . $row['FIRSTNAME'] . "</td>";
echo "<td>" . $row['MIDNAME'] . "</td>";
echo "<td>" . $row['ADDRESS'] . "</td>";
echo "<td>" . $row['TELNUM'] . "</td>";
echo "<td>" . $row['STAT'] . "</td>";
echo "<td>" . $row['NURSE'] . "</td>";
echo "";
}
echo "";
And I want to display the corresponding records with this html form, by inputting a primary key. And clicking the search button, the record will appear on each box. Just like when you update mysql database through phpmyadmin. But this time using a custom html form.
<td width="168"><input name="hnum" type="text" id="hospnum"></td>
<td width="41"><font size="3">Room #</td>
<td width="3">:</td>
<td width="168"><input name="rnum" type="text" id="rnum"></td>
how can I do that?
<input name="hnum" type="text" id="hospnum" value="<?php echo $row['ROOMNUM']; ?>" />
In text field you have fill the value attribute with php fetched attribute value
echo "<input name='rnum' type='text' id='rnum' value =".$row['ROOMNUM'].">";