1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Dynamic page for changing team members.

Discussion in 'PHP' started by concertband, Nov 10, 2015.

  1. #1
    Hi all,

    I'm creating a website for a university society. On the site, there's going to be one page with pictures and a short bio of each committee member. I've already designed this page statically, but I'm aware that every year, committee members change.

    Because I cannot guarantee that whoever manages the website after me will be able to edit the HTML data at source correctly, I want to design a form on a separate page which will give a user-friendly interface for "uploading" new committee members.

    I have already solved the images, creating an upload form that uploads a new picture with a set filename for each committee position. The problem I face is changing the text content on the page.

    What I need help with is how to get the information from a form to change the html code on the committee page directly. Obviously I know that this will involve PHP but I want to avoid using SQL or any other database to store the member info. I want the form to change the HTML content directly, not have a website that relies on reading from a database everytime it's visited.

    Thanks in advance!

    Untitled5.jpg
     
    concertband, Nov 10, 2015 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    Since this is a fairly limited set of content (at least I assume), you could just write (via PHP) directly to a file for each position, and then include those files.
    I'm not really sure why you're so adamant not using a database (this is EXACTLY what a database is for) - if you were using a database, creating the page would just be a query to the database, for so looping through the content in the database. For such a limited number, such a query wouldn't put much of a strain on anything - you could even leverage php, and have php output a static file based on the content in the database (and whenever something changes, just have an "update static file" button to refresh the content).
     
    PoPSiCLe, Nov 10, 2015 IP
  3. concertband

    concertband Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    The reason I'm trying to avoid a database is that I don't know where to store it. The company hosting our web domain may not be able to store an SQL database, and I cant store it on a local machine that's permanently hooked-up to the web. I may be missing an option since I'm fairly new to all this, but last time I used SQL (someone else set it up) it was hosted on a local server.

    Would it be possible to store a standalone database file? Similar to a spreadsheet?
     
    concertband, Nov 10, 2015 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #4
    Honestly, as long as you are only going to have a few dozen of these, you are likely better off without the database anyways. There's something simple you can leverage to do a lot of the gruntwork for you -- and that's the file system.

    How I would approach that would be to have a /staff directory, in that directory I'd have files that follow a certain naming convention... probably use a three or four digit leading value, followed by a underscore delimiter, then the name of the person, then an extension -- either ".markup" for the HTML describing the person, and a ".avatar.jpg" or ".avatar.png" for the avatar. The leading number would be so that alpha sort by filename (the default behavior of things like glob) since you don't seem to want them in alphabetical order. The leading number would also be handy for if you have two people with the same name... I'd probably reserve the lowest digit for such redundancies or the ability to pre-sort, and probably START with a main index of 5, so for example "Woody" would have these two files:

    /staff/0050_Woody.markup
    /staff/0050_Woody.avatar.jpg

    To pull a list of all staff, you'd just pull up a glob, then pathInfo to extract the staff name from the filename and create the avatar link thusly:

    $staffGlob = glob('staff/*.markup');
    $staffList = []; 
    foreach ($staffGlob as $data) {
    	$info = pathInfo($data);
    	$staffList[] = [
    		'name' => explode('_', $info['filename'])[1],
    		'markup' => $info['basename'],
    		'avatar' => $info['filename'] . '.avatar.php'
    	];
    }
    Code (markup):
    * note * I'm using PHP 5.4 style arrays there. Change [] to Array() if on outdated insecure versions of PHP... or just upgrade the blasted system.

    PHP 5.5's generators are even better suited to this, as if you have multiple instances of things like "staff" you could use a generator instead.

    function getUsers($path) {
    	$glob = glob($path . '/*.markup');
    	foreach ($staffGlob as $data) {
    		$info = pathInfo($data);
    		yield [
    			'name' => explode('_', $info['filename'])[1],
    			'markup' => $info['basename'],
    			'avatar' => $info['filename'] . '.avatar.php'
    		];
    }
    
    $staffList = getUsers('staff');
    Code (markup):
    But again you need to be on PHP 5.5 or higher for that to work.

    Either way, to output you avatars you'd just foreach through $staffList.

    foreach($staffList as $staffMember) echo '
    	<img
    		src="staff/' . $staffMember['avatar'] . '"
    		alt="' . $staffMember['name'] . '"
    	>';
    Code (markup):
    the ['markup'] being the link to the include for the text of that member. I would also consider storing the ['filename'] off the pathinfo as that could be used with the data- attributes for ajax linking in the text or as an ID for making it show using CSS trickery if you want to monolithic load everything -- I'd probably use the latter approach so that you have a chance at scripting off graceful degradation.

    Adding new ones is as easy as just making the two files, removing them is as simple as deleting files or you could even just rename the .markup files to .markup.old and they'll be ignored.

    When you have simple data sets you want to manually edit, sometimes you can get the filesystem to do the heavy lifting for you -- it removes the overhead of a database from the equation making it ideal for smaller data sets. A number of early forum software operated in this manner, using the date in YYYYMMDD format as the prefix and saving the contents of posts and responses via htmlspecialchars.
     
    deathshadow, Nov 16, 2015 IP
  5. ketting00

    ketting00 Well-Known Member

    Messages:
    772
    Likes Received:
    27
    Best Answers:
    3
    Trophy Points:
    128
    #5
    Yeah, this is easy using an array.
    Alternately, you can do it with JavaScript using JSON to store data.
     
    ketting00, Nov 17, 2015 IP