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.
Related
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>
I am trying to do a query and update that query on a same page by using form but the problem is I have to submit form twice to get it updated. This code is ported from my last mysql project. My last project was search then query then update. This one is query then update. I can't see why form doesn't get variable to it on first click. Still learning PDO. Please point me to a right direction. Thank you.
require_once ('control/control.php');
$db = db_connect ();
$stmt = $db->query("SELECT * FROM offsite_inventory WHERE category != '' ORDER BY FIELD(category,'Sparkling Wine','Rose Wine','Riesling Magnum 1.5L','Riesling Magnum 3L','Austrian Riesling','Austrian Gruner','Trocken','Kabinett','Spatlese','Auslese','Chardonnay USA','Chardonnay France','Chablis','White Wine 1','White Wine 2','Pinot Noir 2','Pinot Noir 1','Cabernet And Bordeau','Red Wine 1','Red Wine 2','Red Wine 3','Red Wine 4','Rhone Valley Red')");
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo "<tr><td width=\”50\">" . $row['code'] . "</td>
<td width=\"380\">" . $row['name'] . "</td>
<td width=\"50\" align=\"center\">" . $row['instock_resto'] . "</td>
<td width=\"50\" align=\"center\">" . $row['instock_home'] . "</td>
<td width=\"100\"><form style='display:inline!important; width:10px!important;' name='inventory' method='post' action='" . $PHP_SELF . "?id=" . $row['id'] . "&instock_home=" . $row['instock_home'] . "&name=" . $row['name'] . "'>
<table width='1' border='0' align='center' style='margin-right:auto; margin-left:auto;'>
<tr>
<td valign='middle'>
<label><input style='display:inline!important; width:25px!important;' type='number' name='instock_home'/></label></td>
<td>
<input style='display:inline!important; width:100px!important; padding:3px 0px;' type='submit' name='instock_home2' value='update stock' /></td></tr></table>
</form>";
echo "</td></tr>";
}
require_once ('control/control.php');
$conn = db_connect ();
$instock_home = $_POST['instock_home'];
$id = $_GET['id'];
$name = $_GET['name'];
$stmt2= $conn->prepare("UPDATE offsite_inventory SET instock_home = ? WHERE id = ?");
$stmt2->execute(array($instock_home, $id));
echo"</table>";
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!
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 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)