$i = 0;
while($row = $statement->fetch()) {
$current_id = 'id-' . $i;
$i++;
echo "
<tr>
<td>
<p>
<button class='btn btn-primary'
type='button'
data-toggle='collapse'
data-target='#<?=$current_id?>'
aria-expanded='false'
aria-controls='Collapse'>
Button with data-target
</button>
</p>
<div class='collapse' id='<?=$current_id?>'>
<div class='card card-block'>
Here is the content for block which will be shown when the button. This uses button with data-target attribute for collapsing.
</div>
</div>
</td>
";
}
Where is my error? It doesn't collapse but I need the unique ids for my rows.
now it work. What i have to do now:
$ccid = "#$current_id";
$ccid2 = "$current_id";
And then i have put the variables inside of ID and Href Like this:
href='".$ccid."'
id='".$ccid2."'
That fixxed this problem. Thanks to all!
Related
What I exactly need:
inside the foreach for every element I create a button. Then connect to postgresql db, select data from the table by condition.
If there is a matching entry in the database then I display <span class="fa fa-heart"> </span>. If no entries then display <span class="far fa-heart"></span>. I need this output exactly inside <button> </button> tag.
<form method="POST">
<?php foreach ($rows as $data): ?>
<button class="btn btn-outline-danger mx-1" name=fav-click style="font-size: 11px;">
<?php
$linkk = pg_connect("host=localhost dbname=webportal user=postgres password=1234567");
$favor=(int)$data['obj_id'];
$id_usr=(int)$id;
$query = "select obj_id, usr_id from favorites where usr_id='$id_usr' and obj_id='$favor'";
$re = pg_query($linkk, $query);
$row1=pg_fetch_all($re);
if(pg_num_rows($re)==0)
{
echo '<span class="far fa-heart"></span>';
}
if(pg_num_rows($re)>0)
{
echo '<span class="fa fa-heart"> </span>';
}
?>
</button>
inside the form there also are
<input type=hidden name=obj_id value=<?= $data['obj_id'];?>>
<input type=hidden name=id_usr value=<?= $id; ?>>
in which I store the values I need.
Outside the foreach I have:
<?php
if(isset($_POST['fav-click']) && isset($_POST['obj_id']) && isset($_POST['id_usr'])) {
$oo = $_POST['obj_id'];
$uu=$_POST['id_usr'];
if(pg_num_rows($re)==0)
{
$zapr="insert into favorites(obj_id, usr_id) values($oo, $uu)";
$done = pg_query($linkk, $zapr);
}
if(pg_num_rows($re)>0)
{
$zapr="delete from favorites where obj_id='$oo' and usr_id='$uu'";
$done = pg_query($linkk, $zapr);
}
}
?>
But it works not correctly because it always displays and does queries in the db for the last element of foreach. Doesn't matter if I click a button for another one.
How can I fix it?
I am creating dynamic posts data on ajax call in which i am creating checkboxes also. but checkbox is not clickable. it is being showed on document but not responding on click. no showing tick i mean checked and uncheked states on user clicks. Everything is working fine except checkboxes. I did not done any jquery for checkboxes yet.
In Console i checked checkbox html and id value etc shown properly
here is my code //
if(mysqli_num_rows($result) > 0){
$output = "";
$output .= "<div class='col-12'><p id='content-title'>Fresh Posts</p></div>";
while($row = mysqli_fetch_assoc($result)) {
$title = substr($row['title'],0,25) . '...';
$description = substr($row['description'],0,200) . '...';
$output .= "<div class='col-4'>
<div class='post-content'>
<a href='single-post.php?id={$row['post_id']}' class='post-img'>
<img src='dashboard/uploads/{$row['post_img']}'>";
if(isset($_SESSION['logged-in'])){
$output .= "<input type='checkbox' id='{$row["post_id"]}' value='{$row['post_id']}' class='fav-icon-checkbox'>
<label for='{$row["post_id"]}'><i class='fa fa-heart fav-icon'></i></label>";
}
$output .= "</a>
<div class='post-info-container'>
<div class='post-info'>
<span class='post-author'><a href='#'>{$row['author']}</a></span>
<span class='dot'></span>
<span class='post-category'><a href='category.php?id={$row['category_id']}'>{$row['category_name']}</a></span>
<br>
<span class='post-date'>{$row['date']}</span>
</div>
<h5 class='post-title'>{$title}</h5>
<p class='post-description'>{$description}<a href='single-post.php?id={$row['post_id']}' class='read-more'>read more</a></p>
</div>
</div>
</div>";
}
echo $output;
}
Check the value attribute of the checkbox try changing the single quote :: $row["post_id"].
I'm creating an admin panel for small ecommerce website (to practice) and I have no idea how to make php understand which id product I want to update after I click this little <i></i> element because I already use $_POST['<i> element name'] in order to detect whether or not it's ready to be updated, I know you cannot assign 2 names to one element otherwise I could use $id = $results['id']; as second name... any advices? I'm completely new in php. sorry if this post is stupid I just need some help...
$query="select * FROM productadd";
$result= mysqli_query($connection, $query);
$results = mysqli_fetch_array($result);
if(!empty($results['id'])) {
while($results = mysqli_fetch_array($result)){
$id = $results['id'];
$name = $results['name'];
$text = $results['text'];
$price = $results['price'];
$image = $results['image'];
echo '
<tr>
<td>'.$id.'</td>
<td>'.$name.'</td>
<td>'.$text.'</td>
<td>$'.$price.'</td>
<td>
<img src="'.$image.'" style="style="display:block;" width="100%" height="100%" ">
</td>
<td>
<a class="add" value="asd" title="Add" name="edit" data-toggle="tooltip">
<i class="material-icons"></i>
</a>
<a class="edit" name="edit" title="Edit" data-toggle="tooltip">
<i class="material-icons"></i>
</a>
<a class="delete" title="Delete" data-toggle="tooltip">
<i class="material-icons"></i>
</a>
</td>
</tr>';
}
}
So I have a table listing the users, and a button each row to edit in modal. I'm using while loop by the way, but my problem is that it only get the last row every time i click any of the button in the rows. I checked the id's of each row via inspect in browser and they have the right id's. It's just that when i clicked it gives the last row. I'm kind of puzzled because i tried in bootstrap modal and my code is working fine but in materialize css, not.
my loop, inside the loop is the tr and td.
while ($row = mysqli_fetch_assoc($select_user)){
$account_id = $row['account_id'];
$username = $row['username'];
$firstname = $row['firstname'];
$middlename = $row['middlename'];
$lastname = $row['lastname'];
$house_number = $row['house_number'];
$street_name = $row['street_name'];
$provincial_address = $row['provincial_address'];
$gender = $row['gender'];
$occupation = $row['occupation'];
$cel_number = $row['cel_number'];
$tel_number = $row['tel_number'];
$house_model_name = $row['house_model_name'];
$mdues_status = $row['mdues_status'];
$account_status_name = $row['account_status_name'];
$address = '#'. $house_number.' '.$street_name;
$fullName = $firstname.' '.$middlename[0].'. '.$lastname;
$fullContact = $cel_number.' , '.$tel_number;
}
this is the button
echo "<td><button class='waves-effect waves-light btn update modal-trigger' data-toggle='modal' data-target='billingModal' id='{$account_id}' style='margin: 5px; background-color: #6E6702;'><i class='material-icons left'>create</i>Edit</button></td>";
this is the modal
<div id="billingModal" class="modal" role="dialog">
<div class="modal-content">
<h5><?php echo $account_id?></h5> <!--Name of home owner-->
<div class="divider"></div>
<p><?php echo $address?><br> <!--Address of home owner-->
09152462389</p><!--Contact Number of home owner-->
</div> <!--TABLE FOR BILL-->
<!-- <input type="input" id="id"> -->
<div style="margin: 20px;">
<div class="row">
<h5><span style"background-color: #B7AFAF;">Billing Summary</span></h5>
<div class="divider"></div>
</div>
</div>
<div class="modal-footer">
Close
Print
Pay
</div>
</div>
i tried also doing like this in button
echo "<td><button class='waves-effect waves-light btn update modal-trigger' data-toggle='modal' href=#billingModal$account_id;' style='margin: 5px; background-color: #6E6702;'><i class='material-icons left'>create</i>Edit</button></td>";
and in modal
<div id="billingModal<?php echo $account_id; ?>" class="modal" role="dialog">
<< Referring to this thread >>
I want to make several modal-box on a page:
<script>
var grid_modal_options = {
height: 'auto',
width: '80%',
modal: true
};
function showProducts1ModalBox() {
$("#products1_modal_box").dialog(grid_modal_options);
$("#products1_modal_box").parent().appendTo('form:first');
}
function showProducts2ModalBox() {
$("#products2_modal_box").dialog(grid_modal_options);
$("#products2_modal_box").parent().appendTo('form:first');
}
function showProducts3ModalBox() {
$("#products3_modal_box").dialog(grid_modal_options);
$("#products3_modal_box").parent().appendTo('form:first');
}
</script>
<div id="products1_modal_box" title="Products" style="display: none;">
<div class="in">
<div class="grid-12-12">
<form id="products1_modal_box_form" action="#" method="post">
<table>
<thead>
<tr>
<th> </th>
<th>Product</th>
</tr>
</thead>
<!-- Query for read mysql goes here (I skipped this line because it's not the main thing I'm gonna ask since it's run well) /-->
<tbody>
<?php
//read the results
while($fetch = mysqli_fetch_array($r)) {
print "<tr>";
print " <td>Choose</td>";
print " <td>" . $fetch[0] . "</td>"; //$fetch[0] == Product ID
print "</tr>";
}
?>
</tbody>
</table>
</form>
</div>
</div>
</div>
<div id="products2_modal_box" title="Products" style="display: none;">
<!--
The rest goes here (the same with "products1_modal_box")
except:
print " <td>Choose</td>";
/-->
</div>
<div id="products3_modal_box" title="Products" style="display: none;">
<!--
The rest goes here (the same with "products1_modal_box")
except:
print " <td>Choose</td>";
/-->
</div>
And:
<input type='text' id='products1_id_textbox' name='products1_id_textbox' />
<a href='#' onclick='showProducts1ModalBox(); return false;'>Choose products 1</a>
<input type='text' id='products2_id_textbox' name='products2_id_textbox' />
<a href='#' onclick='showProducts2ModalBox(); return false;'>Choose products 2</a>
<input type='text' id='products3_id_textbox' name='products3_id_textbox' />
<a href='#' onclick='showProducts3ModalBox(); return false;'>Choose products 3</a>
Why this doesn't work? When I removed the div "products2_modal_box" and "products3_modal_box", the modal-box for div "products1_modal_box" appear, but when I tried to get back all of them, each modal-box doesn't appear while I clicked the link. What's wrong with the code? Thanks..
This doesn't technically answer your question, but I use jQuery Reveal for modals on my site. Seems a lot easier than what you're trying to do. Here's the source: http://www.zurb.com/playground/reveal-modal-plugin
It's really easy to set up, and you can have multiple modals per page, and can trigger them with an event (such as a click) or dynamically with jquery.
Hope this helps!