Display specific number of rows inside an HTML table - html

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>

Related

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>";
}

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!

how to have a vertical header and textarea

i have a code...server side and cant seem to make it load wherein HEADER would be vertical, i have tried the code below,
<?php
require 'include/DB_Open.php';
$ea_name = $_POST['ea_name'];
$sql="SELECT * FROM ea_error WHERE ea_name = '" . $ea_name . "'";
$myData = mysql_query($sql) or die(mysql_error());
//to count if there are any results
$numrow = mysql_num_rows($myData) ;
if($numrow == 0)
{
echo "No results found.";
}
else
{
echo '<fieldset><legend><strong>Information</strong></legend>
<table width="auto" border="0" align="center">
<tr><th scope="row">Error</th></tr>
<tr><th scope="row">Resolution</th></tr>
<tr><th scope="row">Contact/s</th></tr>';
while($info = mysql_fetch_array($myData))
{
echo "<form action='retrieve.php' method='post'>";
echo "<td align='center'>" . "<textarea readonly=readonly name=error cols=75 rows=8> " . $info['error'] . "</textarea></td>";
echo "<td align='center'>" . "<textarea readonly=readonly name=resolution cols=75 rows=8> " . $info['resolution'] . "</textarea></td>";
echo "<td align='center'>" . "<textarea readonly=readonly name=contacts cols=75 rows=8> " . $info['contacts'] . "</textarea></td>";
echo "</form>";
echo "</table>";
}
}
echo "</fieldset>";
include 'include/DB_Close.php';
?>
whats showing with this code is like below
Error
Resolution
Contact/s
then i would have the three text areas here on a single row
what i want to happen is
Error - TEXTAREA
Resolution - TEXTAREA
Contact/s - TEXTAREA
pls help...i also tried using a css style to no avail
table, td, th {
border: 1px solid red;
}
thead {
float: left;
}
ive also tried to use the code below,
echo "<form action='retrieve.php' method='post'>";
echo "<tr>";
echo "<td align='center'>" . "<textarea readonly=readonly name=error cols=75 rows=8> " . $info['error'] . "</textarea></td>";
echo "</tr>";
echo "<tr>";
echo "<td align='center'>" . "<textarea readonly=readonly name=resolution cols=75 rows=8> " . $info['resolution'] . "</textarea></td>";
echo "</tr>";
echo "<tr>";
echo "<td align='center'>" . "<textarea readonly=readonly name=contacts cols=75 rows=8> " . $info['contacts'] . "</textarea></td>";
echo "</tr>";
but what i am getting is
Error
Resolution
Contact/s
TEXTAREA
TEXTAREA
TEXTAREA
If I understood the question correctly, this could be an answer (although I would TOTALLY avoid using tables for layout design and not just tabular data):
$myRes = "<form action='retrieve.php' method='post'>
<fieldset>
<legend><strong>Information</strong></legend>
<table width='auto' border='0' align='center'>
<tr>
<th scope='row'>Error</th>
<td align='center'><textarea readonly=readonly name=error cols=75 rows=8>" . $info['error'] . "</textarea></td>
</tr>
<tr>
<th scope='row'>Resolution</th>
<td align='center'><textarea readonly=readonly name=resolution cols=75 rows=8>" . $info['resolution'] . "</textarea></td>
</tr>
<tr>
<th scope='row'>Contact/s</th>
<td align='center'><textarea readonly=readonly name=contacts cols=75 rows=8>" . $info['contacts'] . "</textarea></td>
</tr>
</table>
</fieldset>
</form>";
echo $myRes;

delete mysql_array_fetch

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)

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'].">";