Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I just want to ask if possible to call an image using php? For example I have homepage that has 1 div for image (pic1) then after two weeks I will change the image into (pic2). How can I accomplish it without going to my cpanel to change the code . Are there any program or languages that can help me to do that? I am trying to do the back-end side of my homepage to change the images.
Changing images is very simple. If you want to do it automatically, you could setup a CRON job or use PHP's date function. If you want to do it manually, by selecting a button, you can do it like this:
<script>
function changeSrc() {
document.getElementById("myImage").src="imageName.jpg";
}
</script>
<body>
<img id="myImage" src="otherImage.jpg" width="107" height="98">
<br><br>
<input type="button" onclick="changeSrc()" value="Change image">
</body>
http://nl1.php.net/manual/en/function.date.php
You can use PHP's date() function in combination with an if/else statement to determine what picture to use.
Example:
if(date('d-m-y') == 'yourdate'){
//Show picture 1
}
Next to that, with a little searching you could've figured this out on your own perfectly fine ;)
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to be able to have my main page (index.php) check every 10 seconds for a change in the mysql database table 'refresh'. If the 'refresh' value is 1 it needs to refresh the page in its entirety. If the value is zero it does nothing. I would use meta-refresh but I cannot have the page always refreshing as the page has a slider and it would mess up the rotation. Please let me know what you think of! Thanks in advance!
Use AJAX to check if an update is required.
http://api.jquery.com/jQuery.ajax/
You should learn the basic how to's of AJAX before using something like jQuery when you don't even know what's going on.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I want to know if it is possible with PHP to make action only happen once.
I have a script where users click an image and gain points for clicking it, but I would like to make it so that if they click again it won't add points anymore for a certain amount of time, or an advertisement would disappear from the site for that particular user.
Is this possible?
Store it in the database.
When they click on the image, run a query that changes the is_clicked column (for instance) to clicked or 1 or whatever you like.
Retrieve the image in such a way that, if the is_clicked column is changed to clicked for a particular user, then don't allow any clicks.
For example :
if($row['is_clicked'] != 'clicked']){
echo '<img>....</img>';
}
It is possible but with PHP, it can get pretty messy. I would suggest you use JS (Javascript). Create a simple function in JS and then use the onclick attribute in the the button element to execute. Like this:-
<script>
document.getElementById('id of the button').onclick='myFunc';
function myfunc(){
document.getElementById('id of the button').style.display="block";
}
</script>
Front end, html:
<button id="id of the button">Click here!</button>
Now if you want to make sure a person who clicks button from a computer shouldn't be able to click it again, then you should set up a cookie using php which will retrieve data about its computer and prevent the computer from using this button
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Is there any way to add php code for updating automatically the seconds in time format without using javascript.
Thanks
Do you mean you want to update a time value in rendered HTML that was produced by PHP?
The only way is to continually reload the page using some HTML reloading tag that I can't (and don't want to) remember every second to show the updated time. Don't do it please, it's annoying to users. Use JavaScript or just don't do it.
Try meta tag in html
<meta http-equiv="refresh" content="1;url=your_url">
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want $counter=$counter +1, when this link on my website is clicked:
<img src="images/old.jpg" width="190" height="32" />
I've tried $counter++; in several creative ways, none of which seem to have worked.
PHP is a server-side language.
This means that PHP is (most often) only responsible from
When the server receives a request
until
The PHP program outputs the page.
So if you want something to happen in response to your action AFTER the page is loaded (e.g. clicking a link), PHP cannot handle that.
Now, you should choose your implementation in either Javascript or PHP depending on what you want to achieve.
If you want to store the counter value in your server, and increment it:
Set the destination of the link to the exactly same page as the one you are viewing now. Use $_SESSION to store a value, and it will be stored across multiple requests.
If you want to see the value of the counter go up as you click on the link:
Use Javascript to store the counter as an variable, and increment it on each click. This will be reset if you refresh the page.
Note: You cannot achieve neither of this if your link takes you to another page. That becomes a whole new story.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I would like to know how you add a function that clears the contents in the textarea if something is typed. For example, the standard message in the textarea would say: "Type something...", but if something is typed, the textarea would be cleared. Basically, the same function that Facebook uses in their wallpost-textarea.
And how do I make the height of the textarea automatically follow the amount of text, so no scrollbar is needed. Again, the same function that Facebook uses in their wallpost-textarea.
Actually, I've noticed that the function that clears the contents in the textarea/input field is used on this site's signup page, when you entering your e-mail, password etc.
I hope that some of you can help me. I've tried to find a script about it but without any luck!
The first thing is a (HTML5) placeholder attribute. It is a message that is there by default and when you start typing it goes away.
http://www.w3.org/html/wg/drafts/html/master/forms.html#the-placeholder-attribute
For the second one you need some JavaScript.
$('textarea').on('keyup',function(e){
$(this).css('height',$(this).get(0).scrollHeight);
});
Probably not the best solution but you could try something like the following.
<script>
function textAreaAdjust(o) {
o.style.height = "1px";
o.style.height = (25+o.scrollHeight)+"px";
}
</script>
<textarea cols="50" id="textAreaAdjust" style="overflow:hidden" placeholder="Type something..." onkeydown="textAreaAdjust(this)"></textarea>
jsfiddle example