PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE Persons ( PersonID int, LastName varchar(255), FirstName varchar(255) ); INSERT INTO Persons VALUES (1, 'Svensson', 'Anders'); SELECT * FROM Persons;
Copy Clear
Copy Format Clear
<?php $query = "SELECT * FROM Persons;"; // Run query using mysqli $result = $mysqli->query($query); $data = $result->fetch_assoc(); print("Efternamn: {$data['LastName']}"); print( "\n"); print($result->num_rows); print( "\n"); print(gettype($result)); print( "\n"); print($data[0]); print("\n"); echo '<pre>'; print_r($data); echo '</pre>'; print( "\n"); echo "<table>"; //while($row = mysqli_fetch_array($result)){ //Creates a loop to loop through results foreach ($result as $row){ echo "<tr><td>" . htmlspecialchars($row['PersonID']) . "</td><td>" . htmlspecialchars($row['LastName']) . "</td></tr>"; //$row['index'] the index here is a field name print( "\n"); } echo "</table>"; //Close the table in HTML //mysql_close(); //Make sure to close out the database connection
Show:  
Copy Clear