I'm loading photos from database with mysql query. For default it load data from database with pagination.
<div class="col-md-10 bg col-md-push-2 ">
<div class="align_center gallery">
<?php
include "anj.php";
$sql = 'SELECT * FROM new_photos ;
/* function anjaan content code for loading photos .*/
anjaan($sql);
}
?>
</div>
<div class=" align_center ">
<div class=" col-md-12 pagination gallery">
<?php
echo $paginationctrl;
?>
</div>
</div>
Now I want when user click a button data should change with this
<?php
include "anj.php";
$sql = 'SELECT * FROM new_photos WHERE weight BETWEEN 10 AND 15';
anjaan($sql);
?>
Php is just server side, so i think u only will have two options.
1 - On click reload de page and send a post or get params to the application usign form and then load the page with the new query.
2 - If u want to do not reload te page, will be better to send an Ajax request to server side with JavaScript and then bring and replace the old content for the new one.
Related
I want to make some kind of booking system. I am displaying all data about cars from the database with buttons(which is a link that directs to the booking page) in "boxes", each box is for one car. I want to get id of the car for which the user pressed the button in box where the car is.
Here is my code
<!-- Fetching data from rows -->
<?php
while($rows = $result->fetch_assoc())
{
?>
<div class="car_box">
<div class="car_title">
<p><b><?php echo $rows['Brand'],' ', $rows['Model'];?></b></p>
</div>
<div class="car_description">
<div class="car_details">
<!-- ENGINE CAPACITY -->
<p>
<b>Engine capacity: </b> <?php echo $rows['Engine_capacity']; ?> cm3
</p>
(...)
<!-- BOOKING -->
<div class="booking">
Book now
</div>
</div>
You could try adding a parameter to your link.
Book now
and retrieve it in your Bookings.php by using $_GET['id'].
I'm showing photo from database with onclick
<div class="align_center gallery">
<?php
if(isset($_GET['s'])){
include "anj.php";
$sql = 'SELECT * FROM new_photos WHERE weight BETWEEN 10 AND
15';
anjaan($sql);
}else{
include "anj.php";
$sql='select * from new_photos';
anjaan($sql);
}
?>
</div>
<div class=" align_center ">
<div class=" col-md-12 pagination gallery">
<?php
echo $paginationctrl;
?>
</div>
My problem is when I click on next page from pagination, it show next page from else statement's query.
I mean I want my second page load from
'SELECT * FROM new_photos WHERE weight BETWEEN 10 AND
15';
But it show next page from
'SELECT * FROM new_photos ';
This could be in HTML That is not a very secure approach, I would recommend to change INPUT to:
<input type="submit" onclick="javascript:window.assign ='index.php?s=nextpage'" class="btn_custom" />
if that didn't work, please enable developer mode in Chrome or Firefox and check your HTTP header to make sure you see GET header.
also it may affect you if you have a POST form in your page that we can't see
I want to use a single file with multiple pages.
In the #first page I have a link to another page with a value sent via GET:
<a href='#second?ID=10'>
And when triggered, it should show the second page and write the value with php:
<div data-role="page" id="second">
<div data-role="header" data-add-back-btn="true">
<h1>Second page</h1>
</div>
<div data-role="content">
<?php
$ID = $_GET["ID"];
echo $ID;
?>
</div>
</div>
It seems that the php code isn't run when the second page is loaded.
Is there any easy way to do this?
I am trying to pull some information from my database and put it in a modal. I went to the foundations website and tried to figure it out from their docs section. I dont exactly understand it. So I have a section of my site that allows users to request to delete a song they uploaded. Now if they click the X a modal should pop up and ask to confirm.
<div class="row">
<div class="large-8 column musicup">
<p> <?php echo "No music uploaded..."; ?> </p>
</div>
</div>
<?php
}else{
?>
<h2 style="margin-top:1em;">Music uploaded</h2>
<hr style="opacity:.4;">
<?php
while($row_a = mysql_fetch_array($res))
{
?>
<div class="row">
<div class="large-4 column musicup">
<p><?php echo $row_a['title']; ?></p>
</div>
<div class="large-3 column musicup"><span data-tooltip class="has-tip tip-top" title="<?php echo $row_a['reason']; ?>">
<div class="button <?php echo $row_a['status'];?>"><?php echo $row_a['status'];?></div>
</span></div>
<div class="large-3 column musicup_date">
<p><?php echo date('F j Y',strtotime($row_a['uploaded'])); ?> </p>
</div>
<div class="large-2 column musicup">
<p>X</p>
</div>
</div>
<?php
}
}
}
?>
</div>
So now I have the modal and all the database queries on a new page called song_delete.php.
Here is the code for that:
<?php
include_once "functions.php";
$query = sprintf("SELECT * FROM songs WHERE user_id = %d AND song_id = %d",$_SESSION['user_id'], $_GET['id']);
$res = mysql_query($query) or die('Error: '.mysql_error ());
$row_a = mysql_fetch_assoc($res);
$totalRows_a = mysql_num_rows($res);
?>
<div id="deleteMusic" class="reveal-modal medium">
<h2>Request to delete<span style="color:#F7D745;"> <?php echo $row_a['title']; ?></h2>
<p class="lead">Are you sure you want to delete this song? Please allow 2 full business weeks for deletion.</p>
<span style="float:right;">Cancel
Submit </span>
<a class="close-reveal-modal">×</a>
</div>
Thanks for any help in advance. I appreciate it.
Please dont tell me about the mysql_query and how I should use PDO or MySQLi and OOP i know this, but this site is not currently coded with all that..
OK first things first - its often better to look at the compile source (HTML Source Code) in these cases. Can you do this? From the code you've given it looks fine but without the css/js linking and showing the placement of the reveal code there's no way to tell.
How Foundation Reveals Work
1 - The modal code is placed just before the ending </body>.
2 - It should look something like this:
<div id="myModal" class="reveal-modal">
<h2>Awesome. I have it.</h2>
<p class="lead">Your couch. It is mine.</p>
<p>Im a cool paragraph that lives inside of an even cooler modal. Wins</p>
<a class="close-reveal-modal">×</a>
</div>
3 - Depending on the size you want you can use an extra class of .small (for a reveal size of 30% browser width. Or one of these (taken directly from Foundation Docs)
.medium: Set the width to 40%.
.large: Set the width to 60%.
.xlarge: Set the width to 70%.
.expand: Set the width to 95%.
4 - At this point you can attach data-reveal-id="<id of modal here>" or call the modal via foundation. At this point your modal will popup in all Foundation 4 supported browsers. However you need the javascript files to close it.
5 - Now make sure you have the necessary scripts
<!-- If running version with default scripts -->
<script src="foundation.js"></script>
<script src="foundation.reveal.js"></script>
6 - Then call $(document).foundation() and then via the magical jQuery javascript library it should work as intended :-).
Extras
You can add extras attributes to reveal if you wish this way (List of all the attributes
):
$(document).foundation('reveal',<options here>,<callback>)
Lastly you might want to take the ajax tag off this (you aren't calling any content in asynchronously - it's all compiled at runtime via your server
I am currently new to php.I am trying to display results from a database to the same html page.However am not using a form for searching,the search is universal.How can i display the results in same page?
For example heres a part of my html page
<body>
<div class="div1>
button to display results
</div>
<div class="div2">
</div>
and in my php everything is working fine.However i want when a user clicks the "button to display results" link,the results from the database should be displayed in div2.Help will be highly appreciated.
Try this: it will cause the page to refresh passing 1 to the query string to indicate whether to display or not
<div class="div1>
button to display results
</div>
<div class="div2">
<?php
$display = $_GET['display'];
if($display)
{
//do some dispaly here
}
?>
</div>