Jump to content

Trying to build a playlist


Dustin013

Recommended Posts

I have built a simple playlist using PHP and mySQL database. I am trying to add some ajax functionality into the page. What I would like to do is when a user clicks the "add" button the item is sent over to another div containing the contents of the playlist.

 

I am still in the process of learning and I know this board is for PHP but since I am working with PHP I am posting here.

 

What I really need is some reading material.

 

So as of now when a user clicks the "add to playlist" option, the information gets sent to the database and then the user can browse to the playlist.php file and view their playlist. Instead of having to browse to the playlist.php page I would like that information sent to a div on the main page.

 

I can load a page into a div no problems but again its not so interactive. Basically the div doesn't get refreshed when the user clicks add to playlist. Maybe if I added a javascript command that told that div to reload whenever a new item to the playlist?

 

Also, currently when the user clicks "add to playlist" it calls up a php file and the browser is directed there. With PHP is there a way to tell the script to load but not actually go to that page?

 

The reason is it going to the next page is because I am using a <a href="playlist.php?blah=123&blah2=123">Click to add</a>...

 

Anyhow guys, i know it isn't the best series of questions and a little broad, but if anyone would link me some reading information that would help me out a lot :-)

 

Thanks

 

Link to comment
Share on other sites

U cant make a link that sends an url, stop execution while in the back end the script still works...only with php. What would be the purpose of ajax then. From what i can understand, u need a button on a song title which adds that song to the user's playlist. Basically that link will call a javascript function by passing a songid parameter, where the function itself will run asynchronously another script which updates the database, and finally update the playlist div's content. That shouldnt be difficult. I'm not an javascript coder, but recently ive used the prototype framework (together with scriptaculous) to ajaxify some parts of a website. I suggest u to take a look at the prototype site, where it has some nice and simple examples on doing ajax requests. U should have the work done very easily.

Link to comment
Share on other sites

Yes, you need to use AJAX. There are many tutorials on the net for using AJAX. I suggest you find a javascript AJAX class so you don't have to worry about all the issues in initiating and making the actual request.

 

Here is an example of how the process could work:

 

1. The button/link to add a song would call a javascript "addSong" function, passing the ID of that song to the function.

2. The "addSong" function would take that ID and make an AJAX call to a PHP page (e.g. "addToPlaylist.php")

3. The PHP page would take the ID passed to it and add the song to the playlist in the database

4. The PHP page would then do a query to get the entire playlist and format it for display in the div and pass back that code to the javascript function (anything the PHP echo's to the page is passed back to the AJAX call).

5. When Javascript receives the formatted HTML from the AJAX call it populates it into the div using innerHTML.

 

Hope that helps get you started.

Link to comment
Share on other sites

No offense, but I would disagree. Your comment was of value, yet it lacked clarity. For example:

Basically that link will call a javascript function by passing a songid parameter, where the function itself will run asynchronously another script which updates the database

You startt the sentence talking about a javascript function and then transition to "another script" without explaining that the other script would be a PHP, or other srver-side, script. That would easily cause confusion in my opinion. I tried to break it down into a logical flow for the OP.

 

Also, I didn't denigrate the English language.

 

U != You

 

Link to comment
Share on other sites

Also, I didn't denigrate the English language.

 

u just wrote "startt"  ???. Dont have any other constructive comment? U, ur, mate, l8, brb, and stuff like that are just shortcuts which can be esily humanly decrypted. Where is your problem with that?

 

I explained that the javascript will run asynchronously another script which updates the database. Would a javascript code update the database by itself? Definitely no so where's the confusion? Even though, if u thinked my post lacked clarity, u could have wrote: "adding to the above post" or smth like that.

 

Closing discussion as there's no more to talk about.

Link to comment
Share on other sites

A bit testy aren't you?

 

I thought I did give some constructive comments. However, you seem to post comments based upon assertions you believe to be "facts" which are not.

 

Would a javascript code update the database by itself?

Well, in fact, you can access a database with Javascript.

http://ajaxian.com/archives/server-side-javascript-databases-access

 

I prefer to not make assumptions as to someone's level of expertise or knowledge.

 

Even though, if u you thinked thought my post lacked clarity, u you could have wrote written: "adding to the above post" or smth something like that.

Didn't the first line of my post state "Yes, you need to use AJAX" - I thought I was agreeing with you. yes I made a spelling error, but it was not intentional. And "text speak", in my opinion, is polluting our communication.

 

Closing discussion as there's no more to talk about.

Really?

Link to comment
Share on other sites

My comment wasn't an assumption. What Jaxer promises to offer for SQLite isn't much and I would better go for a JavaScript function which passes queries to a PHP script. The support isn't native and you know that. Posting some random stuff you find on Google doesn't make you smart. Anyway I'm not a JavaScript expert so it's beyond my expertise to debate on this theme.

 

Just to let you know, in Albania we don't speak English on a daily basis. Even if we did, what's the point of correcting what i write? Are you trying to prove something? Probably you know English better then me and can write it more correctly, but still I can't seem to find the whole point!

 

Initially I didn't want to make that post, as I guessed this could happen. That's why I included the "without offense" part, so you could take it more easily. Anyway, my intention isn't to start a totally non constructive debate, one very far from the purpose of this forum.

 

So cheers and let's put down these stupid things :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.