Solved

php mysql out put data

Posted on 2016-11-29
4
12 Views
Last Modified: 2016-11-30
Dear Experts,

I do it by heart ( memorized it ), I want to learn what $result variable do?

without while loop $result variable does not give anything, not even row number,

what does this variable do?

$sql = "SELECT * FROM ilan where uid='$uid'";
$result = $conn->query($sql);
0
Comment
Question by:Braveheartli
4 Comments
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 167 total points
Comment Utility
As mentioned on this page http://php.net/manual/en/mysqli.query.php ,  a 'mysqli' query returns a mysqli_result object  or FALSE on failure.  The mysqli_result object  is used to reference the query you made in the functions that follow.  It is not something that is used by itself.

Do Not memorize these things by heart, look them up.  In addition to the many basic PHP language features, there are an additional 1500 plus functions that are available.  They are all well documented at http://php.net/
1
 
LVL 51

Assisted Solution

by:Julian Hansen
Julian Hansen earned 167 total points
Comment Utility
When you run a query there are many potential actions you can take once it is complete. For instance - get a row which you may want as an object or an associative array. You may want to know how many rows were affected.

The $result variable is an instance of the mysqli_result class (as Dave pointed out) that gives access to the various functions you may want to perform on the result set.

As a value on its own it is only really usable on failure when it will be set to false or when the query() does not return data in which case it will be true.

If you are expecting data to be returned from the query you can do this
$result = $mysqli->query($query);
if ($result) {
   // query was successful so process result here
}
else {
   // report error
}

Open in new window

0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 166 total points
Comment Utility
+1 for Dave's recommendation to look up the examples in the documentation.  PHP is a living language, and there are features being added to it all the time.  If you read the man pages, you'll find out about these features and you'll see examples of how to use them.  I could not write code without having a window open to the online documentation at http://php.net!

Many examples of MySQL, MySQLi, and PDO are available here, with the scripts built in parallel construction so you can see how each extension accomplishes the same tasks.  In these examples I named the results variable $res.
https://www.experts-exchange.com/articles/11177/PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html

As a general rule, var_dump() is your friend.  It will not always expose everything about a variable (some things like SimpleXML_Element and PHP "resources" are hidden), but for any initial exploration, the first thing to do is use var_dump() and see what's in the variable.  There are examples in the article showing how to use var_dump() to visualize the results variable.

MySQL is a complicated thing, with a history that is sometimes nonlinear.  Information you need to provide or retrieve is often scattered across different objects.  Sometimes it's useful to look at the MySQLi object, and other times a statement or results object contains what you want.  The man pages, and var_dump(), can help you discern what is where.
0
 
LVL 1

Author Closing Comment

by:Braveheartli
Comment Utility
Thank you Dave, Julian and Ray. var_dump() is good idea Ray. I would remember next time. Thank you all.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now