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
Solved

php mysql out put data

Posted on 2016-11-29
4
23 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 55

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 109

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

828 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