As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread: https://forums.penny-arcade.com/discussion/240191/forum-advertisement-faq-and-reports-thread/
We're funding a new Acquisitions Incorporated series on Kickstarter right now! Check it out at https://www.kickstarter.com/projects/pennyarcade/acquisitions-incorporated-the-series-2

PA Programming Thread - The Best Servers Are The Ones You Don't Use

1444547495063

Posts

  • bowenbowen How you doin'? Registered User regular
    edited February 2011
    This is all true. That's what I get for being especially lazy while writing an example.

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • PhyphorPhyphor Building Planet Busters Tasting FruitRegistered User regular
    edited February 2011
    Papillon wrote: »
    Phyphor wrote: »
    Well, you get to smash the stack due to name being placed after input :P

    The order of the variables isn't the main problem. The main problem is that he's writing name (which could be up to 75 characters long) into an array which is only 50 characters long. Either increase the size of name, or use sscanf(input, "%50s %u", name, &age).

    You should be checking if the return from sscanf() is equal to the number of fields parsed. I.e. sscanf("%50s %u", name, &age) == 2.

    I also like to add an extra space around my format string so it will gobble leading and trailing whitespace:
    sscanf(input, " %50s %u ", name, &age) == 2.

    Finally, this will still match inputs with extra garbage at the end. You can fail if there's extra garbage by comparing the length of the matched string with the length of the entire string: sscanf(input, " %50s %u %n", name, &age, &len) == 2 && len == strlen(input)

    Well, if it appeared before then it would just overwrite the start of the input string, which is still bad, but not quite as bad.

    Phyphor on
  • bowenbowen How you doin'? Registered User regular
    edited February 2011
    So uh, let's say I have this $2000 server doing absolutely nothing. Let's also say I have git repo on a server. Is there anyway to using this server to make builds based off that git repo whenever there's a change? I'd need a windows and linux executable, if that helps, so I'm assuming cmake of some sort.

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • FodderFodder Registered User regular
    edited February 2011
    You might look into Jenkins. It can run arbitrary scripts based on triggers like a git commit/push.

    Fodder on
    steam_sig.png
  • JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited February 2011
    I have a semi-interesting database design question.

    I'm working on creating a WebDAV emulator with Django.

    Django will store information on files and folders in SQL (actual file data stored on a filesystem, not in SQL itself) and handle WebDAV protocol requests.

    The area where I am getting fuzzy in this design is how to handle folders. There's no folder programming interface, so everything is represented by strings. I feel like I do in fact need an actual Folder object in Django because I have to serve information on specific folders al a carte. So the issue comes with storing the file and folder path information.

    I'm basing my work off of a WebDAV emulator written for Google App Engines where every file and folder entity in SQL is stored with a full path (therefore if a file has two parent folders, the file path field is written '/parent1/parent2/file.png'). I'm not crazy about this because I then have to babysit the value of the path field during move operations. Moving a folder with 1000 files means I need to do 1000 row updates to update the path value.

    On the flipside, I could just store the normalized path representation of the single entity (a.k.a. the file or folder name) and reconstruct full paths recursively during runtime. This also could potentially suck because if I have a file with 10 parents then that seems to me like one hell of a query because I would need all 10 parent path fields to reconstruct the path.

    My brain is telling me that the second option is ultimately better. I can probably figure out how to make that kind of query at least tolerable. I'm not so crazy about having to deal with an unknown number of row updates per move. That is so exploitable.

    Short of that, I am looking for other ideas on how to implement a WebDAV service that interfaces with the authentication module of a proper HTTP web framework. A big reason I need these entities in a database is for complex authentication. Folder level authentication and file level permissions to multiple users and the like.

    WebDAV isn't exactly as pervasive as Rails so there's not much written on this subject, so I'm cobbling together my knowledge from a very few people who've taken the subject to open source.


    *edit*

    This for example might be far less egregious than trying to mock a WebDAV filesystem with SQL and Django

    http://stackoverflow.com/questions/700480/control-access-to-webdav-apache-using-python

    Although this doesn't really account for the type of folder-specific authentication that I need.

    Jasconius on
  • ASimPersonASimPerson Cold... and hard.Registered User regular
    edited February 2011
    Papillon wrote: »
    Phyphor wrote: »
    Well, you get to smash the stack due to name being placed after input :P

    The order of the variables isn't the main problem. The main problem is that he's writing name (which could be up to 75 characters long) into an array which is only 50 characters long. Either increase the size of name, or use sscanf(input, "%50s %u", name, &age).

    You should be checking if the return from sscanf() is equal to the number of fields parsed. I.e. sscanf("%50s %u", name, &age) == 2.

    I also like to add an extra space around my format string so it will gobble leading and trailing whitespace:
    sscanf(input, " %50s %u ", name, &age) == 2.

    Finally, this will still match inputs with extra garbage at the end. You can fail if there's extra garbage by comparing the length of the matched string with the length of the entire string: sscanf(input, " %50s %u %n", name, &age, &len) == 2 && len == strlen(input)

    Yeah, when I did C in college it was all fgets, all the time. I don't think we even used scanf(), but as my original response indicated, we weren't big on this interactivity stuff. (I mean, after all, if you want to write user interfaces that's what HCI is for, isn't it? ;-) )

    ASimPerson on
  • Jimmy KingJimmy King Registered User regular
    edited February 2011
    I really, really hate people who write code that is critical to our system and then don't put it in version control. This is really making my current work setting up our platform on new servers so that we can sell off the old servers a total nightmare. All the important stuff seems to work now, but there's lots of stupid little crap.

    Jimmy King on
  • EtheaEthea Registered User regular
    edited February 2011
    bowen wrote: »
    So uh, let's say I have this $2000 server doing absolutely nothing. Let's also say I have git repo on a server. Is there anyway to using this server to make builds based off that git repo whenever there's a change? I'd need a windows and linux executable, if that helps, so I'm assuming cmake of some sort.

    Why yes you can do it with [email protected]. The other option is to write a shell script that checks every X minutes for new updates, which was how we did/do things before [email protected]

    Edit:
    If you are interested in the shells scripts we use, I can show you where to look. But most of them are fairly project/os specific.

    Ethea on
  • bowenbowen How you doin'? Registered User regular
    edited February 2011
    Damnit Ethea, why do you make me love you?

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • DVGDVG No. 1 Honor Student Nether Institute, Evil AcademyRegistered User regular
    edited February 2011
    So I'm making a simple iOS game (nothing graphical, using normal UI controls).

    I've got a Core Data database with models of Characters and Monsters, which have game statistics tied to them.

    When an encounter is created, the encounter just holds a relationship to the individual Characters in the persistent store that are selected for that encounter. However, for the monsters, I want to be able to have several copies of a generic monster for the characters to fight. (5 Orcs, for example).

    Because of this, i can't just have a relationship handle it like I can for characters, because if I, deal damage, for instance, to a monster, all 5 orcs will take the damage, and that's not what we're looking for.

    So how do I handle managing multiple copies of a baseline monster and still be able to interact with them individually? I feel like this is one of those things where i know the answer but i just can't think of it for some reason.

    DVG on
    Diablo 3 - DVG#1857
  • JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited February 2011
    your monster entity should contain your encounter foreign key, not the other way around.

    *edit*

    also core data sucks

    Jasconius on
  • DVGDVG No. 1 Honor Student Nether Institute, Evil AcademyRegistered User regular
    edited February 2011
    Okay, I think I figured it out actually.

    I can make another model (Called EncounterStats in my mind) which holds a relationship to a Monster or Character, and their non-static statistics like currentHP, and refers to the baseline character for static stats like maximumHP.

    DVG on
    Diablo 3 - DVG#1857
  • JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited February 2011
    That would certainly work but that sounds like a roundabout way of achieving it.

    You might want to provide to visualization for how you're hauling all your data around.

    Jasconius on
  • DVGDVG No. 1 Honor Student Nether Institute, Evil AcademyRegistered User regular
    edited February 2011
    Right now it's 3 View Controllers. Characters, Monsters and Encounters. Characters and Encounters is the only thing that does anything now, and I'm using temporary quick-and-dirty view controllers to add data into those lists.
    Character
      name:string
      maximumHP:int32
      has_many encounters
    
    Encounter
      name:string //e.g. "Bar Fight"
      has_many characters
    

    I was thinking ahead this morning about monsters, and how there will be several generic monsters in a given encounter.

    So now I've evolved to this:
    Character
      name:string
      maximumHP:int32
      has_one type
      has_many encounters
    
    Type
      name //eg "Monster" or "Character"
      belongs_to character
    
    CharacterStatus
      currentHP:int32
      has_one character
      belongs_to encounter
    
    Encounter
      name:string //e.g. "Bar Fight"
      has_many characterStatus
    

    That's more or less a rough draft. The whole goal is to be able to get a a UITableView that looks like
    Player: Ramza Beoulve
    Player: Delita Hiral
    Monster: Orc 1
    Monster: Orc 2
    Monster: Orc 3
    

    While only having "Orc" be a single row in the database.

    DVG on
    Diablo 3 - DVG#1857
  • JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited February 2011
    Am I correct in assessing that your actual monster templates are stored in Core Data?

    If that is correct then I would say that's probably your biggest problem. That's the kind of stuff you'd configure in the initialization cycle of an object.

    Jasconius on
  • DVGDVG No. 1 Honor Student Nether Institute, Evil AcademyRegistered User regular
    edited February 2011
    Jasconius wrote: »
    Am I correct in assessing that your actual monster templates are stored in Core Data?

    If that is correct then I would say that's probably your biggest problem. That's the kind of stuff you'd configure in the initialization cycle of an object.

    Well, everything in this case is a user-created object. The user inputs the player characters and monsters, which are stored in Core Data.

    The user creates player characters and monsters, then creates an encounter, and selects the player characters participating and the monsters participating, then uses some controls to interact with those objects.

    DVG on
    Diablo 3 - DVG#1857
  • EvilMonkeyEvilMonkey Registered User regular
    edited February 2011
    EvilMonkey wrote: »
    Any WebSphere Portlet programmers in the thread?

    Shamelessly posting my stackoverflow question in hopes of more views.
    Suck it unfriendly IBM developers, I (sorta) fixed it without you!

    Once again thanks to all who upvoted me.

    EvilMonkey on
    [PSN: SciencePiggy] [Steam]
  • PapillonPapillon Registered User regular
    edited February 2011
    Is anyone here familiar with Rational Quantify?

    My problem is I'm trying to profile a program which launches a Java process. I don't want to profile the child process, just the parent. However, whenever I run my program in Quantify, it attempts to start profiling the Java process, reports that Quantify does not support Java, and kills the child. Everything I've found on the Internet is a few years old and indicates that by default quantify does not instrument child processes. Any idea on how I can stop Quantify from committing Java infanticide?

    All in Windows, by the way.

    Papillon on
  • JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited February 2011
    DVG wrote: »
    Right now it's 3 View Controllers. Characters, Monsters and Encounters. Characters and Encounters is the only thing that does anything now, and I'm using temporary quick-and-dirty view controllers to add data into those lists.
    Character
      name:string
      maximumHP:int32
      has_many encounters
    
    Encounter
      name:string //e.g. "Bar Fight"
      has_many characters
    

    I was thinking ahead this morning about monsters, and how there will be several generic monsters in a given encounter.

    So now I've evolved to this:
    Character
      name:string
      maximumHP:int32
      has_one type
      has_many encounters
    
    Type
      name //eg "Monster" or "Character"
      belongs_to character
    
    CharacterStatus
      currentHP:int32
      has_one character
      belongs_to encounter
    
    Encounter
      name:string //e.g. "Bar Fight"
      has_many characterStatus
    

    That's more or less a rough draft. The whole goal is to be able to get a a UITableView that looks like
    Player: Ramza Beoulve
    Player: Delita Hiral
    Monster: Orc 1
    Monster: Orc 2
    Monster: Orc 3
    

    While only having "Orc" be a single row in the database.

    I dunno mang.

    I will make the disclaimer than I am a vehement opponent of Core Data usage for most things, but it honestly sounds like you're kind of trying to make Core Data program for you, instead of programming for Core Data.

    So, without telling you to blow up your entire app..

    "Monsters" and "Monster Templates" need to be separate database entities. A "Monster" should take "Monster Template" in its constructor.

    This way you don't have to worry about weird ass quirks like hitting one monster and it impacting everything because they're all actually the same Core Data row.

    Jasconius on
  • SparserLogicSparserLogic Registered User regular
    edited February 2011
    Sorry to interrupt your discussion. I've actually never even been in this forum before, aside from asking about a phone I was considering buying a little while back.

    I'm a programmer/web developer by trade working in a small part of a big company and it has recently occurred to me that its shameful that I don't have my own website. If/when I ever want to change jobs I'll need something to show off my abilities. This mostly comes from interviewing a ton of candidates for a job and being miserably disappointed with both their skills and their examples.

    So does anyone know a good .Net capable web host? I've never even considered any of this before and I'd love to trust someone's opinion instead of the purchased adspace on google.

    SparserLogic on
  • JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited February 2011
    You don't *need* your own website. Plenty of good programmers, namely ones with shit to do, don't have websites, and still get jobs. I've never had one.

    As far as .NET... none that are cheap. .NET shared hosting usually comes in two varieties: cheap and shitty, or expensive and pretty decent.

    Jasconius on
  • SparserLogicSparserLogic Registered User regular
    edited February 2011
    Jasconius wrote: »
    You don't *need* your own website. Plenty of good programmers, namely ones with shit to do, don't have websites, and still get jobs. I've never had one.

    As far as .NET... none that are cheap. .NET shared hosting usually comes in two varieties: cheap and shitty, or expensive and pretty decent.

    You get what you pay for I suppose...

    In the short term shitty is probably going to do just fine. All I need is a DB and some bandwidth, it will mostly be for me to play around in.

    Yeah I understand its not a strict requirement, I'm just tired of wasting my time on video games and TV when I could be playing around more. There's a ton of things that I get the impulse to try out at work but can't justify putting into a corporate site (even an internal one). I'm a big fan of javascript widgets, for one thing, and I've encountered plenty of gaps in easily available open source ones so I may as well contribute a few to the ether.

    Edit: Oh, I forgot to ask, a friend pointed me to https://www.discountasp.net/ saying his company uses it. Seems pretty cheap, anyone used it before?

    SparserLogic on
  • JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited February 2011
    When I say shitty, I mean configuration nightmares, not necessarily performance shitty.

    As a .NET programmer I imagine you are aware of .NET's absolutely ridiculous configuration environment and how stupid IIS6 is (a lot of cheap hosts still use IIS6 when last I checked)

    I used three or four .NET hosts back when I did .NET and each one of them had their own unique nonsense to slice through.

    The best one I ever used was Mosso (now Rackspace Cloud) but I believe their service is something like $texas per month. But at least there you could file support tickets to get account specific IIS configuration done.

    If you use something on par with Godaddy or 1and1, you get what you get.



    If your primary objective is only to create a website to showcase your work, then there are ways of doing that that don't entail literally hosting and running your portfolio code for people to see. Employers will care more about seeing technique in source code than seeing "oh yeah, that DataGrid totally pages".

    Given that, there are about 1000000000 easier ways to host some sort of informational website/blog than using .NET

    Jasconius on
  • SparserLogicSparserLogic Registered User regular
    edited February 2011
    I'm not wedded to .Net, to be completely honest. If you know a decent LAMP host that is cheap yet awesome I'd probably take that as well.

    Anyways, thanks for the advice, I will keep looking around.

    SparserLogic on
  • bowenbowen How you doin'? Registered User regular
    edited February 2011
    Yeah stick to PHP. I don't have a website either, maybe I'll get one this year.

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • iTunesIsEviliTunesIsEvil Cornfield? Cornfield.Registered User regular
    edited February 2011
    Sparser, I'd just skip looking for an ASP host. Check out a nice LAMP hosting package. There are lots of inexpensive ones out there with good support. I'd personally recommend Dreamhost. They're who I'm with and I've been happy with them.

    ...

    I started going into what all they let you have on their base hosting plan (which I feel like is great) but I re-read it and I sound like a shill. So, check 'em out if you want, I think they're a good deal. :)

    [ed] Ok, so one thing about them that I was really happy about (which may be an over-reaction, but I've not had another host offer it) was subdomain redirection/forwarding. So I'm able to take my domain and point private.mydomain.com to my home IP; which I just think is the bee's knees.

    iTunesIsEvil on
  • Alistair HuttonAlistair Hutton Dr EdinburghRegistered User regular
    edited February 2011
    +1 Dreamhost is great.

    I am impressed at your self-restraint in not putting in refferal links there iTunesIsEvil.

    Alistair Hutton on
    I have a thoughtful and infrequently updated blog about games http://whatithinkaboutwhenithinkaboutgames.wordpress.com/

    I made a game, it has penguins in it. It's pay what you like on Gumroad.

    Currently Ebaying Nothing at all but I might do in the future.
  • iTunesIsEviliTunesIsEvil Cornfield? Cornfield.Registered User regular
    edited February 2011
    <.<
    >.>

    Wel, uh, Sparser, if you do sign up it looks like it'd be awesome if you shoved in my email address as someone that referred you during the sign-up process. grkaiser [at] gmail [period] com

    [ed] Actually, it looks like I can generate custom promo codes too, with things like a free domain registration for you or a free unique IP for you, if either of those would make Dreamhost more interesting.

    I'm a whooooooooooooooore and it's all Allistair's fault for pointing out that there is a referral system. :wink:

    iTunesIsEvil on
  • DVGDVG No. 1 Honor Student Nether Institute, Evil AcademyRegistered User regular
    edited February 2011
    Jasconius wrote: »
    I dunno mang.

    I will make the disclaimer than I am a vehement opponent of Core Data usage for most things, but it honestly sounds like you're kind of trying to make Core Data program for you, instead of programming for Core Data.

    So, without telling you to blow up your entire app..

    "Monsters" and "Monster Templates" need to be separate database entities. A "Monster" should take "Monster Template" in its constructor.

    This way you don't have to worry about weird ass quirks like hitting one monster and it impacting everything because they're all actually the same Core Data row.

    To be fair, I'm just doing this as a learning project. I see what your saying though, store the monster base stats as a monster template in the DB then insert the monster rows based on those templates when the encounter is created. That makes sense, thanks.

    DVG on
    Diablo 3 - DVG#1857
  • RSPRSP Registered User regular
    edited February 2011
    Maybe everybody else already knew this but John Carmack has a twitter.

    There are some gems in there.

    RSP on
  • bowenbowen How you doin'? Registered User regular
    edited February 2011
    http://www.barcodediscount.com/catalog/magtek/sureswipe.htm

    Anyone have any experience interfacing to one of those? I want to capture patient names from a swiped card (credit/debit) to help expedite check in and show account information. Maybe even do bill pay at the check in terminal if they want. I assume it will give first/last name and the card number/cv2 code the last two don't really matter to me until I do bill pay but the first/last would help people check in and out way faster. Am I assuming correctly?

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Smug DucklingSmug Duckling Registered User regular
    edited February 2011
    I personally use WebFaction. They support a bunch of different languages and static layouts, and also allow full SSH access to your machine, all the while charging like a virtual private server host. They're great.

    Smug Duckling on
    smugduckling,pc,days.png
  • JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited February 2011
    yup webfaction is pretty damn good

    Jasconius on
  • templewulftemplewulf The Team Chump USARegistered User regular
    edited February 2011
    Anyone know why I wouldn't be able to call a javascript function from the onclick event in an <a> tag?

    I'm using jQuery to navigate a page using javascript. In index.php, I have an AJAX request that loads the content of <div id="gameList">. That content has links in it which should load new content into the same div.

    That content has links which call a function defined in a .js file which is included at the top of index.php. Unfortunately, the function is never called, though if I change it to alert() the dialog box is launched correctly.

    index.php
    <script type="text/javascript" src="jquery-1.5.min.js"></script>
    <script type="text/javascript" src="gameregistrycontroller.js"></script>
    ...
    <div id="gameList"></div>
    

    gameregistrydisplay.php
    <tr>
    		<td><?php echo $game->id; ?></td>
    		<td><?php echo $game->title; ?></td>
    		<td><?php echo $game->status == 'gotit' ? 'Owned' : 'Wanted'; ?></td>
    		<td><?php echo $game->votes; ?></td>
    		<td><a class="voteLink" onclick="VoteClick();">Add Vote</a></td>
    	</tr>
    

    gameregistrycontroller.js
    function VoteClick()
    {
    	document.alert("vote!");
    }
    
    ...
    
    function OnReady()
    {
    	$.ajax({
    
             method: "get",
             url: "gameregistrydisplay.php",
             beforeSend: ShowLoadingMessage,
    		 error: ShowErrorMessage,
             success: DisplayContent
        });
    }
    
    $(document).ready( OnReady );
    

    Edit:

    Oh god damn it, I'm dumb. I didn't pass the handler correctly through AJAX, so to simplify testing I reduced the function to document.alert() which isn't actually a function! Changing it to just alert() and moving my $("#voteLink").click() statement fixed up everything.

    templewulf on
    Twitch.tv/FiercePunchStudios | PSN | Steam | Discord | SFV CFN: templewulf
  • templewulftemplewulf The Team Chump USARegistered User regular
    edited February 2011
    Well, now that I've recovered from my brief stupidity I have a best practices question.

    If I have a variable in a PHP file (e.g. $id), and I'm printing it to HTML as part of an AJAX request, what's the best way to package it into a link which will generate a new AJAX request?

    The path goes something like index.php -> AJAX fills div with links from display.php and adds a new AJAX call to their click events -> clicking links executes the AJAX call to vote.php, but vote.php needs the $id from display.php.

    I thought of using the id field in display.php to do something like <a id="game-<?php echo $id; ?>">, and then extract the ID from the string, but that seems kind of hacky. Any recommendations?

    templewulf on
    Twitch.tv/FiercePunchStudios | PSN | Steam | Discord | SFV CFN: templewulf
  • bowenbowen How you doin'? Registered User regular
    edited February 2011
    echo "<a id=\"game-{$id}\">"; ?

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • bowenbowen How you doin'? Registered User regular
    edited February 2011
    Pick whichever method you like, they both are roughly the same thing. There really isn't a less hacky way to do it, unfortunately, except I think:

    <a id="game-<?php=$id;?>">

    I don't think that works unless short tags are turned on, though, changing it to <?=$id;?>

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • InfidelInfidel Heretic Registered User regular
    edited February 2011
    Are you returning just HTML with your AJAX calls?

    You should consider script/JSON, since then you can do things right and separate your presentation from your logic/data. Your AJAX request should handle the data, your client-side JS and HTML should handle the presentation.

    You're asking for best practices after all. :^:

    If you need an example then just ask.

    Infidel on
    OrokosPA.png
  • templewulftemplewulf The Team Chump USARegistered User regular
    edited February 2011
    Infidel wrote: »
    Are you returning just HTML with your AJAX calls?

    You should consider script/JSON, since then you can do things right and separate your presentation from your logic/data. Your AJAX request should handle the data, your client-side JS and HTML should handle the presentation.

    You're asking for best practices after all. :^:

    If you need an example then just ask.

    I'm at my day job, and I have a hard time visualizing the code when I'm screaming inside. Do you have a link or anything I could look at?

    Edit:
    The bolded is exactly the kind of thing I'm trying to get at.

    templewulf on
    Twitch.tv/FiercePunchStudios | PSN | Steam | Discord | SFV CFN: templewulf
  • InfidelInfidel Heretic Registered User regular
    edited February 2011
    Here's an example of how you should break up your AJAX stuff (imo).

    I leave it to you to format and do these tags properly!

    page.php
    ...
    <script src="script.js">
    ...
    <div id="votepane"></div>
    ...
    

    script.js
    ...
    // call this with a link or onclick or what have you
    function openVotePane(id)
    {
      $.ajax({
        dataType: 'json',
        data: {
          call: 'votePane',
          id: id,
        },
        success: loadVotePane
      });
    }
    
    function loadVotePane(o)
    {
      // generate HTML here for presenting the vote interface based on the data in o
    }
    ...
    

    controller.php
    $call = $_POST['call'];
    ...
    if ($call == 'votePane')
    {
      $o = array();
      // fill $o with relevant data
      print json_encode($o);
    }
    ...
    

    Obviously that is just to illustrate where to break things up, code it much better than that. ;-) You can get a MVC type setup, keeping things organized has been really vital to me since I am working on an AJAX web game with simultaneous users interacting and allowing the same account to be open in multiple browsers at once.

    edit: to be clear, the View is the HTML-generating PHP and the JavaScript, the Controller is my back-end PHP logic, and the Model is of course my class-based data model that allows my Controller to interface with the database in a consistent fashion.

    Infidel on
    OrokosPA.png
This discussion has been closed.