Connect To Database & Perform SQL Query

Hello!
Just really quick, yesterday marked my first day dealing with php and I am really lost!!

I am at this point attempting to create a page that displays the fields in a table. All I want to see for now is all entries (SELECT * FROM Public_Official_Ratings) and display them on the page. I watched a lot of tutorials yesterday and anything like this just would not work. It always displays the page as blank or white.

I just want to see the above process work for now. But the plan is to display all Public Officials that have been entered and then (AVERAGE) the rating column. What should happen is a user gets to the page and then sees a picture of the Public Official and a brief Description then they would rate 1 - 10. Then I would display the average rating.

The database that I’m using is hosted locally. Login Credentials: Localhost, U/N: root, P/W: root, Database: Rate

Currently I’m using the following tools on my MAC: MAMP FREE. PHPMYADMIN(Database Location), Dreamweaver CC 2015.

Folder Locations: Applications/MAMP/htdocs/Website/Rating.php

Database Layout:
Database Name: Rate
Table 1: Public _Officials
Field 1: ID (INT,11, Primary Key, A_I), Field 2: Public_Official_Name (VARCHAR, 255)
Table 2: Public_Official_Rating
Field 1: ID (INT,11, Primary Key, A_I), Field 2: Public_Official_Name (VARCHAR,255), Field 3: Rating (INT, 11)

Rate.php File Code:
[php]<?php
//Connect
$mysqli = NEW MySQLi(‘localhost’,‘root’,‘root’,‘rate’);

//Query Database
$ResultSet = $MySQLi->query(“SELECT * FROM Public_Official_Ratings”);

//Count Returned
if($ResultSet->num_rows !=0){

//Result Array
While ($rows = $ResultSet->Fetch_Assoc())
{
$ID = $rows[‘ID’];
$PON = $rows[‘Public_Official_Name’];
$Rating = $rows[‘Rating’];
echo “

Name: $PON $Rating
ID: $ID

”;
}

//Display Results
}else{
echo “No Results.”;
}
?>[/php]

Thanks So Much,
Bdenn

First, turn error reporting on. Next, quit arbitrarily capitalizing things. Fetch_Assoc is not the same as fetch_assoc, nor is While the same as while.

Lastly, get rid of dreamweaver and use a real editor.

Thanks for the information.

Sponsor our Newsletter | Privacy Policy | Terms of Service