In my PHP application there is a link which generate total summary data. Now I need to add another link which generates current date summary data rather than total summary.
I created the link and got the query to do the same. Now the challenge is to identify which link is clicked in the function. Is there any way I can get the clicked link text from php code? So that I can differentiate between them and call the appropriate branch of code can be executed.
You can use $_GET to differenciate which link was clicked.
in your HTML, make the links like this:
<a href='my_page.php?report_id=1'>Report 1</a>
<a href='my_page.php?report_id=2'>Report 2</a>
In your PHP file (in the example above, it is my_page.php) it should have something like:
<?php
if (isset($_GET['report_id']) {
$report_id = $_GET['report_id'];
if ($report_id =='1') {
// ... generate the first report here
}
else if ($report_id=='2') {
// ... do the other stuff here
}
}
?>
You could have the links direct to different pages one page for total summary one for daily or you could put the info in the URL of the link for instance
<a href="path.php?daily_report=true>Generate daily<\a>
<a href="path.php?total_report=true>Generate total<\a>
Post your code if that doesn't help
Related
I have a few php files, lets call them planet1.php, planet2.php, planet3.php and satellite.php.
Each "planet" has a link to this unique "satellite.php" file this is because the information there is all the same no matter the "planet" where its being redirected. Now as I say all infomartion is the same but an image -which is inside a DIV as a background-image-.
Here's my question
How can I click the link in planet1.php and open satellite.php with visible or click on planet2.php and open satellite.php with ?
I have three differents "planets" and I need to display only one acoording where it's being redirected.
Thanks!
This is how I solved it (with the help of Lev Buchel)
Inside -> satellite.php
if (<? echo $_GET["planet"] ?> == 1){
document.getElementById("planet").classList.add("planet1");
}else if (<? echo $_GET["planet"] ?> == 2) {
document.getElementById("planet").classList.add("planet2");
}else{
document.getElementById("planet").classList.add("planet3");
}
Inside every planetX.php file
Styles...
<style>
.planet1{background-image: url('img1.JPG');}
.planet2{background-image: url('img2.JPG');}
.planet3{background-image: url('img3.JPG');}
</style>
Actual div with the image...
If i understood you correctly, you want the same "satellite" page to display a different image according to which "planet" file was clicked to reach it.
What you can do is to use a "GET" method, for example in your planet1.php file the href will look like this :
href="satellite.php/?planet=1"
Same goes for planet2 (planet=2) and planet3 (planet=3).
In your satellite.php page you can check which planet the user came from using
if ($_GET["planet"] == 1)
document.getElementById("yourDiv").classList.add("planet1");
Now you can set a different background for class planet1/2/3.
I'm creating a video site using PHP, and I want to insert video source code from a PHP URL.
For example, if I want to get Episode 1 from PHP, I want it like this:
example.com/player.php?=episode1
For Episode 2:
example.com/player.php?=episode2
I don't understand how to link all of the source pages with the main index page.
How can I accomplish this task?
Here's a way you could do it: Use a form on your homepage (index.html?) to select which video you want, and send it to player.php using a GET method. Then use the following on player.php:
<?php
$select = $_GET['select']; //This will be the number input for the video number
echo("<video><source src="episode$select.mp4"></video>"); //This will source the video named `episodeX.mp4`, where `X` is the select value from the form on `index.html`.
?>
Just ask if you need any additional clarification.
We're trying to create a trackback system where an outside web publisher can put some html on a page on their website that links back to a specific product page on our site. Let's call it a 'badge' for purposes of this question.
Once they've inserted the badge, we want to identify this, then grab the < h1 > and first < p > as a teaser to comprise a link from our site back to theirs and write all this stuff to our database. Then, our users can see the title and first bit of their page, then decide if they want to see more.
Here's what we've done (not much I'm afraid):
<a href="http://www.mysite.com/abc.html">
<img alt="abc" src="http://www.mysite.com/logo.gif" style="width:200px;height:100px" />
</a>
We're planning to build an admin page to do the last part of grabbing the < h1> and < p> and posting it to the live database, etc. and we'll figure this out later.
However, the middle step (identifying that this piece of html has been used) we're at a loss.
Is this something we should be doing through a log file....I have no clue even how to begin thinking about it.
A little direction of where to begin working on this problem would be very helpful.
Thanks in advance!!
This is one approach.
You give them HTML which looks something like:
<a href="http://www.mysite.com/abc.html">
<img alt="abc" src="http://www.mysite.com/logo.php" style="width:200px;height:100px" />
</a>
Notice that says logo.php, not logo.gif.
logo.php will live on your server. Its purpose is twofold:
Gather information about the page holding the <img> tag
Load and output logo.gif so the users see the image as expected.
If you embed that html on a webpage somewhere, logo.php will have information about where the request for the image originated. Specifically, $_SERVER['HTTP_REFERER'] will give you the complete URL to the page where the img tag resides. It is then up to you to decide how to process and store that information.
I don't know exactly what you want to do, but a very simplified logo.php would look something like this:
<?php
$url = $_SERVER['HTTP_REFERER'];
// do something with $url...
// it will be something like "http://theirsite.com/wherever/they/pasted/the.html"
// now output the logo image...
header("Content-Type: image/gif");
echo file_get_contents("/path/to/logo.gif");
Keep in mind that every time anyone hits their page with the image tag, logo.php will be run. So don't accidentally create 10000 links back to their site on your site :)
We have several pages generated using PHP on our website with the following titles (for example):
http://www.mysite.com/project/category/1
http://www.mysite.com/project/category/2
http://www.mysite.com/project/category/3
Each one is created dynamically with the same page layout with each showing a different database result depending on the predefined conditions.
I would like an image to be displayed at the top of the page for just one of the results, let's say for http://www.mysite.com/project/category/2 - how can I go about this?
The relevant code on our page is this:
$category=mysql_fetch_array(mysql_query("select * from project_category where project_category_id='".$project_category_id."'"));?>
If we go down the if statement route can you show an example of how to display an example image by modifying the above code to get me started?
I would probably make it a property (can be a as simple yes/no) in the database, and use the existing db-result to determine if the category has to display a page. Although this might seem overkill - I'd definitely pick this dynamic solution over a if ($categoryId == 2) { } solution any day. Keeps it dynamic and your code clean and generic.
In the end I opted for an if statement (as found here http://www.tizag.com/phpT/if.php).
The original code above was modified in the following way:
$category=mysql_fetch_array(mysql_query("select * from project_category where project_category_id='".$project_category_id."'"));
if ( $project_category_id == "2" ) {
echo '<img src="http://www.mywebsite.com/image.jpg" width="675" height="75" border="0" />';
}?>
I have searched but could not find answer to my satisfaction so
I have a header file, which is being included on top of every page and part of the header is a menu with 3 tabs, when user click on tab browser take them to that page (working fine), what i want is, that what ever tab user clicks to be highlighted(diff back color) when that page is loaded.
Here is html :
<div id="top-choicebar">
<ul id="topmenu">
<li><a href="daily.php" class="ww" >Daily</a></li>
<li>< href="weekly.php" class="ww">Weekly</a></li>
<li>< href="monthly.php" class="ww">Monthly</a></li>
</ul>
<div id="event-menu">
New to php and jquery ... any help will be greatly appriciated
You can do that by means of CSS and conditional classes.
Weekly
Monthly
you can try using something like this, but it's very rudimentary:
<?php if (preg_match("/weekly.php/i", $_SERVER["SCRIPT_NAME"])) {
// Tab should be highlighted
< href="weekly.php" class="ww active">Weekly</a>
} else {
< href="weekly.php" class="ww">Weekly</a>
}
?>
this will add an 'active' class to the link, that you can then style with CSS to change the background colour...
What I've always done in the past is pass a parameter to the class that is building the menu based on what page I'm loading.
So daily.php loads up Header.php and passes it a variable like new Header(0) when Header builds the html, it loops through the links to print them, and on the number that's been passed, it adds a class like current.
So if:
Daily == 0
Weekly == 1
Monthly == 2
The header would pick the correct one to apply the class to based on the page that calls it.
Of course, this would only work if your menu links are being stored somewhere besides raw HTML, like in a database or even just an array.
Have a class setup like .selected{background-color:red} That defines the different background color you want to view. Then when you render the page, since you already know which tab it is, you just render the selected tab with that class attached. If you are rendering the tab content through ajax you can just find all tabs with class "selected" and then add the class to the selected tab
$("#topmenu li").live("click", function()
{
$("#topmenu").find(".selected").removeClass("selected");
$(this).addClass("selected");
});