Sunday, 21 May 2017

Which Should I Learn First PHP or MYSQL?

Which Should I Learn First PHP or MYSQL? I always think that the programming language should come first. PHP -› MYSQL. On the off chance that it’s about picking one to learn initially, then it ought to be PHP. When you start learning PHP, then as you progress, you will see the need of communicating with database, and all things considered MySQL will fit in exceptionally well and afterward you can learn MySQL as well. Be that as it may, such a circumstance would not be there the other way around. So starting first with PHP would without a doubt turn out to be better.

Simply get fundamental learning and comprehension of PHP. Once you’re sure you can begin compose basic projects or application which does not include database. After that learn Mysql or any database and do some basic login and validation application.

MySQL is a fine tool, however in the event that will learn it I would recommend that you begin with MySQL, however individuals are beginning to feel dubious about MySQL itself, since it's presently in the hands of Oracle.
Learning MySQL or MariaDB is still unquestionably a significant thing to do, and I exceptionally recommend it. Furthermore, what you would realize Postgres and Sqlite3, which are additionally worth learning.
Take a look at :). After you will reach some knowledge’s, it will help you to work with database(db).

When you want to go ahead with more mind boggling application then work on center or enormous application ventures or learn both simultaneously.

You might be able to get a short free trial on (O'Reilly's site) and investigate which one most interests to you. Here are several books to take a look at.
  • 1.      Learning PHP, MySQL, and JavaScript By: Robin Nixon Publisher: O'Reilly Media, Inc. Print ISBN-13: 978-0-596-15713-5
  • 2.      Head First PHP & MySQL By: Lynn Beighley; Michael Morrison Publisher: O'Reilly Media, Inc. Print ISBN-13: 978-0-596-00630-3
Some open libraries have these books also.

PHP is immense, and decent to utilize. All hosts support it, and it's been around sufficiently long for a group to work around it. When you get your comprehension of how a PHP communicates with a database, and how connections work in a database you're prepared for developing a great system. Try not to tune in to the PHP haters either, PHP is getting to be noticeably mainstream again yet as new systems that simply expand on the information you've picked up of learning PHP.

I exceedingly recommend PHP, it's what my group and I utilize. web programming is entirely fun. Cooperation is a whole lot more reasonable.
I know that someone can make good PHP code, but it the experience with the vast amount of bad code that sets people's opinions of the language. I have been fortunate enough to go away from the bad code and create new applications with laravel lately, however, it never seems to compare with the beauty of working with rails.I feel that you can do well in any language, you just need to apply proper design principles, know your code smells, and test. I was really happy when I found guard-phpunit2 the other day as it has improved the way I code in PHP a lot. -tmuntan1
You ought to put your time in a language that you want to utilize. PHP may have more assets and more employments accessible, yet in the event that you don't care for the language then don't land a position utilizing it. As for PHP, I would learn but it's common now. Nothing against it.

It's a good idea to learn PHP eventually, since it's so common.

Thursday, 18 May 2017

Facebook Notification Database Structure Approach

I have been investigating how to build a notification system on Thewallclone social network system and somewhere else and got myself attracted to the arrangement that worked.

