Jump to content

Recommended Posts

Hi Everybody,

My friends dentistry want a dynamic element adding to their website, Hes asked me to take a look at adding this feature as he doenst want to have to draft in a web design agency and its only a small task. He currently has a 5 page static website. 1 of the pages is a meet the team, he wants this page to be php driven where he can edit his own content, I said Ill learn how its done and create this for him, As far as im aware I will only need to create an admin section where he can edit the data in a table and have the content stored call this data, Is this as small a job as I presume? and if he was to go to an agency would failing me being able to do this will he be charged extensively?

Link to comment
https://forums.phpfreaks.com/topic/192270-static-to-dynamic/
Share on other sites

It all depends on how "extensive" the editing features need to be for this page. Does he need to be able to edit font and graphics? If the layout is such that there is only a block of text for each person it can be implemented very easily and would not even need a database. Can you provide a link to the current page?

Link to comment
https://forums.phpfreaks.com/topic/192270-static-to-dynamic/#findComment-1013205
Share on other sites

You could do this with a content management system such as Wordpress or Drupal. The only real charge would be to convert the current page into a workable template for Wordpress/Drupal and shouldn't cost more than say $150 - 200 if done properly by a professional (including the installation and configuration)

Link to comment
https://forums.phpfreaks.com/topic/192270-static-to-dynamic/#findComment-1013207
Share on other sites

the page in question is similiar to http://www.moonfleet.co.uk/the-dental-team-holisitc-poole/meet-the-team-poole-dentist.html

He needs to add/edit the photo and just upload a block of text and a name, no font styling is neccessary, I have done this technique before but only using adobe dreamweaver developer toolbox, I want to learn how its done properly, and how long do you think this would take?

 

Thanks for your response mjdamato

Link to comment
https://forums.phpfreaks.com/topic/192270-static-to-dynamic/#findComment-1013208
Share on other sites

What? It doesn't need a custom framework. The OP only wants to allow one page to be edited.

 

@liamloveslearning: Making a page, such as the one you linked to, editable is fairly simple as long as the format will always be consistent. In this case I would assume only the profiles for each person would be editable. Each profile consists of four pieces of information: Name, Title, Description, and image. As long as the output of each of those four peces of information will be consistent (i.e. name is always bold, no ability to italicize/bold individual words in the decription) it is fairly straitforward.

 

Personally, for a project such as this, I would use a flat file to store the data and build PHP scripts to edit the file. For the edting, I would create a form page with input fields for all the current profiles and an empty set of fields at the bottom to add a new profile. When the page is saved, the form is displayed again with all the profiles (including the new one) and again, another empty set of fields to add a new profile. I suppose you could also create a function to move profiles up/down on the page. But I doubt that that function would be used much - if at all.

 

Without knowing your level of expertise in HTML/PHP I'm not sure how much of an undertaking this would be for you. For someone proficient, I think this could be done in a couple of hours.

Link to comment
https://forums.phpfreaks.com/topic/192270-static-to-dynamic/#findComment-1013217
Share on other sites

Thanks for your post mjdamato, So by file would you edit the data via an xml file? I was planning on building a login where the user will be presented with a page, He could then click one of the team and update their records or add a new record.

 

Im fluent in xhtml/css and have a basic knowledge of php (Nothing serious however) Ive not dabbled with xml for a long time but im sure I could pick it up again easily.

 

What do you suggest I look at first?

 

Thanks again and I appreciate your input  ;D

Link to comment
https://forums.phpfreaks.com/topic/192270-static-to-dynamic/#findComment-1013223
Share on other sites

Yeah, you could use XML, but I'd just use a CSV file. I was bored on a conference call, so I wrote some rough code.

 

manageProfiles.php

<?php

$dataFile = "profiles.txt";

function getProfiles()
{
    global $dataFile;

    $profiles = array();
    if(file_exists($dataFile))
    {
        $dataArray = file($dataFile);
        foreach($dataArray as $key=>$profileRecord)
        {
            $profiles[$key] = explode("\t", $profileRecord);
        }
    }

    return $profiles;
}


function saveProfiles($profilesArray)
{
    global $dataFile;
    $fh = fopen($dataFile, 'w') or die("can't open file");

    foreach($profilesArray as $profile)
    {
        $textRecord = implode("\t", $profile) . "\n";
        fwrite($fh, $textRecord);
    }

    fclose($fh);
    return;
}

?>

 

