Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Could someone please explain this to me?

Posted on 2009-02-20
5
Medium Priority
?
224 Views
Last Modified: 2012-05-06
Specifically, I don't under stand what these rows are supposed to be doing.

what is the <?= for?

Is this PHP,javascript,...

<h2><?= $data_row->title ?></h2>
<p><?= $data_row->body ?></p>
<?php
	# Dataset ID is present
	if ( !empty( $id ) ) {
		# Get data from database and print out
		$query = mysql_query( "SELECT * FROM ". DBTABLE ." WHERE id=$id", $db_server );
		if ( mysql_numrows( $query ) == 1 ) {
			$data_row = mysql_fetch_object( $query );
			?>
<h2><?= $data_row->title ?></h2>
<p><?= $data_row->body ?></p>

Open in new window

0
Comment
Question by:ISHUC
5 Comments
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 600 total points
ID: 23693017
<? ... some php code ?>
is the short opening tag of
<?php ... some php code >?

the same code could read:
<?php
      # Dataset ID is present
      if ( !empty( $id ) ) {
            # Get data from database and print out
            $query = mysql_query( "SELECT * FROM ". DBTABLE ." WHERE id=$id", $db_server );
            if ( mysql_numrows( $query ) == 1 ) {
                  $data_row = mysql_fetch_object( $query );
                  print "<h2>{$data_row->title}</h2><p>{$data_row->body}</p>";

Open in new window

0
 
LVL 8

Assisted Solution

by:agamal
agamal earned 200 total points
ID: 23693163
this is php code

<h2><?= $data_row->title ?></h2>

can be

<h2><?php echo  $data_row->title ?></h2>
0
 

Author Comment

by:ISHUC
ID: 23693197
I am trying to run this in PHP5 which I understand that needs to use mysqli instead of mysql commands.  Is the $data_row->title usable in PHP5 or do I need to use the mysqli with an execute command?
0
 

Author Comment

by:ISHUC
ID: 23693249
I mean extract() not execute()
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 1200 total points
ID: 23700881
Here it is, with query error checking and some comments in the code.

MySQL is fine with PHP5 - you can choose MySQLi, but it is not required.

You do not need to use the extract() statement.  The OOP notation is OK.

Let us know if you have any more questions, ~Ray
<?php
// IF THE $id VARIABLE IS NOT EMPTY
if ( !empty( $id ) ) 
{
 
// CONSTRUCT A QUERY
$query  = "SELECT * FROM DBTABLE WHERE id=$id";
 
// EXECUTE THE QUERY
$result = mysql_query( $query, $db_server );
 
// TEST FOR QUERY SUCCESS - SHOW ERROR IF NOT SUCCESSFUL
if (!$result)
{
   echo "<br/>QUERY FAIL: $query \n";
   echo mysql_errno();
   echo mysql_error();
   die();
}
 
// IF AND ONLY IF THERE WAS EXACTLY ONE ROW FOUND
if ( mysql_numrows( $query ) == 1 ) 
{
 
// GET THE RESULTS SET IN AN OBJECT NAMED $data_row
// NOTE THE CODE ASSUMES THAT title AND body ARE FIELDS IN THE RESULTS SET
   $data_row = mysql_fetch_object( $result );
?>
<h2><?=$data_row->title ?></h2>
<p><?=$data_row->body ?></p>
<? }

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses
Course of the Month21 days, 1 hour left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question