I am new to MYSQL and i am trying to export my database to html, and put the data into specific html tables. I have looked around the site, but i cant get my code to work, can someone help me, and tell me if this code looks right ?
<?php
$con=mysqli_connect("xxx","xxx","xxx","xxx","xxx");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM xxx");
while($row = mysqli_fetch_array($result))
{
<tr>
<th bgcolor="#3281c6">" . $row["PO_nummer"]. "</th>
<th bgcolor="#3281c6">" . $row["Varenummer"]. "</th>
<th bgcolor="#3281c6">" . $row["Produkt_beskrivelse_"]. "</th>
<th bgcolor="#3281c6">" . $row["Antal"]. "</th>
}
mysqli_close($con);
?>
You seem to be expecting an associative array and not a regular (numbered) array, in this case try:
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC))
{
// code
}
Try and echo or print the html
echo "
<th bgcolor="#3281c6">" . $row["PO_nummer"]. " </th>
<th bgcolor="#3281c6">" . $row["Varenummer"]. "</th>
<th bgcolor="#3281c6">" . $row["Produkt_beskrivelse_"]. "</th>
<th bgcolor="#3281c6">" . $row["Antal"]. "</th>";
And use single quotes here bgcolor='#3281c6'
Related
First of all. I apologize for the poor English. I'm also sorry for the novice level of this question.
I would like to put my SQL results in a table, and add a new row for every result.
if(mysql_num_rows($raw_results) > 0){
while($results = mysql_fetch_array($raw_results)){
echo "<p><b>".$results['FNAME']."</b> " .$results['LNAME']." ".$results['AGE']."</p>";
}
}
So I would like [FNAME] in a own TD, [LNAME] in it's on TD and the same with [AGE].
Thank you in advance!
Just put <tr> around each row of data, <td> around each column, and put everything inside <table>.
if (mysql_num_rows($raw_results) > 0) {
echo "<table><tr><th>First Name</th><th>LAst Name</th><th>Age</th></tr>";
while ($results = mysql_fetch_assoc($raw_results) {
echo "<tr><td>{$results['FNAME']}</td><td>{$results['LNAME']}</td><td>{$results['AGE']}</td></tr>";
}
echo "</table>";
}
use this code :
<table>
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<?php
if(mysql_num_rows($raw_results) > 0){
while($results = mysql_fetch_array($raw_results)){
echo "<tr><td>" . $results['FNAME'] . "</td><td>" . $results['LNAME'] . "</td><td>" .$results['AGE']."</td></tr>";
}
}
?>
</tbody>
</table>
How can I use Distinct with join in CodeIgniter, I'm trying to fetch customer's name and registered category, but my problem is whiles fetching the data I'm getting data in repetation because of sub-category, I've used distinct but then I'm getting Ambiguous field error, how can I solve this problem.
My View
<table class="table table-hover example1">
<thead>
<tr>
<th>SNo.</th>
<th>Business Name</th>
<th>Category Name</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<?php $i=0;
foreach($value as $row){ ?>
<tr>
<td><?php echo ++$i;?></td>
<td><?php echo $row->Bussiness_Name;?></td>
<td><?php echo $row->Category_Name;?></td>
<td onClick="RestoreVendor(<?php echo $row->Business_Id; ?>,<?php echo $row->Trash;?>,'<?php echo $row->Bussiness_Name;?>')" class="btn btn-primary">Remove</td>
</tr>
<?php }?>
</tbody>
</table>
My Controller:
public function removecategory()
{
$this->load->model('VendorModel');
$data = $this->VendorModel->remove_category();
$this->load->view('admin/remove_cat', array('value'=>$data));
}
My Model
public function remove_category()
{
$this->db->select('*');
$this->db->distinct('Category_Id');
$this->db->from('business_mapping');
$this->db->join('business_profile_details', 'business_profile_details.Business_Id = business_mapping.Business_Id');
$this->db->join('category_master', 'category_master.Category_Id = business_mapping.Category_Id');
$query = $this->db->get();
return $query->result();
}
result image
You can use below mentioned query.
$query = $this->db->group_by('category_master.Category_Id,business_profile_details.Business_Id');
Please try above, It will help you.
you can use
$this->db->distinct();
Some times distinct not works then you can use
$this->db->group_by('business_mapping.unique_coloumn_Name');
actually i created a form and the inputs have been stored into the database succesfully.. then i retreived those inputs in the browser in table format ..now i added another column(delete) in browser table where i have data in that column is delete link which moves to delete.php page...now wat i need to code in display.php page to delete the specified row ?? i tried but i am not sure about that how to make that specific row .
this is my browser display.php page
?>
<table border="2">
<th>
<tr>
<th>SNO</th>
<th>First Name</th>
<th>Last Name</th>
<th>email</th>
<th>gender</th>
<th>language</th>
<th>country</th>
<th>interest</th>
<th>edit</th>
<th>delete</th>
</tr>
</th>
<tbody>
<?php
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_assoc($result))
{
echo '<tr>';
echo '<td>' .$row['SNO'] .'</td>';
echo '<td>' . $row['firstname'] . '</td>';
echo '<td>' . $row['lastname'] . '</td>';
echo '<td>' . $row['email'] . '</td>';
echo '<td>' . $row['gender'] . '</td>';
echo '<td>' . $row['language'] .'</td>';
echo '<td>' . $row['country'] . '</td>';
echo '<td>' . $row['interest'] .'</td>';
echo '<td>' .'edit' .'</td>';
echo '<td>' .'delete'.'</td>';
echo '</tr>';
}
}
?>
</tbody>
</table>
</body>
</html>
This is my code were is show the table . i made the links to move to edit.php and delete.php page respectively...so wat i need to do as acode in that respective pages
You could add POST variables in the delete.php URL so:
echo '<td>' .'delete'.'</td>';
Then on the delete.php page you can retrieve it with:
$_POST["idX"];
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 reservation and postflight table. I have to do a query in the reservation table and look for the data in the postflight table.
$query="select * from reservation where date(fdate) between '$datefrom' and '$dateto' and status in ('Flown') $aircraft order by $sort";
$result=mysql_query($query) or die(mysql_error());
echo "<div class='box'><table class='hovertable'>
<th>Flight Date</th>
<th>Client Name</th>
<th>Group Code</th>
<th>Aircraft</th>
<th>Block Time</th>
<th>Waiting Time</th>
<th>Charter Fee</th>
<th>Take-off and Landing Fee</th>
<th>Waiting Time Fee</th>
<th>Other Charges</th>
<th>Sub-Total</th>
<th>Value-added Tax</th>
<th>Total Service Invoice Amount</th>
<th>Reservation No.</th>
</tr>";
while($row=mysql_fetch_array($result))
{
$rvno=$row['reservno'];
$yr=(string) date("Y");
$rn=$yr."-".$rvno;
$a=mysql_query("select *, (fdf + fce + aef + hf + sfp) as 'tcharge' from postflight where reservno='$rvno'") or die(mysql_error());
//$e=mysql_fetch_array($a);
while($b=mysql_fetch_array($a))
{
echo"<tr><td>".$row['fdate']."</td><td>".$b['cliename']."</td><td>".$row['grpcode']."</td><td>".$row['acode']."</td><td>".$row['btime']."</td><td>".$b['wtime']."</td><td>".$b['total_cfee']."</td><td>".$b['total_tol']."</td><td>".$b['total_wtfee']."</td><td>".$b['tcharge']."</td><td>".$b['sub_total']."</td><td>".$b['vat']."</td><td>".$b['total_service_invoice_amt']."</td><td>".$rn."</td></tr>";
}
}
Before I close the </table>, I would like to add another row where it sums up all the required fields to be summed up based on the outputted data of the query above. Something like,
echo "<tr><td colspan='6'></td><td><b>sum</b></td><td><b>sum</b></td><td><b>sum</b></td><td><b>sum</b></td><td><b>sum</b></td><td><b>sum/b></td><td><b>sum</b></td><td></td></tr>";
But I'm not sure how to do it. Please help. Thanks.
you could do something like this:
$sum = 0;
while($b=mysql_fetch_array($a))
{
//your codes
$sum += $fields //fields you want to sum up
echo "<tr><td> 'Sum:'. $sum ... </td></tr>";
}
echo "</table>";