On Mon, 25 Jun 2012, B. Aerts wrote:
On 17/06/12 21:06, Ethan Rosenberg wrote:
Dear List -
I have a database:
+---------------------+
| Tables_in_hospital2 |
+---------------------+
| Intake3 |
| Visit3 |
+---------------------+
Hey Ethan --
Remember that your posts are archived likely forever, and using dummy data
like "Bongish" and being critical of people's weight probably isn't going
to help you when you decide to seek a job somewhere.
Also, for people replying, before offering advice about MySQL on a PHP
list, it is good practice to actually run your queries to verify your
suggestions. Most of the replies thus far have been conjecture, with only
one or two reasonable data-backed voices.
Those voices asked: "What are you doing with $result?" How you answer is
important. If you are simply printing it with hopes that $result contains
data, the suggestion to "RTFM" is vital, as that would be wrong.
Those voices also stated "'where 1' just evaluates to true." They are
correct and proven here (42 intentional :-) ):
mysql> select count(*) from numbers where 1=1 and num like '1212%';
+----------+
| count(*) |
+----------+
| 42 |
+----------+
1 row in set (0.26 sec)
mysql> select count(*) from numbers where 1 and num like '1212%';
+----------+
| count(*) |
+----------+
| 42 |
+----------+
1 row in set (0.02 sec)
mysql> select count(*) from numbers where num like '1212%';
+----------+
| count(*) |
+----------+
| 42 |
+----------+
1 row in set (0.02 sec)
So Ethan, if your query works on the command line, but not in your code,
where do you think the issue might exist?
http://us3.php.net/manual/en/mysqli.query.php
Return Values
Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or
EXPLAIN queries mysqli_query() will return a mysqli_result object. For
other successful queries mysqli_query() will return TRUE.
Granted, the PHP manual doesn't include *how* to loop through return data.
http://us3.php.net/manual/en/class.mysqli-result.php
Ethan, your question was: why does this work on the command line, and not
through PHP.
The remarks by other posters still stand - you don't show anything that leads
us to discriminate wether the fault lies in the query, in the API's or in the
code.
If you're not going to show it, maybe try the following 2 tips :
1) try to modify the query: "SELECT . . . WHERE 1=1 ; " : this formulation
removes any doubt wether it is a filtering statement, or a result limiting
statement
2) see if " SELECT . . . WHERE 2" or " SELECT . . . WHERE 3 " yields
respecively 2 or 3 result rows. If not, the problem is NOT with the API's.
I'll save you some time, it's not the "where 1" part of the query:
mysql> select count(*) from numbers where 3 and num like '1212%';
+----------+
| count(*) |
+----------+
| 42 |
+----------+
Beckman
---------------------------------------------------------------------------
Peter Beckman Internet Guy
beckman@xxxxxxxxxxx http://www.angryox.com/
---------------------------------------------------------------------------
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php