Please help me understand... comment this code completely

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
VinceGledhill
New php-forum User
New php-forum User
Posts: 4
Joined: Sat Nov 04, 2017 8:56 am

Sun Nov 05, 2017 9:05 am

Hi People.

I am new to learning PHP and got some code written by a friend. Please could some expert on here help me to understand everything that is going on by commenting it all?

This code, gets stuff from the database and makes a menu out of it. It's a database with hundreds of entries. See the left hand menu of www.airfieldcards.com

Code: Select all

<?php
$rows = getMenu();

foreach($rows as $row){
	echo "<li><a href='index.php?a=".$row['letter']."'>".ucfirst($row['phonetic'])."(".$row['count'].")</a>";
	if($selected == $row['letter']){
          echo "<ul>";
            foreach(getAirfields($selected) as $field){
                echo "<li><a href='index.php?a=".$selected."&amp;f=".$field['user_id']."'>".$field['username']."</a></li>";
            }
	  echo "</ul>";
	}
	echo "</li>";
}
?>
Thanks in anticipation.
Kind Regards
Vince.

User avatar
benanamen
New php-forum User
New php-forum User
Posts: 23
Joined: Mon Oct 16, 2017 1:06 pm

Sun Nov 05, 2017 6:48 pm

What attempt have you made at understanding the code? Have you googled any of the coding words in the script to see what they mean?
The XY Problem
The XY problem is asking about your attempted solution (X) rather than your actual problem (Y). This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help.

VinceGledhill
New php-forum User
New php-forum User
Posts: 4
Joined: Sat Nov 04, 2017 8:56 am

Mon Nov 06, 2017 3:37 am

Thanks for that.

When I've visited forums in the past, I've usually gotten help.

Guess I made a mistake coming to this one.

chorn
php-forum Active User
php-forum Active User
Posts: 411
Joined: Fri Apr 01, 2016 2:18 am

Mon Nov 06, 2017 5:02 am

the mistake you made was thinking that "help" is a one-way road and you can lean back while others make your work.

thinsoldier
New php-forum User
New php-forum User
Posts: 24
Joined: Sat Dec 02, 2017 3:12 pm

Sat Dec 02, 2017 7:04 pm

VinceGledhill wrote:
Mon Nov 06, 2017 3:37 am
Thanks for that.

When I've visited forums in the past, I've usually gotten help.

Guess I made a mistake coming to this one.
Image

Post Reply