I have a bootstrap table which has pairs of rows appear like the following:
There is a button generated at the end of the first row. Is there way to make it appear so its BETWEEN the two rows (i.e. sat on the line that is dividing the two rows) instead of it being in the first row only? I am using the Boostrap table class 'table' so the styling is automatically applied.
The table is generated via PHP script, here is the snippet:
$table = "<table class='table'>";
$table .= "<thead><tr><th>Departing Station</th><th>Depart Time</th><th>Destination</th><th>Arrival Time</th><th>Route</th></tr></thead>";
$table .= "<tbody>";
foreach ($printable_results as $result){
$journey1 = $result['journey1']['journey_id'];
$journey2 = $result['journey2']['journey_id'];
$table .= "<tr style='background-color:#F9F9F9;'>
<td>" . $result['journey1']['start_station'] . "</td>
<td>" . $result['journey1']['depart_time'] . "</td>
<td>" . $result['journey1']['end_station'] . "</td>
<td>" . $result['journey1']['arrive_time'] . "</td>
<td>
<a href='index.php?action=route_changeover&journey1_id=". $journey1 . "&journey2_id=". $journey2 . "'>
<input class='btn btn-success' type='submit' value='Full Route >'>
</a>
</td>
</tr>";
$table .= "<tr style='background-color:#F9F9F9;'>
<td>" . $result['journey2']['start_station'] . "</td>
<td>" . $result['journey2']['depart_time'] . "</td>
<td>" . $result['journey2']['end_station'] . "</td>
<td>" . $result['journey2']['arrive_time'] . "</td>
<td></td>
</tr>";
$table .= "<tr><td colspan='4'></td></tr>";
}
$table .= "</tbody></table>";
echo $table;
You can use row span to make it happen :)
.table>tbody>tr>td.route-wrap {
vertical-align: middle;
text-align: center;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<table class="table">
<thead>
<tr>
<th>Departing Station</th>
<th>Depart Time</th>
<th>Destination</th>
<th>Arrival Time</th>
<th>Route</th>
</tr>
</thead>
<tbody>
<tr>
<td>Text</td>
<td>Text</td>
<td>Text</td>
<td>Text</td>
<td class="route-wrap" rowspan="2">
<input class='btn btn-success' type='submit' value='Full Route >'>
</td>
</tr>
<tr>
<td>Text</td>
<td>Text</td>
<td>Text</td>
<td>Text</td>
</tr>
</tbody>
</table>
Related
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>
I am using the code below to gather and show the data stored in a database. Everything is workig fine but I am not able to show it with bootstrap css. If I copy an exemple of a table (code 2 below) in boostrap it does work (which means I did included all the files for bootstrap correctly).
Is there something i am missing? WHy the table I retrieve show up as a plain table and not with bootstrap css that looks nicer?
-------code 1------------
$query = "SELECT * FROM ...";
$result = mysql_query($query);
echo "<table>";
while($row = mysql_fetch_array($result)){
echo "<tr><td>" . $row['name'] . "</td>
<td>" . $row['...'] . "</td>
<td>" . $row['...'] . "</td>
<td>" . $row['...'] . "</td>
<td>" . $row['...'] . "</td>
<td>" . $row['...'] . "</td>
</tr>";
}echo "</table>";
mysql_close(); //Make sure to close out the database connection
?>
-----------code 2-----------
<div class="bs-example">
<table class="table">
<thead>
<tr>
<th>Row</th>
<th>Bill</th>
<th>Payment Date</th>
<th>Payment Status</th>
</tr>
</thead>
<tbody>
<tr class="active">
<td>1</td>
<td>Credit Card</td>
<td>04/07/2014</td>
<td>Call in to confirm</td>
</tr>
<tr class="danger">
<td>5</td>
<td>Telephone</td>
<td>06/07/2014</td>
<td>Due</td>
</tr>
</tbody>
</table>
-----------exemple solution updated--------
echo "<table class='table'>";
while($row = mysql_fetch_array($result)){
echo "<tr class='info'><td>" . $row['...'] . "</td>
<td>" . $row['...'] . "</td>
<td>" . $row['...'] . "</td>
<td>" . $row['...'] . "</td>
<td>" . $row['...'] . "</td>
<td>" . $row['...'] . "</td>
</tr>";
}
echo "</table>";
mysql_close();
?>
You need to add the table class:
echo "<table class='table'>";
The magic of bootstrap is in its class attributes. You need to add the specific bootstrap class attributes that you want to help structure your table. Like table, active and danger. As you can see quite clearly the difference in code 1 and code 2 are the class attributes. Give this blog post a read to get more info on what each attribute does for you.
I have created a php file called search.php. I want to show the result on a table
I want a table structure like this.
__________________________
| |________________|
| |________________|
| |________________|
|________|________________|
|________________|
|________________|
On the left side I want to place a picture which will be obtained from database and to the right I will place information about the student photo.
Could you write a code. Can we separate photo and the information column by a vertical line only.(if yes,HOW ?? )
<table>
<tr>
<td rowspan="4" style="border-right: 1px solid black">
<img src"whatever.png" alt="" />img
</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
</tr>
<tr>
<td>3</td>
</tr>
<tr>
<td>4</td>
</tr>
<tr>
<td rowspan="2">
</td>
<td>5</td>
</tr>
<tr>
<td>6</td>
</tr>
</table>
but really: learn html an get used to the boxed model, that is: use divs
<?php
$sql = "Select FROM * `yourtablename` where `id` = 'theidofthestudent'";
if(!mysql_query($sql)){
die(mysql_error());
} else {
echo "<table border="1px" style="text-align:center;" align="justify">";
echo "<th>Photo of student</th>";
echo "<th>Name of the student</th>";
echo "<th>Student Detials</th>";
while($row = mysql_fetch_array($sql)){
echo "<tr>";
echo "<td style="float:left;">' . $row['student_pic'] . "</td>";
echo '<td style="float:right;">' . $row['student_name'] . "</td>";
echo '<td style="float:right;">' . $row['student_details'] . "</td>";
echo "</tr>"
} echo "</table>";
}
?>
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;
I have a very basic and simple script that should display records from my database. The problem: it doesn't show all the records. I've tried it even with the most simple mysql
($sql="SELECT * FROM $tbl_name";) but still some records are missing (mostly the first of the list that isn't shown).
So here is my code (it's all on 1 page):
<?php
$host="localhost";
$username="***";
$password="***";
$db_name="***";
$tbl_name="***";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name WHERE rowNameOne >= 0.01 AND rowNameTwo='2013'";
if ($_GET['sort'] == 'one')
{
$sql .= " ORDER BY one ASC";
}
elseif ($_GET['sort'] == 'two')
{
$sql .= " ORDER BY two ASC";
}
elseif ($_GET['sort'] == 'three')
{
$sql .= " ORDER BY three ASC";
}
elseif($_GET['sort'] == 'four')
{
$sql .= " ORDER BY four ASC";
}
elseif($_GET['sort'] == 'five')
{
$sql .= " ORDER BY five ASC";
}
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
<body onload="parent.alertsize(document.body.scrollHeight);">
<br />
<table cellspacing="0" cellpadding="0" align="center">
<tr>
<td valign="top" colspan="5">
<font>Titel</font>
</td>
<tr>
<td>Titel one</td>
<td>Titel two</td>
<td>Titel three</td>
<td>Titel four</td>
<td>Titel five</td>
</tr>
<tr>
<td colspan="5" class="noBorder">
<?php
while($rows=mysql_fetch_array($result)){
?>
<a href="pageName.php?id=<? echo $rows['id']; ?>" >
<table width="100%">
<tr>
<td><? echo $rows['rowNameOne']; ?></td>
<td><? echo $rows['rowNameTwo']; ?></td>
<td><? echo $rows['rowNameThree']; ?></td>
<td><? echo $rows['rowNameFour']; ?></td>
<td><? echo $rows['rowNameFive']; ?></td>
</tr>
</table>
<input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>">
<?php
}
?>
</a>
</td>
</tr>
</table>
It's a very basic code, easy as can be I would say, but still it's missing records, not displaying everything that's in the database. What am I doing wrong?
Thanks for the help!
Before you start the loop, you do this:
$rows=mysql_fetch_array($result);
Then the loop condition is:
while($rows=mysql_fetch_array($result)){
So the first result is never shown. I would advice to remove the first statement, since you're not using its results between that statement and the loop.
On a related note, please consider moving to PDO or mysqli.