‘Setting Featured Work’ Function


if(!isset($_SESSION[‘session’])){ //if login in session is not set
header(“Location: indexpage.php”);

$userid = $_GET[‘userid’];

if(count($_POST[‘featured’]) <= 3){
$query = “UPDATE files set featuredwork = 0 where USERID = ‘$userid'”;
mysqli_query($db_server, $query);
foreach($_POST[‘featured’] as $selected){
$query1 = “UPDATE files set featuredwork = 1 where id=’$selected'”;
$result = mysqli_query($db_server, $query1);

if (!$result) {
echo “Unable to update database”;
} else {
echo “<div id=’successfeatured’>
Successfully set featured work! Click <a href=’profilepage.php?user=$myprofile’>here</a> to go to your profile!

echo “Please select only 3 featured items”;


I have been working on this feature for quite some time now and had approached the coding several different ways before finally being successful in the end result.

By enabling the user to set up to three featured pieces of work, their work can be viewed instantly on their mini profile. Originally I had tried creating separate buttons to enable a user to set any file to be ‘featured’, however once setting three pieces of work, if a user wanted to change or update this, the functionality would fail due to the query I had written.

I decided to use check boxes instead so that a user on return to the edit profile page can see which files are selected as their featured work. In addition to this I felt that a tick box improves the user intuition aspect to the website which I had previously spoke about with my supervisor in the week when discussing areas for improvement.

The explanation of the code is as follows:

If the array is counted and the number is more than three, then it should not insert as featured work, and it will keep the file set to ‘o’. For each file is that selected to be a ‘featured file’ update its value to ‘1’. If this query result is false, print out “Unable to update database”, otherwise, print the div “successfeatured” which “Successfully set featured work! Click here to go to my profile”, or alternatively print an error which states that the user has selected more than three featured pieces of work!

This entry was posted in Code. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s