Update a record with a single click - php

I am working on a CMS for a website using PHP and MySQL and have been asked if it is possible to 'publish' articles just by clicking on a button?
To make things clear, the articles may have already been entered into the database but not identified as being ready for publication. Articles for the site have a column in the db called _'pub'_, which is an ENUM('n','y'). I have created a page which lists all articles by section, article heading, date and published.
If _'pub'_ is 'y', published displays YES, otherwise it displays NO
I have created an additional page that changes the state of _'pub'_ so that it works by clicking on the Yes or No for published, but wondered if there was a way of changing the status of _'pub'_ using javascript rather than an additional page.
I look forward to hearing any suggestions

Just use jquery like this
$.post("/submit.php","title='Title of post'&content='PostContent'", function(d){
$(".output").html(d);
});
What that basically does is, sends the content to submit.php with ($_POST['title'] and $_POST['content']).. and then returns the output in a div with the classname output
And everything happens with a single click on the same page

You want the users to stay on same page, is that it?
Use ajax/jQ to:
submit articleid that should be published
on request-completion, change image/text in list from "no" to "yes"
http://net.tutsplus.com/tutorials/javascript-ajax/5-ways-to-make-ajax-calls-with-jquery/
is a good start.
regards,
//t

Related

Creating unique pages of a website by passing an sql key

The title may be a bit awful as I'm really not sure how to describe what I'm trying to achieve without using lots of words.
I'm currently building an events website. This website has the option for users to create their own events which can be added to a big list of upcoming events that other users have submitted.
What I want to do is be able to have a user create an event and have the details of the event stored in an SQL database (which I've successfully done), I want to be able to then have a large list of events on a separate page the details of which are pulled from the server dynamically using PHP and SQL (I've also successfully done this). The part I am struggling with however is being able to create unique pages (or a single dynamic page) that displays a more detailed look at the event, such as age restrictions etc etc, which cannot be displayed on the big list which displays all the available events.
I figured that this could be done using a unique eventID, which is something the SQL database already includes and autoincrements with each new event entry. What I'm really not sure about is how I'd be able to pass that eventID through the link to the more detailed page so that the detailed page can be created displaying all of the details of the event.
I'm not even sure if this idea will work at all. Would having a page with a unique URL that is created on event submission that has a more in-depth look at the details of the event be a better idea? How would I go about creating unique URL webpages that correspond to each event on event submission?
I'm really not sure how I need to go about this at all, so I need some help and pointing in the right direction.
Here's a kind of TLDR:
1) Events website
2) All events on the website are displayed on a single page that has minimal detail about each event (title, date, location) BUT has a link to a page that displays the event in more detail.
3) User can select an event from the list and click on that event's unique HTML link to more detailed page
4) More detailed page displays event in more detail by pulling event's unique information from the database
Feel free to ask any questions at all as I know this probably isn't the easiest idea to get across
When creating the links from the general listing page to the detail page, simply include the id in the link. For example:
<A HREF="mysite.com/detail.php?id=3>Big Event</A>
In detail.php then, you'll find the id in $_GET['id'].

mysql stuff when click on link then go to link

I have a phpBB forum, some posts contains Links... I want to count how many times the link on the post has been visited...
I think that catching the "click" on the link, make php and mysql stuff and, then after all, go to the external link is the best way ... but I dont know how to do that.
Its possible to interrupt the link click, modify some things and then load de link as always? (maybe using ajax or jquery)
A link example could be:
www.google.com
The mysql table called phpbb_likes contains:
Like_id
Post_id
User_id
Like_time
I know how to add a new like using something like this:
Insert INTO phpbb_likes ("Post_id","User_id","Like_time") VALUES ("2355","45","1343546456");
But the problem is interrupting the link redirecting to make that sql query
Any Idea?
thanks

Building a slider for all posts

In the header of my website, I have a horizontal list of the 6 latest posts. Now I would like to add a "previous" button, which causes the content of this list to be replaced by the 6 posts before the ones that are currently displayed. The idea is that, if a user clicks "previous" often enough, he is able to thereby see all posts ever made.
Most of the tutorials for creating this always load ALL posts, and then simply stuff them into some jQuery-slider. However, since I have 100+ posts, this seems not the best approach (some users might actually never click "previous" at all so why waste resources loading them).
Could you please point me to a tutorial that explains how I can get the previous posts using php each time the "previous" button is clicked? (I'm using Wordpress btw)
The problem was solved without any tutorial, just with the help of a few stackoverflow threads. Now I have an awesome Post-Slider :)
If you rely on php for that, you'll need to refresh the page each time. I think you really want an AJAX solution.
You can build a PHP web service that
1) accepts some variable, such as the ID of the lowest post currently displayed
2) outputs XML or JSON of the six posts prior to that
Then, on your page, onclick of your previous button, send the variable, accept the response, and place each post as needed. .ajax and .load are some jQuery methods to look into

Display search result page on back

I am developing a website in php (I am using codeigniter). On search by user I need to display list of products. Search result should give small description about the each product. Once the user clicks on more anchor I need to give full description about the product. Once user clicks back I need to be back to the search result page. I have used pagination. Any suggestion on how to carry out this task. Thanks in advance.
Indeed, this sounds like a job for our good friend Javascript. But not that much - simple history trick would be sufficient in my opinion. Resource:
http://www.javascriptkit.com/jsref/history.shtml
Example:
Go back 3 pages
This sounds like a job for our good friend Javascript. You could do this with a modal window that retrieves a page (such as /product/id/full_description) and displays the full description.
There are many modal window scripts out there that can do this. I am using jQuery and one called SimpleModal (http://www.ericmmartin.com/projects/simplemodal/) and it works well. I am using this since I am already using jQuery for many other things.
Here are some other examples:
http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/dhtmlmodal.htm
http://okonet.ru/projects/modalbox/index.html
http://www.huddletogether.com/projects/lightbox2/
http://orangoo.com/labs/GreyBox/
http://jquery.com/demo/thickbox/

Refresh Using Ajax/PHP

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)

Categories