pageEdit.php

<?php

include("manageProfiles.php");

function createFieldSet($profileData=false)
{
    if(!$profileData)
    {
        $name  = "";
        $title = "";
        $desc  = "";
        $image = "";
    }
    else
    {
        list($name, $title, $desc, $image) = $profileData;
    }

    $fieldSet  = "Name: <input type=\"text\" name=\"name[]\" value=\"{$name}\" /><br />\n";
    $fieldSet .= "Title: <input type=\"text\" name=\"title[]\" value=\"{$title}\" /><br />\n";
    $fieldSet .= "Description: <textarea name=\"desc[]\">{$desc}</textarea><br />\n";
    $fieldSet .= "Image: <input type=\"text\" name=\"image[]\" value=\"{$image}\" /><br /><br />\n";
    return $fieldSet;
}

//Data was posted, save changes
if (isset($_POST['name']) && is_array($_POST['name']))
{
    $profileCount = count($_POST['name']);
    //Parse the data
    $profileData = array();
    for($idx=0; $idx<$profileCount; $idx++)
    {
        $name  = trim($_POST['name'][$idx]);
        $title = trim($_POST['title'][$idx]);
        $desc  = trim($_POST['desc'][$idx]);
        $image = trim($_POST['image'][$idx]);

        if(!empty($name) || !empty($title) || !empty($desc) || !empty($image))
        {
            $profileData[$idx] = array($name, $title, $desc, $image);
        }
    }
    //Save the changes
    saveProfiles($profileData);
}
else
{
    //Get the current data from file
    $profileData = getProfiles();
}

//Create the form fields
$formFields = '';
foreach($profileData as $profile)
{
    $formFields .= createFieldSet($profile);
}

//Create empty fieldSet to add new profile
$formFields .= createFieldSet();

?>
<html>
<head></head>

<body>
<form action="" method="POST">
<?php echo $formFields; ?>
<button type="submit">Submit Changes</button>
</form>
</body>
</html>

 

pageDisplay.php

<?php

include("manageProfiles.php");
$profileData = getProfiles();

function displayProfile($profileAry)
{
    list($name, $title, $desc, $image) = $profileAry;
    $htmlOutput  = "<div><img src=\"{$name}\">\n";
    $htmlOutput .= "<span><b>{$name}</b> {$title}<br /><br />\n";
    $htmlOutput .= "{$desc}<br />\n";
    $htmlOutput .= "</div><br /><br />\n";
    return $htmlOutput;
}

?>
<html>
<head>
<style>
</style>
</head>
<body>
<?php
$profileData = getProfiles();
foreach($profileData as $profile)
{
    echo displayProfile($profile);
}

?>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/192270-static-to-dynamic/#findComment-1013252
Share on other sites

That works perfectly mjdamato, I wish I could write code that easily in my spare time haha, My only question is that the manageProfiles.php shows no data, Also would it be easily done for me to change the image text field to a browse button?

Link to comment
https://forums.phpfreaks.com/topic/192270-static-to-dynamic/#findComment-1013608
Share on other sites

Also would it be easily done for me to change the image text field to a browse button?

 

Yeah, that could be done, but it wouldn't be as simple as adding a browse button. You have different options on handling the images. The solutions require differing capabilities of the user. The simplest solution would be for the user to manually upload pre-sized images to the server and to manually enter the path in the edit page. Next easiest would be to incorporate upload functionality on the edit page. BUt, the user would need to be responsible for uploading pre-sized images or at least images with a consistent scale so you can appropriately display them programatically. The third option would be to include scripting that will automatically scale/crop the uploaded images.

 

I have no idea what the ROI is for this project - which would determine how much time and effort should be invested. Again, none of this is exceptionally difficult. Just do one thing at a time and add individualt features as you complete others.

Link to comment
https://forums.phpfreaks.com/topic/192270-static-to-dynamic/#findComment-1013795
Share on other sites

Why on earth are you using global?  Use the argument list!  That's what its there for!

 

I originally wrote it that way, but then decided against it. The way I coded it the page which contains the "management" functions is completely self contained. This way, on any pages that need to read/write the profile data, the developer does not have to reference back to the variable created on the page with the management functions. Ideally, this would be a class. I try to avoid gloabl variables whenever possible, but I feel they do have their place.

Link to comment
https://forums.phpfreaks.com/topic/192270-static-to-dynamic/#findComment-1013859
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.