Why not close row? [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I output data from atabase in table.
In result table created with next code:
while($i=$res2->fetch_assoc()) {
$a++;
$t2.='
<tr>
<td>'.$a.'</td>
<td>'.date_format(new DateTime($i['date']),'d.m.Y').'</td>
';
if($valid!='id'){
$t2.='
<td>'.$partner.'</td>
';
}
$t2.='
<td>'.$http_referer.'</td>
</tr>';
}
$t1='
<table class="table table-hover table-bordered">
<thead>
<tr>
<th class="column_th_number">№</th>
<th>Date</th>
';
if($valid!='id'){
$t1.='
<th>Partner</th>
';
}
$t1.='
<th></th>
</tr>
<tr>
<td colspane="2">
</td>
</tr>
</thead>
<tbody>
';
$t3='
</tbody>
</table>
';
echo $t1.$t2.$t3;
but in the result I see that last row was not closed (see image):
Tell me please why last row was not closed?
And how can I make this right?

<td>'.date_format(new DateTime($i['date']),'d.m.Y').'</td>
if($valid!='id'){
replace with
<td>'.date_format(new DateTime($i['date']),'d.m.Y').'</td>'; <--- end the string here
if($valid!='id'){

you missed ';
<td>'.$a.'</td>
<td>'.date_format(new DateTime($i['date']),'d.m.Y').'</td>';
if($valid!='id'){

Thanks ALL.
Error was with colspan(value does not match the number of columns).
Thanks all for help

Related

Display selected values in mysqli columns [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
All i want to do is to output only Agric Department inside the Department columns. How do i go about this. Thanks in advance. This is my code.
<thead>
<tr>
<th>SL</th>
<th>Student Name</th>
<th>Department</th>
<th>Age</th>
<th>Photo</th>
</tr>
</thead>
<tbody>
<?php
$query=mysqli_query($db_con,'SELECT *
FROM `student_info`
ORDER BY `student_info`.`datetime` DESC;');
$i=1;
while ($result = mysqli_fetch_array($query)) { ?>
<tr>
<?php
echo '<td>'.$i.'</td>
<td>'.ucwords($result['name']).'</td>
<td>'.ucwords($result['department']).'</td>
<td>'.ucwords($result['age']).'</td>
<td><img class="rounded-circle avatar-xl" src="../../images/'.$result['photo'].'" ></td>';?>
</tr>
<?php $i++;} ?>
</tbody>
</table>
What am trying to achieve is to display only students in Agric Department
change your query from
SELECT * FROM `student_info` ORDER BY `student_info`.`datetime` DESC
to
SELECT * FROM `student_info` where department = 'Agric' ORDER BY `student_info`.`datetime` DESC

how to create a nested array and store it in database? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
i have a data like
<table>
<tr>
<th>title 1</th>
<td>para1</td>
</tr>
</table>
<table>
<tr>
<th>title 2</th>
<td>para1</td>
<td>para2</td>
<td>para3</td>
</tr>
</table>
<table>
<tr>
<th>title 3</th>
<td>para1</td>
<td>para2</td>
</tr>
</table>
now how can i take this data and make into an array..it will be really helpful if i can get a solution for this.
In my problem i have a table as shown above and want to store the data in a nested/ multidimensional array. All the solution above doesnot answer my question
thanks in advance
I think I know what you are looking for... It's actually pretty simple.
You want to iterate through the <table> tags first .. And subsequently iterate the children tr - tds.
I'd surround the tables with a surrounding div to make grabbing them much easier.
Then I'd use jQuery because the library makes it easy to choose children etc etc. Then for Storage into the database .. I'd "Json-ify" the array(s)
IE
$(document).ready(function() {
myHTML = $('#myDiv').html();
});
var tableNumber = $('#myDiv').children('table').length;
var items = [];
for (i = 0; i < tableNumber; i++) {
var title = $($("table tr th")[i]).html();
var paras = [];
$($("table tr")[i]).find('td').each(function() {
paras.push($(this).html());
});
items.push(title, paras);
}
var outPut = JSON.stringify(items);
$('#jsonOut').html(outPut);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="myDiv">
<table>
<tr>
<th>title 1</th>
<td>para 1-1</td>
</tr>
</table>
<table>
<tr>
<th>title 2</th>
<td>para 2-1</td>
<td>para 2-2</td>
<td>para 2-3</td>
</tr>
</table>
<table>
<tr>
<th>title 3</th>
<td>para 3-1</td>
<td>para 3-2</td>
</tr>
</table>
</div>
<br>
<pre>
<div id="jsonOut">
</div>
</pre>
You can also view the FIDDLE
Hope this helps.

display an Html table as nested array [duplicate]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
i have a data like
<table>
<tr>
<th>title 1</th>
<td>para1</td>
</tr>
</table>
<table>
<tr>
<th>title 2</th>
<td>para1</td>
<td>para2</td>
<td>para3</td>
</tr>
</table>
<table>
<tr>
<th>title 3</th>
<td>para1</td>
<td>para2</td>
</tr>
</table>
now how can i take this data and make into an array..it will be really helpful if i can get a solution for this.
In my problem i have a table as shown above and want to store the data in a nested/ multidimensional array. All the solution above doesnot answer my question
thanks in advance
I think I know what you are looking for... It's actually pretty simple.
You want to iterate through the <table> tags first .. And subsequently iterate the children tr - tds.
I'd surround the tables with a surrounding div to make grabbing them much easier.
Then I'd use jQuery because the library makes it easy to choose children etc etc. Then for Storage into the database .. I'd "Json-ify" the array(s)
IE
$(document).ready(function() {
myHTML = $('#myDiv').html();
});
var tableNumber = $('#myDiv').children('table').length;
var items = [];
for (i = 0; i < tableNumber; i++) {
var title = $($("table tr th")[i]).html();
var paras = [];
$($("table tr")[i]).find('td').each(function() {
paras.push($(this).html());
});
items.push(title, paras);
}
var outPut = JSON.stringify(items);
$('#jsonOut').html(outPut);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="myDiv">
<table>
<tr>
<th>title 1</th>
<td>para 1-1</td>
</tr>
</table>
<table>
<tr>
<th>title 2</th>
<td>para 2-1</td>
<td>para 2-2</td>
<td>para 2-3</td>
</tr>
</table>
<table>
<tr>
<th>title 3</th>
<td>para 3-1</td>
<td>para 3-2</td>
</tr>
</table>
</div>
<br>
<pre>
<div id="jsonOut">
</div>
</pre>
You can also view the FIDDLE
Hope this helps.

Display table in PHP if statement [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Can anyone help me how to display table inside PHP if statement.
Here's my code:
if( empty($errors))
{
ACTIVITIES \n
echo ' <table>
<thead>
<tr>
<th>Activity</th>
<th>Price</th>
<th>Quantity</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<tr>
<td>Chicken Feeding</td>
<td>$price_chicken</td>
<td>$num_chicken</td>
<td>$total_chicken</td>
</tr>
</tbody>
<tbody>
<tr>
<td>Fish Feeding</td>
<td>$price_fish</td>
<td>$num_fish</td>
<td>$total_fish</td>
</tr>
</tbody>
.................
</table> ';
}
try this
<?php if( empty($errors)): ?>
ACTIVITIES \n
<table>
<thead>
<tr>
<th>Activity</th>
<th>Price</th>
<th>Quantity</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<tr>
<td>Chicken Feeding</td>
<td><?=$price_chicken;?></td>
<td><?=$num_chicken;?></td>
<td><?=$total_chicken;?></td>
</tr>
</tbody>
<tbody>
<tr>
<td>Fish Feeding</td>
<td><?=$price_fish;?></td>
<td><?=$num_fish;?></td>
<td><?=$total_fish;?></td>
</tr>
</tbody>
.................
</table>
<?php endif; ?>
You have the table code wrapped in single quotes, but there are PHP variables inside. PHP will not translate those variables unless you wrap the table in double quotes.
If this doesn't help, give us an idea of what the output looks like.
Try using a 2-dimensional array and looping through it to create a proper HTML table. This way, there's no hard-coding, so you can make as many rows/columns as you want. Here's the code, just change the array:
<table>
<tbody>
<?php
$tableArray = [["Chicken Feeding", $price_chicken, $num_chicken],
["Fish Feeding", $price_fish, $num_fish]];
foreach ($tableArray as $tableRow) {
echo "<tr>";
foreach ($tableRow as $tableCell) {
echo "<td>$tableCell</td>";
}
echo "</tr>";
}
?>
</tbody>
</table>

Retrieving records from mysql [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Just looking for better solution.I'm retrieving all the records from mysql. Then I will send this data by email. Its working fine. Is there any better solution? thanks
$query = "SELECT * FROM order_details WHERE order_id = '".$data['order_id']."'";
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$message_admin .= "<table style='text-align:center;' border='1' cellspacing='0' cellpadding='7'>
<tr>
<td>Source</td>
<td>".$data['source']."</td>
</tr>
<tr>
<td>Email</td>
<td>".$data['email']."</td>
</tr>
<tr>
<td>Message</td>
<td>".$data['message']."</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>";
}
You would benefit from: http://us.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
Instead of the complicated string manipulation you are doing now.
You are setting $row, but using $data?
I would take a look at the following to improve your code.
mysql-real-escape-string
SELECT * vs SELECT column

Categories