Hi everyone,
I've just started using php, and although I am very impressed by it,
there are some things with which I am confounded!
What I'm trying to do is read in a Date from a mySql database and then
display it on screen (the Date is in the usual yyyy-mm-dd format).
If I use SQL on phpadmin
SELECT Date
FROM details
WHERE details.Name = "Paul Lee"
LIMIT 0 , 30
The result comes up 2005-01-01, so this seems to work.
But if I use the following:
$db = mysqli_connect("localhost","root","");
@mysqli_select_db($db, "personnel") or die ( "Unable to select
database" );
$query = 'SELECT Date FROM details WHERE details.Name = "Paul Lee"
LIMIT 0, 30';
$result=mysqli_query($db, $query);
echo "<br>";
echo $result;
mysqli_close($db);
I get "Object id #2" displayed on screen.
I have tried to use the explode function to separate the months, year
and day using the "-" as a delimeter, but this doesn't work, and I
can't seem to get the other php date/time functions to work either.
Thanks for your help
Paul 8 1982
*** pa**@paullee.com wrote/escribió (19 Jan 2005 07:23:33 -0800): $result=mysqli_query($db, $query); echo $result;
I get "Object id #2" displayed on screen.
From manual ( http://es2.php.net/mysqli_query):
Return Values
Returns TRUE on success or FALSE on failure. For SELECT, SHOW, DESCRIBE or
EXPLAIN mysqli_query() will return a result object.
So it's normally not a good idea to print an object: printing works fine
with strings, integers... but not with objects.
Just look at the examples on the page, they're pretty clear.
In any case, if you're learning PHP I suggest you forget (by now) about the
mysqli_* functions: they're rather recent and only work with PHP 5+ and
MySQL 4.1+ (not the most common scenery). Try mysql_* instead: http://es2.php.net/manual/en/ref.mysql.php
--
-- Álvaro G. Vicario - Burgos, Spain
-- Thank you for not e-mailing me your questions
--
Hi,
There were some historical reasons why we went for mysqli rather than
mysql...no one can recall what they are though!
I've modified the code to use mysql, but at the line:
$db = mysql_connect("localhost","root","");
I get:
Fatal error: Call to undefined function mysql_connect() in
d:\wamp\www\time.php on line 15
Hmmm....!
Paul
Hi,
There were some historical reasons why we went for mysqli rather than
mysql...no one can recall what they are though!
I've modified the code to use mysql, but at the line:
$db = mysql_connect("localhost","root","");
I get:
Fatal error: Call to undefined function mysql_connect() in
d:\wamp\www\time.php on line 15
Hmmm....!
Paul
Incidentally, I can use mysqli_ ... to connect to a mysql database and
retrieve string data, such as Names etc. Incidentally, I can use mysqli_ ... to connect to a mysql database
and retrieve string data, such as Names etc.
I don't get it. In your original post you give an example of code that
does not display anything from a database, string or otherwise (and
could not because it is incomplete).
Here you are saying that you CAN retrieve string data successfully.
Could you give us some sample code that DOES work for you, so we can
compare it with the code that doesn't work for you.
---
Steve
Alright. This works:
$db = mysqli_connect("localhost","root","");
@mysqli_select_db($db, "personnel") or die ( "Unable to select
database" );
$query="SELECT * FROM details";
But this doesn't:
$db = mysqli_connect("localhost","root","");
@mysqli_select_db($db, "personnel") or die ( "Unable to select
database" );
$query = 'SELECT Date FROM details WHERE details.Name = "Paul Lee"';
Paul
> $query = 'SELECT Date FROM details WHERE details.Name = "Paul Lee"';
Depends on what "doesn't work" means, and we'd have to see the rest of
your code (the bit that tries to use the returned result) to be sure,
but one possible problem is that you have mixed-case columns names in
this SELECT - you will have to refer to them using the exact name you
gave in the SELECT statement, otherwise PHP will not find them in the
associative array.
---
Steve This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dariusz |
last post by:
I have PHP code (below) which reads data from a MySQL format database. The
problem I am having is trying to find out when the last ID entry was made.
When the script is executed, the $gbID is...
|
by: John |
last post by:
I have over 5000 thumbnail pictures of size 5kb each. I would like to
able to load all 5000 pictures and view 50 per page using
mysql_data_seek(). I would like to know what are the advantages and...
|
by: Paul Beckett |
last post by:
I have successfully used strtotime to format the date on a webpage that is
pulled form a MySQL database in the form yyyy-mm-dd.
However, in another part of the webpage, I have to insert another...
|
by: Dariusz |
last post by:
Below is part of a code I have for a database. While the database table is
created correctly (if it doesn't exist), and data is input correctly into
the database when executed, I have a problem...
|
by: DaRemedy |
last post by:
Hiya,
If I had several folders full of images, how can I get PHP to open the
folder, read the image names and save the image names (inc extension) to a
MySQL database?
What I am trying to do...
|
by: Dave Posh |
last post by:
I seem to be having a problem displaying time stored in mysql. The
format stored in the database is 13:15:05. The database data type is
time. I'm using asp vbscript and sql to retrieve the time...
|
by: Panna |
last post by:
Hey there
I am using phpMyAdmin and MySQL to develop a dbase application.
I have a dropdown menu on one of the pages which gets populated automatically with data from a table in the database....
|
by: Colleen Robledo, MLIS |
last post by:
Hello,
I'm still pretty new to PHP and MySQL, and have a PHP scripting
question.
If I'm querying DATE info from a MySQL database, and displaying it
with PHP echo statements... is there a PHP...
|
by: janetopps |
last post by:
I have a news website, with asp pages, which was on Access, and i upgraded to MySQL, i used Bullzip to transfer the data. It had about 1000 pages, which im now able to pull up on the public side. Im...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |