I been trying to figure out if I can add a for loop in this situation:
$g = '<td id="'.$this->currentDate.'" class=" td-top-text '.($cellNumber%7==1?' start ':($cellNumber%7==0?' end ':' ')).
($cellContent==null?'mask':'').'">'
//if statement
.($this->currentDate === $tutor_date ?
'<div class="inside">'//open inside
.'<div class="inside-content">' //open inside-content
. '<div class="inside-date">'.$cellContent.'</div>'//open and close inside-date
for($i =0; $i < count($appt_date['date']); $i++) {
'<div class="inside-event '.$bkg_color.' ck-button btn-xs" title="Group Session">'//open inside-event
. '<label class="label-for-text">'//open label
. '<input type="radio" data-toggle="modal" data-target="#myModal" name="appt_selected" value="'.$tutor_shedule_id.'" >'//open input
. '<span>'.$tutor_info.'</span>' //open and close span
.'</input>'// close input
. '</label>'// close label
. '</div>';//close inside-event
}
'</div>'//close inside-content
. '</div>'//close inside
. '</td>' //close td
//else
: '<div class="inside">'.$cellContent.'</div>'
. '</td>' );
return $g;
I tried so many things such as added a ; at the end of </div> and before the for loop, I also added a . before the for loop and after.
EDIT:
Instead of down-vote this question, please provide some feedback and let me know what is wrong. For me this code is "fine" until you tell me a better way to do it. So, please I really appreciated your feedback.
Thanks.
I recommend you to do the if-else statement rather than this approach as this process is very difficult to debug. So, go with the following code:
$g = '<td id="'.$this->currentDate.'" class=" td-top-text '.($cellNumber%7==1?' start ':($cellNumber%7==0?' end ':' ')).
($cellContent==null?'mask':'').'">';
if ($this->currentDate === $tutor_date){
$g.='<div class="inside">'//open inside
.'<div class="inside-content">' //open inside-content
. '<div class="inside-date">'.$cellContent.'</div>';//open and close inside-date
for($i =0; $i < count($appt_date['date']); $i++) {
$g.='<div class="inside-event '.$bkg_color.' ck-button btn-xs" title="Group Session">'//open inside-event
. '<label class="label-for-text">'//open label
. '<input type="radio" data-toggle="modal" data-target="#myModal" name="appt_selected" value="'.$tutor_shedule_id.'" >'//open input
. '<span>'.$tutor_info.'</span>' //open and close span
.'</input>'// close input
. '</label>'// close label
. '</div>';//close inside-event
}
$g.= '</div>'//close inside-content
. '</div>'//close inside
. '</td>' ;//close td
}else{
$g.='<div class="inside">'.$cellContent.'</div>'
. '</td>'; }
return $g;
Well that was painful, I've tried to fix it up a little and at least make it more readable. Have a try of this... also I should point out I'm pretty sure this code is vulnerable to XSS attacks.
// Work out the Class names.
$classNameOne = ($cellNumber % 7) == 1 ? ' start '
: ($cellNumber % 7) == 0 ? ' end'
: ' ';
$classNameTwo = ($cellContent == null) ? 'mask'
: '';
// Build up the html.
$html = '<td id="' . $this->currentDate . '" class="td-top-text ' . $classNameOne . $classNameTwo . '">';
if ($this->currentDate === $tutor_date) {
$html .= '<div class="inside">';
$html .= '<div class="inside-content">';
$html .= '<div class="inside-date">' . $cellContent . '</div>';
$dateInstances = count($appt_date['date']);
for ($i = 0; $i < $dateInstances; $i++) {
$html .= '<div class="inside-event ' . $bkg_color . ' ck-button btn-xs" title="Group Session">';
$html .= '<label class="label-for-text">';
$html .= '<input type="radio" data-toggle="modal" data-target="#myModal~ name="appt_selected" value="'. $tutor_shedule_id .'">';
$html .= '<span>' . $tutor_info . '</span>';
$html .= '</input>';
$html .= '</label>';
$html .= '</div>';
}
$html .= '</div>';
$html .= '</div>';
$html .= '</td>';
} else {
$html .= '<div class="inside">' . $cellContent . '</div>';
$html .= '</td>';
}
return $html;
Related
Hello i have a table when i want to display some td value = 0 if the status of the task has the id=52!
Down i will put a picture of the table!
I tried to use this code for that:
if ($status['id']) { $calC = $calCminusrealcost = $realCost =0; }
Here $calC, $calCminusrealcost and $realCost are the values i want to become 0!
Here is the pucture of the table: [!https://i.stack.imgur.com/YWOwb.png][1]][1]
So after i use this code it works but in general for all tasks, not just for those which have the id = 52, and if i try to replace id with 52 in the function it doesn't work!
Does someone know what can I do?
this is the full code i have about status:
$outputStatus = '';
$outputStatus .= '<span class="inline-block label" style="color:' . $status['color'] . ';border:1px solid ' . $status['color'] . '" task-status-table="' . $aRow['status'] . '">';
$outputStatus .= $status['name'];
if ($canChangeStatus) {
$outputStatus .= '<div class="dropdown inline-block mleft5 table-export-exclude">';
$outputStatus .= '<a href="#" style="font-size:14px;vertical-align:middle;" class="dropdown-toggle text-dark" id="tableTaskStatus-' . $aRow['id'] . '" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">';
$outputStatus .= '<span data-toggle="tooltip" title="' . _l('ticket_single_change_status') . '"><i class="fa fa-caret-down" aria-hidden="true"></i></span>';
$outputStatus .= '</a>';
$outputStatus .= '<ul class="dropdown-menu dropdown-menu-right" aria-labelledby="tableTaskStatus-' . $aRow['id'] . '">';
foreach ($task_statuses as $taskChangeStatus) {
if ($aRow['status'] != $taskChangeStatus['id']) {
$outputStatus .= '<li>
<a href="#" onclick="task_mark_as(' . $taskChangeStatus['id'] . ',' . $aRow['id'] . '); return false;">
' . _l('task_mark_as', $taskChangeStatus['name']) . '
</a>
</li>';
}
}
if ($status['id']) {
$calC = $calCminusrealcost = $realCost =0;
}
$outputStatus .= '</ul>';
$outputStatus .= '</div>';
}
$outputStatus .= '</span>';
$row[] = $outputStatus;
[1]: https://i.stack.imgur.com/YWOwb.png
I am trying to make a dropdown menu from which you can sort a page "price high-low" or "price low-high".
This is the HTML with an id="show_product"
<div class="row" id ="notification-bar"></div>
<div class="row" id="show_product">Here comes the table with products</div>
This is the HTML for the dropdown menu:
<select name="sort" id="sort">
<option value="asc">Price low - high</option>
<option value="desc">Price high - low</option>
</select>
The Jquery for this is:
$(document).ready(function(){
$('#sort').change(function() {
var sort = $(this).val();
$.ajax({
url:"load_products.php",
method:"POST",
data: {sort:sort},
succes:function(data){
$('#notification-bar').text('The page has been successfully loaded');
$('#show_product').html(data);
},
error: function() {
$('#notification-bar').text('An error occurred');
}
});
});
});
And finaly the load_products.php is:
<?php
include("inc/connect.php");
$output = '';
if($_POST["sort"] != '') {
$query = "SELECT * FROM shop ORDER BY price " . $_POST["sort"];
$result = mysqli_query($con, $query);
while($row = mysqli_fetch_array($result)) {
$output .= '<div class="col-lg-4 col-md-6">';
$output .= '<div class="single-product">';
$output .= '<img class="img-fluid" src="' . $row["imageURL"] . '">';
$output .= '<div class="product-details">';
$output .= '<h6 class="text-center">' . $row["title"] . '</h6>';
$output .= '<div class="price text-center">';
$output .= '<h6>€ ' . $row["price"] . '</h6>';
$output .= '</div>';
$output .= '</div>';
$output .= '</div>';
$output .= '</div>';
}
return $output;
} else {
$query = "SELECT * FROM shop ORDER BY price ASC";
$result = mysqli_query($con, $query);
while($row = mysqli_fetch_array($result)) {
$output .= '<div class="col-lg-4 col-md-6">';
$output .= '<div class="single-product">';
$output .= '<img class="img-fluid" src="' . $row["imageURL"] . '">';
$output .= '<div class="product-details">';
$output .= '<h6 class="text-center">' . $row["title"] . '</h6>';
$output .= '<div class="price text-center">';
$output .= '<h6>€ ' . $row["price"] . '</h6>';
$output .= '</div>';
$output .= '</div>';
$output .= '</div>';
$output .= '</div>';
}
return $output;
}
?>
The problem is that when I change the option from the dropdown, the ID "show_product" isn't filled with the data from load_products.php.
Any idea what's going wrong?
Kind regards,
Arie
Well I could not see your form method but I hope u check for little things like is set to POST. Also yes if you not using OOP way try to sanitized inputs.
Enable show errors in PHP.ini as this helps us too if you showed us exact display of effect when code runs.
I have a table like so
echo '<table>';
echo '<tr>';
echo '<td>' . $value['title'] . '</td>';
echo '<td>' . $value['date'] . '</td>';
echo '<td>' . $value['preview'] . '</td>';
echo '<td>' . substr($value['description'], 0, 10) . '</td>';
echo '<td><img src="../images/articles/' . $value['image'] . '"></td>';
echo '<td><img src="../images/articles/' . $value['detailImage'] . '"></td>';
if($value['showDetailImage'] == 1){
$showDetailImage = 'Yes';
}else{
$showDetailImage = 'No';
}
echo '<td>' . $showDetailImage . '</td>';
echo '<td><a class="btn btn-default" href="Press.php?action=edit&id=' . $value['id'] . '">Edit</a></td>';
echo '<td><a onclick="if(!confirm(\'Are you sure you want to delete this item?\')) return false;" class="btn btn-default" href="Press.php?action=delete&id=' . $value['id'] . '">Delete</a></td>';
echo '</tr>';
echo '</table>';
notice I have substr and when I have that in there, it does not display the description and breaks the rest of my table, if I remove the substr the table is fine and everything is displayed. Why is substr breaking my table.
It's probably the contents of description that contains HTML markup that's breaking the table, use htmlspecialchars...
echo '<td>' . htmlspecialchars(substr($value['description'], 0, 10)) . '</td>';
Is that because your substr concatenates half way through some HTML element?
For example, you should use:
echo htmlentities(substr($value['description'], 0, 10));
Or if you want to strip the HTML tags:
echo strip_tags(substr($value['description'], 0, 10));
I want to implement this <img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" /> into the following function.
function list_my_categories($exclude = '') {
if (!empty($exclude)) {
$exclude = 'exclude=' . $exclude;
}
$categories = get_categories($exclude);
$html = '';
foreach ($categories as $cat) {
if($cat->category_parent == 0) {
<img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" />
$html .= '<p>' . $cat->cat_name . '</p>';
$html .= '<p>' . $cat->category_description . '</p>';
$childcategories = get_categories('child_of='.$cat->cat_ID.'');
if(!empty($childcategories)){
foreach ($childcategories as $ccat) {
$html .= '<p>' . $ccat->cat_name . '</p>';
$html .= '<p>' . $ccat->category_description . '</p>';
}
}
}
}
return $html;
}
add_shortcode('show-cats', 'list_my_categories');
The function shows a list of categories in WordPress, and I have another plugin which allows you to set an image for each category, so i am trying to show it...
if($cat->category_parent == 0)
{
$html .= '<img src="' . z_taxonomy_image_url($cat->term_id) . '" />';
$html .= '<p>' . $cat->cat_name . '</p>';
$html .= '<p>' . $cat->category_description . '</p>';
$childcategories = get_categories('child_of='.$cat->cat_ID.'');
if(!empty($childcategories))
{
foreach ($childcategories as $ccat)
{
/*$html .= '<img src="' . z_taxonomy_image_url($ccat->term_id) . '" />';*/
$html .= '<p>' . $ccat->cat_name . '</p>';
$html .= '<p>' . $ccat->category_description . '</p>';
}
}
}
Simple question I believe for anyone with minimal php skills (which I don't have sufficient amounts of haha)
$numrows = $retour['nb'] / 4;
echo $numrows;
echo "<table><tr>";
while ($callback = mysql_fetch_assoc($queryLocations2))
{
echo utf8_encode('<td><img src="/flags/' . strtolower($callback['loc_code']) . '.png" id="' . $callback['loc_id'] . '"><input type="checkbox" value="' . $callback['loc_url'] . '" />' . $callback['loc_city'] . ', ' . utf8_encode($callback['loc_state']) . '</td>');
}
echo "</tr></table>";
}
How would I go about presenting a table that will hold 4 results(4 columns) per row, based on the value of $numrows?
Thank you!
Output tr tags inside while loop:
$count = 0;
echo "<table>";
while ($callback = mysql_fetch_assoc($queryLocations2))
{
if ($count % 4 == 0)
echo '<tr>';
$count++;
echo utf8_encode('<td><img src="/flags/' . strtolower($callback['loc_code']) . '.png" id="' . $callback['loc_id'] . '"><input type="checkbox" value="' . $callback['loc_url'] . '" />' . $callback['loc_city'] . ', ' . utf8_encode($callback['loc_state']) . '</td>');
if ($count % 4 == 0)
echo '</tr>';
}
if ($count % 4 != 0)
{
// need to add missing td-s here
echo '</tr>';
}
echo "</table>";
$numrows = floor($retour['nb'] / 4);
echo $numrows;
$i=0;
echo "<table>";
while ($callback = mysql_fetch_assoc($queryLocations2))
{
if($i==4)
{
echo "<tr>";
echo utf8_encode('<td><img src="/flags/' . strtolower($callback['loc_code']) . '.png" id="' . $callback['loc_id'] . '"><input type="checkbox" value="' . $callback['loc_url'] . '" />' . $callback['loc_city'] . ', ' . utf8_encode($callback['loc_state']) . '</td>');
echo "</tr>";
$i=0;
}
$i++;
}
while ($i<4)
{
echo '<td></td>';
$i++;
}
echo "</table>";
}
//if numrows used for # of rows then use following
$count=0;
while ($callback = mysql_fetch_assoc($queryLocations2) && $count<=$numrows)
{
if($i==4)
echo "<tr>";
echo utf8_encode('<td><img src="/flags/' . strtolower($callback['loc_code']) . '.png" id="' . $callback['loc_id'] . '"><input type="checkbox" value="' . $callback['loc_url'] . '" />' . $callback['loc_city'] . ', ' . utf8_encode($callback['loc_state']) . '</td>');
if($i==4)
{
echo "</tr>";
$i=0;
$count++;
}
$i++;
}
while ($i<4)
{
echo '<td></td>';
$i++;
}
echo "</table>";
}