Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Oct 2008
    Location
    Poland
    Posts
    382
    Thanks
    150
    Thanked 2 Times in 2 Posts

    How to create a long Select (menu/list) form taking data from CSV or XML?

    Hello,

    in my blog I'd like to create a long Select form. Something like this:


    It will have hundreds of items. Upon selection a new link will open. Every item will be a different link. Normal html page. Static content, no PHP needed.

    Is it possible to upload a .csv file or XML file to the server and then code the HTML in some way that will read those files in the following way?

    • Column 1: menu item name
    • Column 2: http link


    In this way I could easily add new menu items to the list just editing the file with Excel. No need to edit manually a very long HTML list.

    How can I do that?

  • #2
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,209
    Thanks
    7
    Thanked 268 Times in 267 Posts
    Sure, if you know PHP you could either use fgetcsv to parse a csv file, or SimpleXML to parse an XML file. Then just loop through and create your list of menu items.

    Dave

  • Users who have thanked tracknut for this post:

    utnalove (07-28-2013)

  • #3
    Regular Coder
    Join Date
    Oct 2008
    Location
    Poland
    Posts
    382
    Thanks
    150
    Thanked 2 Times in 2 Posts
    Hm, I don't know PHP, I thought it could be done without using it.
    Hmm... maybe you can suggest some sites that explain it step by step? I think I can use PHP even if I don't understand it

  • #4
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,209
    Thanks
    7
    Thanked 268 Times in 267 Posts
    What language did you have in mind? You can't do it in html, if that was the question.

    For php help, you could search for fgetcsv and simplexml at php.net, and they will have examples of using them.

    Dave

  • Users who have thanked tracknut for this post:

    utnalove (07-28-2013)

  • #5
    Regular Coder
    Join Date
    Oct 2008
    Location
    Poland
    Posts
    382
    Thanks
    150
    Thanked 2 Times in 2 Posts
    I thought it was possible with some javascript.
    Ok, I'll take a look at php.net

    Thanks

  • #6
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,209
    Thanks
    7
    Thanked 268 Times in 267 Posts
    Quote Originally Posted by utnalove View Post
    I thought it was possible with some javascript.
    It is, I just didn't know that's what you were looking for. I'll let someone else answer re. JS, since I'm no expert in it.

    Dave

  • #7
    Regular Coder
    Join Date
    Oct 2008
    Location
    Poland
    Posts
    382
    Thanks
    150
    Thanked 2 Times in 2 Posts
    I don't know JS as well... to be sincere from 0 to 10 I understand PHP 1 and JS 0

    In php.net I didn't find anything understandable. But I found this one: http://www.claromentis.com/wiki/help..._list_from_csv

    It's ready code, but still not complete. I don't see the HTML part that would be in the front end. And I don't see what happens with the other columns of the CSV.

    In my case column 2 should be the URL which the text from column 1 will be linked to.

  • #8
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,903
    Thanks
    15
    Thanked 226 Times in 226 Posts
    It will be simpler with php. You can include static pages as a plain text file.
    PHP Code:
    <?php
    include "../Files/select_menu.txt";
    ?>
    Just that hard to do. It will be written verbatim to the page. And you can make conditional statements, just like in JS, which will allow you to choose what is included.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • #9
    Regular Coder hdewantara's Avatar
    Join Date
    Aug 2009
    Location
    Jakarta, Indonesia.
    Posts
    346
    Thanks
    9
    Thanked 51 Times in 50 Posts
    If the .CSV looks like this:
    Code:
    Alaska - Anchorage,http://www.weather.com/weather/today/Anchorage+AK+USAK0012
    California - Los Angeles,http://www.weather.com/weather/local/USCA0638
    Florida - Miami,http://www.weather.com/weather/local/USFL0316
    Hawaii - Honolulu,http://www.weather.com/weather/local/USHI0026
    THen I think you may load that as TEXT with an AJAX?
    Load it into a buffer, split it into lines, and then each lines into <OPTION>'s value and text...

    Hendra


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •