0% found this document useful (0 votes)
53 views3 pages

Colspan and Rowspan:: Example Mysql Table

This document contains code snippets demonstrating different PHP functions and concepts: 1) It shows how to properly escape quotes when outputting HTML elements to avoid syntax errors. 2) It displays an example HTML table with rowspan and colspan attributes. 3) It connects to a MySQL database, runs a query, and loops through the results to output the data. 4) It demonstrates various string functions like strlen(), substr_count(), and how they work with offsets and lengths. 5) It uses the list() function to extract elements from an array into separate variables.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views3 pages

Colspan and Rowspan:: Example Mysql Table

This document contains code snippets demonstrating different PHP functions and concepts: 1) It shows how to properly escape quotes when outputting HTML elements to avoid syntax errors. 2) It displays an example HTML table with rowspan and colspan attributes. 3) It connects to a MySQL database, runs a query, and loops through the results to output the data. 4) It demonstrates various string functions like strlen(), substr_count(), and how they work with offsets and lengths. 5) It uses the list() function to extract elements from an array into separate variables.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

<?

php
// This won't work because of the quotes around specialH5!
echo "<h5 class="specialH5">I love using PHP!</h5>";

// OK because we escaped the quotes with ! \


echo "<h5 class=\"specialH5\">I love using PHP!</h5>";

// OK because we used an apostrophe '


echo "<h5 class='specialH5'>I love using PHP!</h5>";
?>

<table border="1">
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<tr><td rowspan="2">Row 1 Cell 1</td>
<td>Row 1 Cell 2</td><td>Row 1 Cell 3</td></tr>
<tr><td>Row 2 Cell 2</td><td>Row 2 Cell 3</td></tr>
<tr><td colspan="3">Row 3 Cell 1</td></tr>
</table>

Colspan and Rowspan:


Column 1 Column 2 Column 3

Row 1 Cell 2 Row 1 Cell 3


Row 1 Cell 1
Row 2 Cell 2 Row 2 Cell 3

Row 3 Cell 1

example MySQL Table:


name age

Timmy Mellowman 23

Sandy Smith 21

Bobby Wallace 15
<?php
// Make a MySQL Connection

$query = "SELECT * FROM example";

$result = mysql_query($query) or die(mysql_error());


//The value that mysql_query() returns and stores into $result is a special type of data, it is a MySQL
Resource

while($row = mysql_fetch_array($result)){
echo $row['name']. " - ". $row['age'];
echo "<br />";
}
?>
Display:
Timmy Mellowman - 23
Sandy Smith - 21
Bobby Wallace – 15

<?php
$text = 'This is a test';
echo strlen($text); // 14

echo substr_count($text, 'is'); // 2

// the string is reduced to 's is a test', so it prints 1


echo substr_count($text, 'is', 3);

// the text is reduced to 's i', so it prints 0


echo substr_count($text, 'is', 3, 3);

// generates a warning because 5+10 > 14


echo substr_count($text, 'is', 5, 10);

// prints only 1, because it doesn't count overlapped subtrings


$text2 = 'gcdgcdgcd';
echo substr_count($text2, 'gcdgcd');
?>
<?php

$info = array('coffee', 'brown', 'caffeine');

// Listing all the variables


list($drink, $color, $power) = $info;
echo "$drink is $color and $power makes it special.\n";

// Listing some of them


list($drink, , $power) = $info;
echo "$drink has $power.\n";

// Or let's skip to only the third one


list( , , $power) = $info;
echo "I need $power!\n";

// list() doesn't work with strings


list($bar) = "abcde";
var_dump($bar); // NULL
?>

You might also like