Bootstrap model shows same content, when fetching data using jplist with php, sql.
Example Link
Source Files
Link tried
private function getHTML($item){
$html = "";
$html .= "<div class='list-item box'>";
$html .= " <div class='img left'>";
$html .= " <img src='" . $item['image'] . "' alt='' title=''/>";
$html .= " </div>";
$html .= "<div class='dropdown'>";
$html .= "<button class='btn btn-primary btn-xs dropdown-toggle' type='button' id='dropdownMenu1' data-toggle='dropdown' aria-haspopup='true' aria-expanded='false'>Details</button>";
$html .= "<ul class='dropdown-menu' aria-labelledby='dropdownMenu1'>";
$html .= "<p class='title'>" . $item['title'] . "</p>";
$html .= "<p class='likes'>" . $item['likes'] . "</p>";
$html .= "</ul>";
$html .= "</div>";
$html .= "<button type='button' class='btn btn-primary btn-lg' data-toggle='modal' data-target='#myModal'>Launch demo modal</button>";
$html .= "<div class='modal fade' id='myModal' tabindex='-1' role='dialog' aria-labelledby='myModalLabel'>";
$html .= "<div class='modal-dialog' role='document'>";
$html .= "<div class='modal-content'>";
$html .= "<div class='modal-header'>";
$html .= "<h4 class='modal-title' id='myModalLabel'>Modal title</h4>";
$html .= "<p class='title'>" . $item['title'] . "</p>";
$html .= "<p class='likes'>" . $item['likes'] . "</p>";
$html .= "</div>";
$html .= "</div>";
$html .= "</div>";
$html .= "</div>";
$html .= " <div class='block right'>";
$html .= " <p class='title'>" . $item['title'] . "</p>";
$html .= " <p class='desc'>" . $item['description'] . "</p>";
$html .= " <p class='like'>" . $item['likes'] . " Likes</p>";
$html .= " <p class='theme'>" . $item['keyword1'] . ", " . $item['keyword2'] . "</p>";
$html .= " </div>";
$html .= "</div>";
return $html;
}
It stores the clicked link in the modal's data, i dont't know how to get new data or remove the old one before fetching.
Related
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'm trying to do a condition within an if statement.
I have a current if statement which determines odd and even for css styling.
Within this I want to add another if statement for the reference number. (outlined as Ref in the code).
I'm not sure how to go about this but I want to add something along the lines of
if ref == 1 then echo ref, I've tried putting an if within an if and I just keep getting syntax errors. Can someone point me in the right direction please?
include "db_connect.php";
$result1 = mysql_query("SELECT * FROM updates ORDER BY id DESC limit 5");
$result2 = mysql_num_rows($result1);
$x = $result2;
while ($row1 = mysql_fetch_array($result1)) {
if (++$x % 2) {
echo "<blockquote class='example-right'>" . $row1['update'] .
"<div class='ref'>Ref: " . $row1['ref'] .
"</div><div class='date-right'> from " . $row1['date'] .
" to " . $row1['todate'] .
"</div> </blockquote> <p>" . $row1['username'] .
"</p> </td>";
echo "</p>";
} else {
echo "<blockquote class='example-obtuse'>" . $row1['update'] .
"<div class='ref'>Ref: " . $row1['ref'] .
"</div><div class='date-right'> from " . $row1['date'] .
" to " . $row1['todate'] .
"</div> </blockquote> <p>" . $row1['username'] .
"</p> </td>";
}
}
the bit I tried to do with 2nd if statement:
include "db_connect.php";
$result1 = mysql_query("SELECT * FROM updates1 ORDER BY id DESC limit 5");
$result2 = mysql_num_rows($result1);
$x = $result2;
while ($row1 = mysql_fetch_array($result1)) {
if (++$x % 2) {
$sch = $row1['schuedled'];
else if ($sch == '1') {
echo "<blockquote class='example-right'>" . $row1['update'] .
"<div class='ref'>Ref: " .$row1['ref'] .
"</div><div class='date-right'> from " . $row1['date'] .
" to " . $row1['todate'] .
"</div> </blockquote> <p>" . $row1['username'] .
"</p> </td>";
else {
echo "<blockquote class='example-right'>" . $row1['update'] .
"</div><div class='date-right'> from " . $row1['date'] .
" to " . $row1['todate'] .
"</div> </blockquote> <p>" . $row1['username'] .
"</p> </td>";
}
}
echo "</p>";
} else {
echo "<blockquote class='example-obtuse'>" . $row1['update'] .
"<div class='assyst-ref'>Ref: " . $row1['ref'] .
"</div><div class='date-right'> from " . $row1['date'] .
" to " . $row1['todate'] .
"</div> </blockquote> <p>" . $row1['username'] .
"</p> </td>";
}
}
Try something like this:
while($row1 = mysql_fetch_array($result1)){
$html = '';
if (++$x % 2 ){
$html .= "<blockquote class='example-right'>";
} else {
$html .= "<blockquote class='example-obtuse'>";
}
$html .= $row1['update'];
if($row1['schuedled'] == '1'){
$html .= "<div class='ref'>Ref: " .$row1['ref'] . "</div>";
}
$html .= "more html";
$html .= "more html";
$html .= "more html";
$html .= "</blockquote>";
echo $html;
}
below I have values and below that I have a while loop with multiple values that are sorted by $top_list_friends['workouts'], with the highest number at top.
How can a merge the below values into one list?
echo "<div class='user'>";
echo "<span class='number'>" . $my_rank . "</span>";
echo "<span class='name'>" . $personal['name'] . "</span>";
echo "<span class='workouts'>" . $personal['workouts'] . "</span>";
echo "</div>";
$i = 0;
while ($top_list_friends = mysql_fetch_array($query_top_list_friends)) {
$i++;
echo "<div class='user'>";
echo "<span class='number'>" . $i . "</span>";
echo "<span class='name'>" . $top_list_friends['name'] . "</span>";
echo "<span class='workouts'>" . $top_list_friends['workouts'] . "</span>";
echo "</div>";
}
Didn't understand question very well, but I would do it in this way:
$name = $personal['name'];
$workouts = $personal['workouts'];
$html = <<<html
<div class='user'>
<span class='number'>$my_rank</span>
<span class='name'>$name</span>
<span class='workouts'>$workouts</span>
</div>
html;
$i=0;
while ($top_list_friends = mysql_fetch_array($query_top_list_friends)) {
$i++;
$topName = top_list_friends['name'];
$topW = $top_list_friends['workouts']
$html += <<<html
<div class='user'>
<span class='number'>$i</span>
<span class='name'>$topName</span>
<span class='workouts'>$topW</span>
</div>
html;
}
echo $html;
At the beginning:
$inserted=0;
into the loop:
if(!$inserted && $personal['workouts']> $top_list_friends['workouts'])}
$inserted=0;
//first div echoes
}
at the end
if(!$inserted){
//the same echos
}
How can I slice away the first value?
foreach ($dataArray ['simpleforecast']['forecastday'] as $arr) {
$html .= "<td align='center' style='font-size:10px; font-weight:bold' >" . substr($arr['date']['weekday'], 0,3) . "<br />";
$html .= "<img style='border-radius:15px' src='http://icons-pe.wxug.com/i/c/a/" . $arr['icon'] . ".gif' border=0 /><br />";
$html .= "<font style='font-weight:bold' color='#555'>" . $arr['high'][$tempScale] . $tempUnit . " </font>";
$html .= "<font style='font-weight:normal' color='grey'>" . $arr['low'][$tempScale] . $tempUnit . "</font>";
$html .= "</td>";
}
$first = array_shift($dataArray ['simpleforecast']['forecastday']);
// use your loop
Quick and dirty:
$first = true;
foreach ($dataArray['simpleforecast']['forecastday'] as $arr) {
if ($first) { $first = !$first; continue; }
$html .= "<td align='center' style='font-size:10px; font-weight:bold' >" . substr($arr['date']['weekday'], 0,3) . "<br />";
$html .= "<img style='border-radius:15px' src='http://icons-pe.wxug.com/i/c/a/" . $arr['icon'] . ".gif' border=0 /><br />";
$html .= "<font style='font-weight:bold' color='#555'>" . $arr['high'][$tempScale] . $tempUnit . " </font>";
$html .= "<font style='font-weight:normal' color='grey'>" . $arr['low'][$tempScale] . $tempUnit . "</font>";
$html .= "</td>";
}
$i = 1;
foreach ($dataArray ['simpleforecast']['forecastday'] as $arr) {
if($i==1)
{
$i++;
continue;
}
$html .= "<td align='center' style='font-size:10px; font-weight:bold' >" . substr($arr['date']['weekday'], 0,3) . "<br />";
$html .= "<img style='border-radius:15px' src='http://icons-pe.wxug.com/i/c/a/" . $arr['icon'] . ".gif' border=0 /><br />";
$html .= "<font style='font-weight:bold' color='#555'>" . $arr['high'][$tempScale] . $tempUnit . " </font>";
$html .= "<font style='font-weight:normal' color='grey'>" . $arr['low'][$tempScale] . $tempUnit . "</font>";
$html .= "</td>";
}
if(key($dataArray) === 0)) continue; But this will work only if you do not specify keys manually.
How can I modify this xml data to appear in a list format?
foreach ($dataArray['simpleforecast']['forecastday'] as $arr) {
$html .= "<td align='center'>" . $arr['date']['weekday'] . "<br />";
$html .= "<img src='http://icons-pe.wxug.com/i/c/a/" . $arr['icon'] . ".gif' border=0 /><br />";
$html .= "<font color='red'>" . $arr['high'][$tempScale] . $tempUnit . " </font>";
$html .= "<font color='blue'>" . $arr['low'][$tempScale] . $tempUnit . "</font>";
$html .= "</td>";
}
I'm just assuming you mean this, because you're not really clear at describing what you wanted.
$html = "<ul>";
foreach ($dataArray['simpleforecast']['forecastday'] as $arr) {
$html .= "<li>" . $arr['date']['weekday'] . "<br />";
$html .= "<img src='http://icons-pe.wxug.com/i/c/a/" . $arr['icon'] . ".gif' border=0 /><br />";
$html .= "<font color='red'>" . $arr['high'][$tempScale] . $tempUnit . " </font>";
$html .= "<font color='blue'>" . $arr['low'][$tempScale] . $tempUnit . "</font>";
$html .= "</li>";
}
$html .= "</ul>";
To skip the current day you could use the following pseudo code on the third line
if(today) continue;
But since I do not now ow to check whether it is to day, I left this open for you to figure out.