Solved

php mysql out put data

Posted on 2016-11-29
4
19 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 83

Accepted Solution

by:
Dave Baldwin earned 167 total points
ID: 41906859
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 52

Assisted Solution

by:Julian Hansen
Julian Hansen earned 167 total points
ID: 41906880
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
ID: 41907054
+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
ID: 41907792
Thank you Dave, Julian and Ray. var_dump() is good idea Ray. I would remember next time. Thank you all.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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 four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
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.

910 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

21 Experts available now in Live!

Get 1:1 Help Now