PHP
<?php echo "Hello World!"; ?> //You can use the short echo tag to <?= 'print this string' ?>. //It's always enabled in PHP 5.4.0 and later, and is equivalent to <?php echo 'print this string' ?>. //PHP statements end with a semicolon (;).
//get current server/domain $domain = $_SERVER['SERVER_NAME']; <?php $t1 = "Are you looking for "; $t2 = ' ?'; echo "$t1"; echo $page["searchterm"]; echo "$t2"; ?>
// DB connection
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
//print_r() displays information about a variable in a way that’s readable by humans. <pre> <?php print_r ($url); ?> </pre> // print more variable <pre> <?php print_r ($projectState . $projectLocation); ?> </pre>
//Show data or row
<?php if(!empty($profile->field_is_miid_registered->value())): ?>
<?php if(!empty($data['field_is_miid_registered'])): ?>
<?php if(!empty($row['field_is_miid_registered'])): ?>
//include
<?php include_once("sites/templates/includes/header.inc.php"); ?>
//copy item with php
<div>
<?php for($i = 0; $i < 3; $i++): ?>
<div class="item news col-lg-4 col-sm-6">
<div class="primary">
<div class="overlay-card">
<a class="blocky" href="#"></a>
</div>
<div class="image-placeholder"></div>
<img class="image" src="https://i.imgur.com/OXmtSsO.jpg">
</div>
<div class="content">
<div class="tag">
BEST BATH SPACE - PROFESSIONALS
</div>
<a href="#">
<h4 class="title">Modern take on mid century Masterbath.</h4>
</a>
<a href="#" class="news-author">Submitted by Limor Pinz Interior Design</a>
</div>
</div>
<?php endfor; ?>
</div>
//row and data
<?php print $row['title']?>
<?php print $data->title->value();?>
Get value of MySQL column and external string combined
PHP
<?php
$results = db_query("select v.developer_name,v.price_desc,v.project_location,v.client_logo,v.client_img,v.project_url,v.project_name from vpex v ORDER BY RAND() LIMIT 9 ");
$social_link = 'https://zing.my';
$externalString = 'http://s3-ap-southeast-1.amazonaws.com/www.theedgeproperty.com.my/vpex/';
?>
HTML
<a href="https://www.facebook.com/sharer/sharer.php?u=<?php print $social_link . url('node/'.$row['nid']) ?>&text=<?php print $row['title']?>" onclick="window.open(this.href, 'sharer-popup-facebook', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,left=383,top=34,width=600,height=600'); return false;">
<li class="facebook">
<i class="fa fa-facebook" aria-hidden="true"></i>
</li>
</a>
<?php print url('node/'.$row['nid']) . ' - ' . $row['title'] ?>
<img src="<?php echo $externalString . $row['client_logo'] ?>">
//PHP Limit Data From MySQL //SQL query to select all records from 1 – 30 (inclusive) from a ‘Project_name’ table $sql = "SELECT * FROM Project_name LIMIT 30"; //To select >start on record records 30 – 40 (inclusive) AND return only 10 records: $sql = "SELECT * FROM Project_name LIMIT 10 OFFSET 29";
//timestamp
<?php
if($project['updated'] > 0 ){
$update = date('d M',$project['updated']);
$timeago = ($project['updated'] > (time() - (60*60*24*4)))?'timeago':'simple-time';
$machine_date = date("Y-m-d\TH:i:s",$project['updated']).'+08:00';
}
?>
//The value to be use in the HTML
<time class="<?php echo $timeago;?>" datetime="<?php echo $machine_date;?>"><?php print($update); ?></time>
//link
//HTML in PHP :
echo "<a href='".$link_address."'>Link</a>";
//Or even you can try like
echo "<a href='$link_address'>Link</a>";
//PHP in HTML :
<a href="<?php echo $link_address;?>"> Link </a>
//example
Are you looking for <a href="/search-property?"><?php echo $page["searchterm"]; ?></a> ?
<h3>
<a href="<?php echo get_term_link( $category ); ?>"><?php echo $category->name; ?></a>
</h3>