Weird to describe but here goes.
I have a table with several rows. One of the fields in each row, is for an image. Now i dont want to show the image itself, but rather the filename of the image as a link.
When i click that link, i want to popup a window that will let me upload or choose a new image from a list.
The key is, when im done, i want the new filename to show up on the table a-la inline edit style.
Now i know how to display the filename as a link, i know how to popup a window, i know how to upload images, or display some to select from. What i dont know how to do, is once i select or upload an image, to then go back and change that text.
Say the fieldname containing the filename text is #picfield1.(will be unique per field)
What would be the best way of building this. Should i use a layer on page like a modal, or should i use a seperate window?
When the popup is opened, you need to pass to it the row, or id, of the link that was clicked. Once the popup is done and prior to calling its window.close() function (if it's a real popup), have it do something like this:
window.opener.updateImageLink(row, fileName); //will call a function on the parent window
Where row is what was passed to this popup initially and filename is the effective filename with which to update the link.
This will call the following function:
function updateImageLink(row, fileName)
{
document.getElementById("#picfield" + row).innerHTML = escape(fileName);
}
This assumes that the fields are enumerated as #picField1, #picField2, etc. You may need to add one to row when making this call.
This needs to be tweaked, of course, based on your specific needs.
Related
I have a website which essentially acts as a blog / photo gallery. It comprises PHP and MYSQL.
My objective is to be able to set an image on my homeimage dynamically. I have set up a form which posts a variable (which contains the relevent image filename) to my homepage file. I pick this up using the $_POST method. This works fine, but only until I refresh the homepage at which point the variable is no longer there and so, understandably, the image is no longer called. Can anyone explain how I can store the variable value i.e. the image filename, so that it can be used until such time as it is overwritten by a new image. I have tried setting up a function that returns the value, but I can't seem to hold on to it!! Any guidance would be much appreciated.
Well, you can do multiple things :
Store it using MySQL. Create a table that will named "configuration" for example, with one field named "homepageImage" for example. When you want to modify the image on the homepage, just update this field. When you want to get the image, just query this table and fetch this field.
Store it in a file on your server. You just have to overwrite the file with the new filename inside it when you want to change the image. Fetch the content of the file when you want to display the image
Create a symbolic link (pointing to the right image), and update the link every time you want to change the image. When you want to display the image, just put the name of the link in your img tag
Use $_SESSION['some_variable'] = some value;
Later put 'if($_SESSION['some_variable'] = some value)' condition and display the image.
After the job done (if you need your visitors to do something) then distroy session.
session_destroy();
I'm looking at neatening my file structures and code. At the moment I'm making an image gallery, it has a management page which allows the user to upload, edit and delete images/information.
To upload an image, the user would select their files, sumbit the form and arrive at uploaded.php.
To delete an image, the user would click a link taking them to delete.php?id=IMAGEID.
To edit an image, the user would be taken to a page with an editor. Upon making any revisions they'd then be taken to edit.php?id=IMAGEID.
Each page runs either a function. I feel it's unecessary to have three different pages to run three different functions. Is there any way I could neaten this process?
Well, it just depends on how you like to manage your files and how you are using your IDE when you've to edit something.
If you're working alone, it's clearly up to you. If you know someone will, maybe, have to rework your code someday, having three files could be a plus, somehow.
I guess you're not concerned about SEO for these pages, but just in case the problem appears again, it could be better to have actions in parameters, rather than in files name.
/manage.php?edit or /manage.php?delete or /manage.php?upload
But, if your code is really really big, using three files could still result in a lower use of memory (Well, very slight improvement, but still)
Exactly you don't need 3 pages for each function
1)Delete ,instead of redirection the user to a different page and delete it ,you can add an image button which delete icon and when user click on it ,it call a specific function in your php and delete it then refresh your page.
2)Edit and Insert : these are 1 page ,like make your insert page if it doesnt have a query string with the Image ID then it's insert function ,else it contains and ID then load the content of this Image inside your inputs and while saving check if there is ID then update else insert new record
So,you moved from 3 pages to 1 page only.Hope this helped you.
I want to create a simple way to bookmark pages in my PHP app using Javascript.
I have a list of items and each one will have an image (maybe an empty star) which when clicked, will toggle a value in MySQL field for that specific user, (from 0 to 1) and also change the image for that item in the list to bookmarked (likely a full yellow star)
Where do I start?
Here is a quick primer:
you'll need to use javascript to trigger an action when the star is clicked. I suggest you use jQuery.
The action you trigger to do the following:
call the server to tell it the image has been clicked, with the jQuery.ajax() function: http://api.jquery.com/jQuery.ajax/
read the response of the server to make sure the user's preference was recorded (I suggest you use JSON to encode the response from the server, easier to use in JavaScript).
change the image. You can read this: Change the image source on rollover using jQuery
Happy coding
I am trying to make it possible for users to vote on some of my pictures online.
I am writing all my code in HTML, JavaScript and PHP.
When the user presses the vote button, it counts 1 up. Then when the user refreshes the page, I want to keep the vote, so it will still say 1, instead of resetting to zero.
My question is, how can I do this?
I found out I can't use javascript fileIO on my server.
I tried with some PHP, but most my code is in javascript and I can't figure out how to execute some code from a javascript function.
I have something like this in mind:
<body onload="opstart();">
When the body is loaded, I call a javascript function. Can I call some PHP here?
// Get number of votes from txt file
function opstart()
{
}
Inside this, I was thinking about reading the data from a text file and load it into the variable holding the number of votes.
Why are you storing these values in a text file. They should be in a database where you can easily pull them out in PHP. This will save you tons of time is much better practice.
You will need a users table with an ID for each user, an image table with an ID for each image, and a votes table recording who voted on what image ID. You then simply count the votes for each thing voted, and to stop someone from voting twice you can check if he has already voted!
See this answer for more details
Create one php page which accept your count and store in db
make ajax call in "opstart" function.
you can study following tutorial
http://net.tutsplus.com/tutorials/html-css-techniques/building-a-5-star-rating-system-with-jquery-ajax-and-php/
You could use a form as follows:
var feature_form =new Ext.form.FormPanel({
id: "featureInfo_panel",
url: 'myfile.php',
autoDestroy:true,
frame: true,
width: 410,
Where 'myfile.php' points to the name an location of the php you want to pass / get data from.
The php can easily trawl text files from there......
I think you dont have a proper database and you only want to do it using a text file. use Ajax to write in the text file about the last number of vote count done. Code will look something like this.
CODE
$.ajax(function(){
url:"voteup.php" //here you wrtie some function in php which takes care of file I/o
data:{votecount:9}//last vote count
success:function(){alert("success");}
}); // this function should to write new votes in your text file using ajax.
Now to read current votes on body onload. You have call a different ajax method to read that text file and get the current vote count..
CODE
function opstart()
{
$.ajax(function(){
url:"getvotes.php" //here you wrtie some function in php which takes care of file I/o
success:function(){alert("success");}
}); // this function should to read current votes in your text file using ajax.
}
So I have this site that dynamically posts content using jquery and php. I would like to know how to generate permalinks. I think I could do it, but I dont even know what I should be searching for on google. You can see the site at www.eataustineat.com.
For example, I would like a link like eataustineat.com/claypit to that would go directly to the video review, instead of having to to search for it and then click the link.
I will describe the how the site works on a basic level:
first the user selects the "All Restaurants tab" in the content slider, then jquery slides to the third frame.
Next, a user selects a link from a list. This list is generated by sql queries in php, while javascript pushes the result of the php to a specific div.
When a user selects a link, jquery slides to the second slide. Once again, php runs a query while javascript pushes the content to a specific div. As a result, the user never leaves the index page.
I think it depends on how your website works. The ideal thing that I have in my mind at the moment is:
Decide a unique way to find your video (could be a title, a file name, an id: must not change), if you are using a database it's a column with a value different for each entry
Create a webpage that accept as a parameter (not optional) (possibly a $_GET parameter, not a post) that unique key and fills it's content with entry's data (the video review hopefully)
Now the permalink will be yourwebsite/yourwebpage?myparam=myvalue
Normally the permalink is the numerical id referred to that entry (thinking about databases in this case)
Edit 1: If what you mean is "moving the webpage to the link" (and not creating it), maybe you should ignore my answer, I didn't understand the question so.
What suggested Tadeck, if this is the case, is good
Edit 2: What about if, following the keylines I given you to create a permalink, you pass this value to the homepage and on page load you fire the event through the click() function (so it's like if the user clicks on the link, fires everything that you need, even the scroller thing)
Obviusly you need to give an ID to each tag, but I don't think it's a big problem (just use directly your "permalink value" as an id
The alternative in using click() method, is: give to the slider function a name so you can call it instead of waiting the click event only, expecially this part
$('.cross-link').live("click", function(){
You'll have to replace function() with a named function
then you will call, on page load, that function + ajaxpage('result.php?id=9', 'results2') + ajaxpage('videoloader.php?id=9') completely emulating the click event in this case.
You still need however an id in the a tag to find out which is the link
You should search for one (or both) of the following points:
pushState and onStateChange - preferred, nicest and probably what you are looking for,
location.hash and onhashchange - probably easier to implement (does not require you to support it on server side and works in older browsers too), but in this case you would get URL like http://eataustineat.com/#!claypit instead of http://eataustineat.com/claypit.
In this first case you would need to make sure server side scripting / configuration will invoke proper state within JS, when visited eg. by entering URL (http://eataustineat.com/claypit).