A notification is about activities (friendship.). Here is a standardized database structure (however I've used                InnoDB).You need to notify certain users about changes. So it's per-user notifications. implying that if there were 10 users included, you create 10 notification.

One the most critical part of social network system is the ablity to notify users of activities, which keep the discussion fascinating. Here will figure out how facebook notification system functions, this is my approch and it worked for me.

Designing a social network system is one of the tough system you would ever work on.

There are few thing to consider

Things to consider are outlined.
  1. Comment
  3. unlike
  4. Follow
  5. Page Likes
  6. Page Post Like and so forth
These are few we will cover on this article, underneath is our database structure that would contain what we have said aboved.

-- Database: `sociallabs`

-- --------------------------------------------------------

-- Table structure for table `notify`

  `nid` int(11) NOT NULL AUTO_INCREMENT,
  `user_one` int(11) NOT NULL,
  `user_two` int(11) NOT NULL,
  `type` varchar(50) NOT NULL,
  `post_id_fk` int(11) NOT NULL,
  `page_id_fk` int(11) NOT NULL,
  `dated` varchar(50) NOT NULL,
  PRIMARY KEY (`nid`)

In this way, the Nid field will be set to foreign key of our table, with the end goal that it would auto increment record on each new record inserted into our table.

user_one would be the first user, who claim the post or page, while the user_two would be the second user who make the move, for example, like, comments, follow, as take after and so on.

post_id_fk would be the remote key for related with the post while page_like_fk is the foerign key joined to the page id during creation.

Type is the kind of activity that will be such her the comment, like, follow etc

dated is the time at which the move were made.

PHP Comment code

//inset into nofication table
 $db->query("INSERT INTO notify (user_one, user_two, type, postid_tk, status, dated)
  VALUES( '$userid_fk', '$uid', 'comment', '$postid', '1', '$time')");


PHP Like code

 //inset into nofication table
 $db->query("INSERT INTO notify (user_one, user_two, type, postid_tk, status, dated)
  VALUES( '$userid_fk', '$uid', 'like', '$likepostid', '1', '$time')");

PHP notification sample code

$up=$db->query("SELECT * FROM notify WHERE status='1' AND user_one='$log_id' AND user_two!='$log_id' ORDER BY nid DESC");
               if ($countNoti) {
                 # code...
                echo'<span id="HW_badge" class="HW_visible" data-count-unseen="'.$countNoti.'">'.$countNoti.'</span></a>';

  if ($countNoti) {

    $cpost=$db->query("SELECT * FROM post WHERE id='{$postid_tk}' ");

    $utwo=$db->query("SELECT * FROM users U, user_bio UB WHERE U.uid='{$user_two}' AND UB.uid=U.uid ");

    $query = $db->query("SELECT * FROM updates WHERE  update_id='{$postid_tk}' ");
    $row=mysqli_fetch_assoc($query );

    $setid= $db->query("SELECT * FROM groups WHERE group_id='{$pageid_fk}'");

switch ($ctype) {
  case 'comment':
    # code...
    $ctype= "Publised a comment on your post - <a href='readtweet?story_id=$postid_tk' style='color:white;' title='Read story'>".convert_clickable_links(substr($message,0,70)).'...</a>';
  case 'like':
    # code...
    $ctype= "likes your post - <a href='readtweet?story_id=$postid_tk' style='color:white;' title='Read story'>".convert_clickable_links(substr($message,0,70)).'...</a>';
    case 'dislike':
    # code...
    $ctype= "dislikes your post  <a href='readtweet?story_id=$postid_tk' style='color:white;' title='Read story'>".convert_clickable_links(substr($message,0,70)).'...</a>';
    case 'followed':
    # code...
    $ctype= "followed you on Wall
To share and get the latest, follow <a href=".$twou['username']." >".$twou['username'].'</a> back';
    case 'pagecomment':
    # code...
   $ctype='commented your post on <a href=page?name='.$pageName.'>'.$pageName.' page</a> - <a href="pagestory?story_id='.$p_id.'" style="color:white;" title="Read story">'.convert_clickable_links(substr($messages,0,70)).'...</a> ';
     case 'pagePostLike':
    # code...
    $ctype='liked your post on <a href=page?name='.$pageName.'>'.$pageName.' page</a> - <a href="pagestory?story_id='.$p_id.'" style="color:white;" title="Read story">'.convert_clickable_links(substr($messages,0,70)).'...</a> ';

    case 'dispagePostLike':
    # code...
     $ctype='Disliked your post on <a href=page?name='.$pageName.'>'.$pageName.' page</a> - <a href="pagestory?story_id='.$p_id.'" style="color:white;" title="Read story">'.convert_clickable_links(substr($messages,0,70)).'...</a> ';


    case 'pageLike':
    # code...
    $ctype= "is following ".$pageName.' page';

    # code..                  
  $ctype="more on your";

 $img= '<img src="user_img/'.$twou['username'].'/'.$twou['img'].'" class="img-circle img-nav" alt="user profile image"> ';

        echo '<div class="alert messageBox" id="removeNav'.$nid.'">
        <span class="closebtn" id="navAction" name="'.$nid.'" rel="'.$navId.'">&times;</span> 

                                  <a href="'.$twou['username'].'" title="'.$twou['name'].'" target="_self"><strong>'.$twou['name'].'</strong></a> '.$ctype.'

                                  <p><small>  <i class="fa fa-clock-o"></i> '.time_passed($dated).' </small> </p> 

       // echo "$twou[username] commented on your post".strlen($dat['message']);
//echo $data['username'];
      echo '<span class="alert alert-danger">No notifications</span>';

Learn to Code HTML and CSS: Develop and Style Websites

In case you're absolutely new to website design or on the off chance that you require a revive, this is a decent place to begin. In this course will figure out how to compose HTML and CSS which are the fundamental building pieces of any site. Try not to stress on the off chance that you've never composed a solitary line of code some time recently.

In the event that you can, envision a period before the innovation of the Internet. Sites didn't exist, and books, imprinted on paper and firmly bound, were your essential wellspring of data. It required a lot of exertion—and perusing—to find the correct snippet of data you were after.

Today you can open a web program, bounce over to your web crawler of decision, and hunt away. Any piece of believable data rests readily available. What's more, odds are somebody some place has designed a site in light of your correct hunt.

In this blog you will learn the best practices to design your own particular sites utilizing the two most overwhelming innovations—HTML and CSS.

Before we start our excursion to figure out how to design sites with HTML and CSS, it is essential to understand the differences between the two languages, the syntax of each language, and some common terminology.

HTML is the standard markup language for creating Web pages.
  • HTML stands for Hyper Text Markup Language
  • HTML describes the structure of Web pages using markup
  • HTML elements are the building blocks of HTML pages
  • HTML elements are represented by tags
  • HTML tags label pieces of content such as "heading", "paragraph", "table", and so on
  • Browsers do not display the HTML tags, but use them to render the content of the page


<!DOCTYPE html>
<title>Page Title</title>

<h1>My First Heading</h1>
<p>My first paragraph.</p>


Example Explained

The <!DOCTYPE html> characterizes this record to be HTML5

The <html> component is the root component of a HTML page

The <head> component contains meta data about the archive

The <title> component indicates a title for the record

The <body> component contains the noticeable page content

The <h1> component characterizes a substantial heading

The <p> component characterizes a passage

In our next article, we figure out how to Design custom site pages with a picture exhibition and contact page. At last, we stroll through how to share a site live on the web.

10 Awesome PHP snippets

10 Awesome PHP snippets

Welcome back, developer's. this article will make a long running on your coding life, underneath are beat 10 valuable pieces i made sense of and most likely thought would be helpful to you. 

These php tips, you may require them on your improvement procedure, and beyond any doubt you require a work round examples. 

These code are helpful and you gone over them more often than not, the easily overlooked detail that matter most, means the most.

1 } How to sanitize user input

You are told the greater part of your coding profession not to trust client's info, it may be spam or infusion, not 100% immaculate, clean and channel clients information is the best alternative, yet that is not 100% secured either but rather felt smidgen safe and secured, beneath is a capacity to clean client's contribution before putting away to your database.

function cleanInput($text)
 //strip tags
 $text = strip_tags($text);
 $text = trim($text);
 return $text;

The most effective method to utilize work

// chow to use function

2}  Step by step instructions to approve Email address with PHP

It's essential to approve client email before putting away and planing to utilize them for any reason, i at some point get a kick out of the chance to confirm email deliver just to make certain is not spam and legitimate email. 

With PHP "FILTER_VALIDATE_EMAIL" rest guaranteed a touch of no spam, so you might need to utilize this capacity to legitimate email address is extremely helpful.

function Is_email($email)
 //If the input string is an e-mail, return true
 if(filter_var($email, FILTER_VALIDATE_EMAIL)) {
  return true;
 } else {
  return false;
// chow to use function

3} PHP how old am I? reveal to me my age

This capacity is exceptionally great pleasant, seen on different stage making inquiry identified with this, for the individuals who are taking a shot at online networking stage, this would be extremely useful, telling your client how old they are. 

Note: you can even utilize this capacity to send glad birthday message, at whatever time it coordinates that 'Day and Month' simply let them despite everything you recall that them as your exceptional clients. it proves to be useful too. 

See demo: enter Day, Month And Year to perceive how old are you... 

Note: you might need to change "DateTimeZone" is exceptionally welcome or better still use without timeZone.
Please read more on  Date and Time Related Extensions

//with timeZone.
function howOldAmI($age)
  $tz  = new DateTimeZone('Europe/Brussels');

$age = DateTime::createFromFormat('d/m/Y', $a, $tz)-&gt;diff(new DateTime('now', $tz))-&gt;y;
     return $age;
     echo howOldAmI('21/04/1993');

    // without timeZone.

function Tellage($b)
     $_age = floor((time() - strtotime($b)) / 31556926);
     return $_age;
  // echo Tellage('1993/04/21');


Step by step instructions to Get All Files Names From A Folder. 
This bit beneath will list/demonstrate all your record names in separate of their document augmentations 
In the event that you at any point needed to flaunt your documents name on your envelope, then this script is ideal for you.

$dir_path = "folder/"; //directory
$options = "";
    $files = opendir($dir_path);
          while(($file_name = readdir($files)) !== FALSE)
              if($file_name != '.' &amp;&amp; $file_name != '..')
               // select option with files names
               $options = $options."&lt;option&gt;$file_name&lt;/option&gt;";   
               // display the file names
               echo $file_name."&lt;br&gt;";


&lt;!DOCTYPE html&gt;
    &lt;title&gt;PHP GET List Of FILES NAMES FROM A Directory &lt;/title&gt;
            &lt;?php echo $options;?&gt;

5} How to create SEO friendly URL with PHP

Have a perfect cordial url is the request of the day, each body need to keep up SEO standard, if require url like this login-page-for-web then you don't need to look any further on this issue, i got you secured. with clean URL work you can have a pleasant looking, amicable and engaging Url for your site or blog.

function cleanURL($string) {
   $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
   $string = preg_replace('/[^A-Za-z0-9\-]/', '-', $string); // Removes special chars.

   return preg_replace('/-+/', '-', $string); // Replaces multiple hyphens with single one.
//How to use this function

6} Function to converting time to ago format

This is aPHP work with class HowLong, having somethis like this 3 weeks ago, 1 min ago or an hour ago, this capacity would be awesome for web informal community application, of discussion base framework, demonstrating clients to what extent they have been on the web and when last they login and so forth utilizing PHP timestamp.

function HowLong($timestamp){
     $difference = time() - $timestamp;
     $periods = array("sec", "min", "hr", "day", "week", "month", "year", "decade");
     $lengths = array("60","60","24","7","4.35","12","10");
     for($j = 0; $difference &gt;= $lengths[$j]; $j++)
      $difference /= $lengths[$j];
      $difference = round($difference);
     if($difference != 1) $periods[$j].= "s";
      $text = "$difference $periods[$j] ago";
      return $text;
// How to use this function
$time=(1482698697); //$timestamp time()

echo HowLong($time);

Note: this can display a long time ago, even decades.

7} How to create secured PHP login function

Approving clients qualifications is a decent method for limiting approve access to some discharge some portion of your site, potentially which is mean for enlisted clients. this capacity will approve, purify each client email and secret key before conceding access to clients, you might need to attempt this on your next venture.

//database configuration
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'sociallabs');

//loginfunction start
function loginVal($db, $email, $password)
if (isset($_POST['email']) &amp;&amp; ($_POST['password'])) {

$email = trim($_POST['email']); //Storing email in $email variable.
$password = ($_POST['password']); //Storing password in $password variable.

  if (!filter_var($email, FILTER_VALIDATE_EMAIL) === false) {

$match = $db-&gt;query("SELECT * FROM users WHERE email='{$email}' AND password='{$password}' "); 
$data = mysqli_fetch_array($match); 
$user_id= $data['uid'];
$fname = $data['fname'];
$lname = $data['lname'];
$email = $data['email'];

if(mysqli_num_rows($match)==1){ //if there is such email and password.
$_SESSION['uid']=$user_id; //Storing user ID in SESSION variable.
$_SESSION['fname']=$fname; //Storing First name in SESSION variable.
$_SESSION['lname']=$lname; //Storing Last name in SESSION variable.
$_SESSION['email']=$email; //Storing EMAIL in SESSION variable.

$_SESSION['AutenUsera']=0; //SET TO FALSE.
if(($_SESSION['email']=$email) and ($_SESSION['password']=$password)){
$_SESSION['AutenUsera']=1; //SET TO TRUE.
echo "&lt;meta http-equiv='refresh' content='0; index.php'&gt;"; //if successful redirect to secured page

  $error='&lt;div id="top-blurb-error"&gt;
            &lt;span id="error-signing-in" &gt;Oops!, Invalid email or password!&lt;/span&gt;
// error message to display

  } else {
   $error=('&lt;div id="top-blurb-error"&gt;
            &lt;span id="error-signing-in" &gt;Oops!, '.$email.' is not a valid email address !&lt;/span&gt;
// How to use this class
echo loginVal($db, $email, $password);

8} How to extract Youtube url from post

On account of PHP group, things are minimal more less demanding than some time recently, with php pre_match function i could extact Youtube Videos from url from any client post to utilize it independently without affecting the orginal post.

Youtube API is use to retrieve the content of the video ''
PHP preg_match function is used to check if youtube url format is detect to capture link address.

Meanwhile you have to define your width-height.

$postdata ="THE SOCIAL NETWORK APP V.1.0 Build Your Own Social Network"; // user post
 //if Youtube url detected;
if(preg_match('~(?:https?://)?(?:www.)?(?|\?v=)?([^\s]+)~', $postdata, $match)){
echo "
&lt;iframe width='560' height='315' src='".$match[1]."' frameborder='0' allowfullscreen&gt;&lt;/iframe&gt;
//print ($match[1]); //url
echo $postdata;


9} How to extract Vimeo url from post

Vimeo is also one of the popular video straming website avaliable so far, and lots of people are diving into it to publish their story and content, is nice to share memorie with familie and friends. if you are a developer working on your dreamed project or client website, that need this feature, then this is the perfect code for you, light weight and small in 

$message ="THE SOCIAL NETWORK APP V.1.0 Build Your Own Social Network";
if(preg_match("/(https?:\/\/)?(www.)?(player.)?\/([a-z]*\/)*([0-9]{6,11})[?]?.*/", $message, $output_array)) {
echo "&lt;br&gt;";

echo '&lt;br&gt;&lt;iframe width="600" height="400" src="//'.$output_array[5].'?title=0&amp;amp;byline=0&amp;amp;portrait=0&amp;amp;color=ffffff" class="video"&gt;&lt;/iframe&gt;';

    //echo "Vimeo ID: $output_array[5]"; //url


10} Instructions to separate @ and # symbol from string and how to change over text[url] to interactive connections

Creating clickable link with PHP is made easy, the function convert url to clickable link, this function support @ symbol and # tag enabled, for example like twitter or facebook @mention and hash # tag usage, you can implement this on your website or clients website. I have implemented this function On social system V3.0

function clickable_links($message)
  $parsedMessage = preg_replace(array('/(?i)\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()&lt;&gt;]+|\(([^\s()&lt;&gt;]+|(\([^\s()&lt;&gt;]+\)))*\))+(?:\(([^\s()&lt;&gt;]+|(\([^\s()&lt;&gt;]+\)))*\)|[^\s`!()\[\]{};:\'".,&lt;&gt;?«»“”‘’]))/', '/(^|[^a-z0-9_])@([a-z0-9_]+)/i', '/(^|[^a-z0-9_])#([a-z0-9_]+)/i'), array('&lt;a href="$1" target="_blank"&gt;$1&lt;/a&gt;', '$1&lt;a href="$2"&gt;@$2&lt;/a&gt;',  '$1&lt;a target="_blank" href="$2&amp;searching=yes"&gt;#$2&lt;/a&gt;'), $message);
  return $parsedMessage;
echo clickable_links($message);

Trust postulations tips make a long keep running on your advancement profession... like, offer or hit me a remark simply say hello.... see you all around.