?
Solved

php mysql out put data

Posted on 2016-11-29
4
Medium Priority
?
28 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 668 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 58

Assisted Solution

by:Julian Hansen
Julian Hansen earned 668 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 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 664 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

770 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