Skip to content

codeadamca/php-big-picture

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

A Basic Introduction to PHP and MySQL

A basic walkthrough of using PHP to display content from a MySQL database.

This walkthrough is meant to illustrate the process of using PHP to display database content in an HTML web page. This is not meant to be a tutorial, more of a quick example of the end goal of these series of PHP tutorials.

Code Explanation

This block of code will connect our PHP file to the MySQL database:

<?php 

$connect = mysqli_connect( 'localhost', 'root', 'root', 'sandbox' );

?>

This block of code will execute an SQL query and display the result using basic HTML:

<?php

// Select all records from the topics table
$query = 'SELECT *
  FROM topics
  ORDER BY name';
$result = mysqli_query( $connect, $query );

// Loop through each record
while( $record = mysqli_fetch_assoc( $result ) )
{

  // Display each record
  echo '<hr>';
  echo '<h2>'.$record['name'].'</h2>';
  echo '<a href="'.$record['website'].'">'.$record['website'].'</a>';
  echo '<br>';
  echo '<img src="'.$record['image'].'">';

}

?>

Full tutorial URL:
https://codeadam.ca/learning/php-big-picture.html


Repo Resources


About

A basic walkthrough of using PHP to display content from a MySQL database.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages