0

I searched for this answer and on Google and found nothing that is what I need done for my client so here I am askin y'all for some help!

Simply put, my client wants to enter in data into a form on a blog entry that in turn, when submitted, simultaneously populates a list on a different page on his site. That page will just be a list that says (for example) name, release date, rating, how many times sampled (in this case, if the item was entered for multiple blog entries, then the list would reflect how many times it was entered in total), and which member suggested it.

I know I will be using a blog plug in to create the form, but I am not sure WHICH plugin will best suit this tast. I know I will be using PHP to send the data where I want it sent, but I have only used PHP to send data to emails, and never before to send it to a live list.

So which plugin? Any one?

How do I direct the PHP to display live page data without having up reupload a page every time the user wants the new data displayed?

Sorry if these are dumb questions but this is new to me. Please help me learn!

Thank you!

Jonnny
  • 4,939
  • 11
  • 63
  • 93
Naomi
  • 7
  • 4
  • So you are saving the data from the form in a Database, then showing a 'list' page with the results of the form? You talk of a plugin? What platform are you using or what plugins are you thinking of using? You can use `header()` to redirect also. – Jonnny Jul 28 '13 at 19:22
  • @Jonnny "So you are saving the data from the form in a Database, then showing a 'list' page with the results of the form?" Yes, exactly. "What platform are you using or what plugins are you thinking of using?" I will be using Wordpress for the blog, and I was thinking of using Easy Table, but I am open to use any plugin that will work best. – Naomi Jul 28 '13 at 19:29
  • http://wordpress.stackexchange.com/ may be a good place for this. Much as I suspect someone could answer it here also – Jonnny Jul 28 '13 at 19:40
  • @Naomi To further a suggestion, in order to *"to display live page data without having up reupload a page every time"*, you would need to use a mix of jQuery and Ajax. I'm not a pro at Ajax, but I can get by at using/modifying existing scripts which will do just what you're looking for. In order to *"populate a list on a different page on his site"*, the basic concept is to write to a file or files at the same time and `include()` them, or use `file_get_contents()`. I hope this serves you. – Funk Forty Niner Jul 28 '13 at 19:42
  • Thank you for that link and reply @Jonnny. I had no idea that branch of this site existed. It will prove to be very useful for me I'm sure! – Naomi Jul 28 '13 at 21:21
  • @Naomi No problem, someone on here told me a while ago and it was really helpful to me. – Jonnny Jul 28 '13 at 21:22

1 Answers1

0

Make this file get_list.php:

<?php

$sql = mysql_query("SELECT * FROM list_table LIMIT 15")
if (!$sql || mysql_num_rows($sql)==0)
    exit("There are no list items");

while ($item = mysql_fetch_array($sql)) {
    echo "<li> format it here";
    echo $item['name'];
    echo "</li>"
}


?>

And in your main file:

<ul class="list">
    <li>Blabla 1</li>
    <li>Blabla 2</li>
</ul>

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>

    function updateList() {
        $('.list').load('get_list.php', function (data, status) {
            if (status) return alert('Error updating the list');
            setTimeout(updateList, 2000);
        });
    }
    updateList();

</script>

...and your list will be updated every two seconds.

Good luck!!

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Leonard Pauli
  • 2,662
  • 1
  • 23
  • 23
  • Thank you @Fred !! This is a great place for me to start. I will try and modify this code to suit my needs. – Naomi Jul 28 '13 at 21:21
  • @Naomi And you can also thank `Leonard`, it's his answer ;-) cheers – Funk Forty Niner Jul 28 '13 at 21:24
  • Thank you @LeonardPauli! I greatly appreciate you taking the time to help me figure this out!! – Naomi Jul 29 '13 at 03:40
  • @LeonardPauli Instead of a generic list, is there a way to add the exact form data to a secondary live master tabular list that contains all entry data from previous entries though? My client will enter the data via a blog form plugin which will display on the blog entry as a table. I want to have that data mirrored exactly, and added to a list. I need the master file to look like the sortable table on this page: [link](http://www.kryogenix.org/code/browser/sorttable/) – Naomi Aug 01 '13 at 03:16
  • Change the code around "format it here" to create th, tr and td tags with the right data, and replace that ul tag with a table tag. Now, to make it sortable, use that plugin you linked to and in the end in the .load function, call sorttable.makeSortable(this);sorttable.innerSortFunction.apply(/* the th dom object that had the class sorttable_sorted before .load was called to preserve the sort order every two seconds */, []); – Leonard Pauli Aug 01 '13 at 10:30
  • @LeonardPauli You are a Saint! Thank you so much! I will post a link once the site goes live, if you care to see the outcome of your generosity and time. Thank you again. You help is just enough to give me directions but still allows me to figure things out for myself, without being overwhelmed. That is a wonderful way to teach someone code! – Naomi Aug 02 '13 at 01:07