Jump to content

Having difficulty understanding PHP syntax..


Recommended Posts



Hey guys and gals, before I ask, I do want to point out that PHP and JS seems very AWESOME to me and I really want to learn it. LIKE REALLY BAD. I am willing to do whatever I can to learn what I need to learn!

So I just finished the 3rd project. Which is PHP Tag Cloud. And I am still having some trouble understanding what's going on within the code.

For example, I am understanding the concepts of a 'loop' or 'if' and 'else', and 'while.' I get what they are doing.

But, when it comes to the code itself(syntax), I am still pretty lost. In this example below, I am totally lost as far as the syntax,  but I understand what we are trying to achieve.

(this is a snippet of code from the downloaded zip file, not from my version of code)

function get_tags()
    $this->tags = array();
    $this->largest = 0;
    // get tag id, tag name and the number of times the tag has been used
    $result = $this->mysqli->query("SELECT posts_to_tags.tag_id, tags.name, COUNT(posts_to_tags.tag_id) AS total FROM tags, posts_to_tags WHERE posts_to_tags.tag_id = tags.id GROUP BY posts_to_tags.tag_id");
    if ($result->num_rows > 0)
      while ($row = $result->fetch_object())
        // figure out which tag has been used the most often. However many times that tag was
        // used will be placed within $this->largest for later use
        if ($row->total > $this->largest) { $this->largest = $row->total; }
        // add tag to array
        $this->tags[] = array('id' => $row->tag_id, 'name' => $row->name, 'total' => $row->total);
      // sort tags
      usort($this->tags, array('tagcloud_model', 'compare_names'));
      // if there are no results to display
      $this->tags = FALSE;
  // used by the usort function within get_tags() above
  function compare_names($a, $b)
    return strcmp($a['name'], $b['name']);


I should mention I have only been learning PHP for few days all together, only from Stef's course and these projects.

Any tips, advice, or ideas on how to grasp it better?(obviously I am going to continue my learning process, videos, tutorials.) I just want to see if maybe I can understand these projects a bit better as I am learning them.


Do you think I should continue the projects and trust the process as I go, or take a detour and try and understand some things more before I finish the projects?








Link to comment
Share on other sites


Sorry for the delay. Sometimes you have to write code blindly .... as you go. It is important to write the code and see the errors, as it will train your brain. So just go through the process of working with the first few basic projects. 

Be sure to watch the projects video on the home page, it tells you how to use the projects. 


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...