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.
Related
OK - Thanks for taking the time!
I am using WP on a CentOS 6 server. I have a plug in with the functions, I have a function that makes a DB call and populates relevant products based on $_GET variables, I took from one of the other project and modify it so it works! But here where I run in to the problem, I go to the main page and i have a function that gets called first, goes through the URL name and determines the categories id and then from that I need to pass that to the URL so that when the next function then calls $_GET["category_id"] and that ID is there and ready to be use and it it does its magic. (all staying on the same page no refreshing or anything)
So I need to put that on the URL as the page is being loaded and so that I can use it (Again i get the variables from a function that is doing all the work with the address for relevant info,) So how do i do it? HTML or PHP, and a straight forward way no extra installs would be nice :)
Edit 1:
So is there something then I could integrate in that would be simple and straight forward that would allow me to do a mini refresh and get the right variables in place, never used JavaScript but seams to be getting or something in php ... Ideas are welcome :)
You can with javascript and the history API
The only way you can change the url without actually redirecting the user is by using the pushState method.
e.g. open a console and copy and paste this:
var stateObj = { foo: "bar" };
history.pushState(stateObj, "changes url to stackoverflow.com/yes-you-can", "/yes-you-can");
You won't be redirected, and the url of your browser will change unless, basically, you're using IE 9 or less. You can see a demo of this on html5demos.com
OK here is how I am going to get around this problem I am having
I made a new table in the DB and then I already have a list of the Domain We are using, so then I am going to give to the customer there are three columns and they will manually enter the fields and it will be on them to manage and change what they want displayed on the webpage.
CVS import and then BAM! done! just pull $_SERVER["SERVER_NAME"] and then compare that to the domain column and done! (I will have what ever cat's and sizes they want and it will not be on us to create any complicated functions and if statements for exceptions and it is in there hands!)
Not the exact answer I wanted to get but much easier and not so much complicated :)
I didn't know how to ask professional so if topic is wrong, please correct it.
My problem is quite complicated. I was training on symfony webpage how to generate form and then send this data to another page.
But now i would like do something different. I would like create page xyzSuccess.php.
Then generate 29 links on this page. Each links would have its own number.
Each link would redirect to the same page. For example numberSuccess.php. After that, this site would give me data of the number which i clicked.
I will show the example :)
Page xyzSuccess.php have links, the third one is http://localhost:8080/web/number?nr=3
I click on it and i go to numberSuccess.php, the page give me number 3
After the page got number, also take from any datafile information under that number 3 ( i don't know, maybe any file wchich can store symfony / array somewhere?.)
I dont know how to do this, i don't want use any database eq. *sql
So far i created only page xyz.php which use php for loop. I see that action.class.php would work with it if i would use submit button, but i really dont have any idea how make this working with links. And... that problem with storing data :( maybe create file in lib/form ?
corrected the link to page (deleted success which used only in templates), guy under is right :)
First of all, you're talking about URL's like /web/numberSuccess... That probably means you've misconfigured the root. Also see this question, asked today.
Then it's common to give your actions names like number, and then in you're actions file you have the executeNumber action, which then renders the numberSuccess template. So you shouldn't include the Success in the action name/URL.
Then, your question:
What I would do, if you don't want to use a database:
Create a file links.txt in your /data directory, and on every line create an url, followed by a space and then the title of your link.
In your list action open the this file using file_get_contents(), explode it on the newline-character, and assign this array to the view.
In your view loop through the array, use the array index as your number, and explode each item on the first space, so you can display the title.
In the view action your open and explode the links file again, and now you can pointer directly to the index, explode again and you have the URL.
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).
I have searched online for this issue, but the results are mostly based around Excel.
I have a webpage that has a list of videos. Every time someone clicks on a link, they are taken to a separate page where they can view a video. I have a table in my mysql database that links video id to views. I would like to increment the views column every time someone clicks on the link.
I know how to do this on the database side, but I am trying to figure out how to trigger the DB operation via PHP. I thought about having a script at the top of the page that calls the stored procedure to update the tally everytime the page is loaded, but the problem with this is that the video doesn't start automatic ally when the page loads. Users have to manually click on "play".
Why not write an Update query on the table which gets called everytime a link is clicked?
It is a little confusing where you want to increment the counter. You give three situations:
When a user clicks a link to a particular video's page
When a user loads a particular video's page
When a user clicks play on a video
1 & 2 wouldn't give an accurate count of those who actually watched the video, so I'll choose that you meant 3.
It depends on your video player then. If the player has a way to hook a javascript function to the start of a video, then you can use that to make an ajax request back to a server page that updates your database. If the player has no hooks then you're limited to on page load, which will be less reliable.
Does this help? If I miss understood the question, please clarify by updating the question or adding comments. PS. adding code of what you've tried goes a long away as well.
Further to my question yesterday (here), I am working on a webpage that has a section that shows 'live' order details.
The top half of my webpage has Spry Tabbed Panels. One of the panels contains an include call to a separate php page that I have created (getOpenOrders.php). This contains an SQL query to obtain all open orders and then puts the details into a table.
As a result, the table of open orders is shown in the Spry panel. What steps do I now need to take to have this refresh every 15 seconds?
Do you really want to call the database every 15 seconds for each user? isn't that an overload?
I'm not saying that your database will be overloaded, but, thats how you shouldn't do things!
Edited
you should show an image, or the link to that page in order to gt an appropriate answer, because it all depends in what are you doing in the table.
because I don't know, I will give you an answer on what probably is happening.
Because you said that you're new to the ajax world, let's make things simple, and not to complicate on the you should return a JSON object and use it to re populate your table. :)
So we will start with 2 buttons (Previous and Next) so the user can move the data that is showing (you probably don't want to give him/her 100 lines to see right?)
let's say that you have 2 pages, a showData.php and getTable.php, in the showData.php you will need to load jQuery (wonderful for this) and add a little code, but where the table is to be placed, just add a div tag with an id="myTable" because we will get the data from the getTable.php file.
getTable.php file has to output only the table html code with all the data in, without no html, body, etc... the idea is to add inside the div called myTable all the code generated by getTable.php
Let's imagine that getTable.php gets a page variable in the queryString, that will tell what page you should show (to use LIMIT in your MySQL or PostgreSQL database)
You can use jQuery plugin called datatables witch is one of my choices, check his example and how small code you need to write! just using jQuery and Datatables plugin.
The first description follows the jQuery.Load() to load the getTable.php and add as a child of the div and wold do this for the previous and next buttons, passing a querystring with the page that the user requested. It's to simple and you can see the website for that, if you prefer to use the DataTables plugin, then just follow their examples :)
if you, after all this need help, drop me a line.
<META HTTP-EQUIV=Refresh CONTENT="15; URL=<?php print $PHP_SELF ?>">
This should be in between the head tags.
-or-
header('Refresh: 15');
This should be before the head tag and directly after the html tag.
As said by balexandre, a different method should be used. One that does not require a database hit every 15 seconds for every single user that is connected to the site. But, there is your answer anyways.
Although, balexandre makes a very good point, if you do decide that you need a refresh, you could simply do something like this in your JavaScript:
window.onload = function( )
{
setTimeout( 'window.location.refresh( )', 1500 );
}
(I've not tested the above code, so syntax may need to be tweaked a little, but you get the idea)