Skip to main content

Posts

Showing posts from February, 2022

How to Link to a Specific Part of a Page Using Anchors Links in HTML

Anchor Links are links that link to a specific part of a page. These are useful when you want the user to easily skim-read through a page or when the page is long, or both. Wikipedia, like many other websites, uses anchor links as you can see in the following video: You need two HTML elements for Linking to a specific part of the page - the link itself and the page section marked by what we call a named anchor. Anchor Link We create the hyperlink using the HTML   <a> tag with the href attribute linking containing #anchor-name . The # tells the browser that this is an anchor link <a href="#anchor-name">Anchor Link</a> Page Section Anchor We can mark any part of the page by providing id attribute to any of the elements. Usually, we create anchor links to headings as they section the page into various parts but you can create named anchors for any elements. <h2 id="anchor-name">Heading</h2> Do remember id by definition have to be uniq

How to Fetch Data from MySQL Database in PHP and Display in Table

This is going to be the second part of the tutorial on how to save and retrieve data from a MySQL database in PHP. In the last post, we learned how to create an HTML form and link in with a database in PHP . In this tutorial, we will learn how to fetch the saved information from the database and display it in a nice HTML table. MySQL Table The database backend (MySQL table) is the common part that this tutorial will share with the last one. If you recall, the database phonebook consisted of just one table table1  which contained the following fields or columns: id, fname, lname, phonenumber, email . PHP Script (show.php) The following code retrieves the data and shows it in a table, the code with the comments is pretty self-explanatory: <?php define ( 'DB' ,  'phonebook' ); define ( 'DB_HOST' ,  'localhost' ); define ( 'DB_USER' ,  'db_user' ); define ( 'DB_PASS' ,  'db_pass' ); define ( 'DB_TABLE' ,  '

How to Remove Bullet Points in CSS

This will be a short guide on how to remove bullet points from ordered/unordered lists with CSS, you only need two lines of CSS for this. The first removes the actual bullet points and the second one removes the space to the left, as evident from the following video: We'll also be doing some bullet beautification in the last section if that's what you are looking to do. How to Remove Bullet Points in HTML/CSS Now that we know what CSS properties actually accomplish what we want let's see how we can implement this in our HTML code. Using Inline "style" Tag (The quick and dirty way) As the title suggests, this is the quickest way to remove bullet points in which you wouldn't have to edit any CSS files (for example, for Blogger or WordPress). This method would be useful for a one-off case - just add the following " style " attribute to the list you want to remove the bullet points from: <h1>Ordered List</h1> <ol  style="list-styl

The Best Way(s) to Comment out PHP/HTML Code

PHP supports various styles of comments. Please check the following example: <?php // Single line comment code (); # Single line Comment code2 (); /* Multi Line comment code(); The code inside doesn't run */ // /* This doesn NOT start a multi-line comment block /* Multi line comment block The following line still ends the multi-line comment block //*/ The " # " comment style, though, is rarely used. Do note, in the example, that anything (even a multi-block comment /* ) after a " // " or " # " is a comment, and /* */ around any single-line comment overrides it. This information will come in handy when we learn about some neat tricks next. Comment out PHP Code Blocks Check the following code <?php //* Toggle line if ( 1 ) {      // } else {      // } //*/ //* Toggle line if ( 2 ) {      // } else {      // } //*/ Now see how easy it is to toggle a part of PHP code by just removing or adding a single " / " from th

How to Create an HTML Form Linked with MySQL Database in PHP

If you're looking for example code and detailed discussion on how to create an HTML form that stores data in a MySQL database using PHP then this post might be what you're looking for. I assume that you're familiar with basic HTML, CSS, PHP coding, and  MySQL. I am going to divide this small project into two parts: The HTML form itself that takes input from the user and the PHP script that saves it into the database A table that displays the user-added data that has been saved in the database. We'll be dealing with the first part in this tutorial. Again I'd like to break this problem into a few parts so that it's easier for you to understand and probably gives you an insight into how breaking up a problem into smaller chunks can help make things clearer in your mind. Let's think about it, there is an HTML form (that is HTML code), then there is the PHP code that deals with the user-input data, and the MySQL database itself. For this tutorial, we'll b