Canadian Posted February 15, 2010 Share Posted February 15, 2010 I've spent the afternoon building a page that counts entries into a database. My table "key" is an auto increment column named "count". Here is what I am trying to do... I think the error is in the value I am receiving from my database but I don't know why. I will post my DB table below. 1. I'm querying the database for the last entry. $npn_count_query = "SELECT * FROM npn ORDER BY count DESC LIMIT 1"; $npn_count = $db->query($npn_count_query); 2. For testing purposes, I'm echoing $npn_count. For some reason I keep getting the following value for $npn_count regardless of what "count" actually is in the table. Object id #2 3. After that I'm using preg_match(). My goal is the following. IF the auto increment "count" ends in 9 "do something" ELSE "do something else". if (preg_match('/9$/', $npn_count)) { do something } else { do something else }; For some reason even when the "count" ends in 9 in the DB table, the IF statement always defaults to the ELSE. I'm guessing that is because my query keeps returning "Object id #2" Can anyone tell my why I keep getting a value of "Object id #2"? Thanks! Here is my DB table setup script. CREATE TABLE `npn` ( `count` int(12) NOT NULL auto_increment, `first_name` varchar(64) NOT NULL default '', `last_name` varchar(64) NOT NULL default '', `email` varchar(128) NOT NULL default '', `timestamp` timestamp NULL default NULL, `result` char( NOT NULL default '', PRIMARY KEY (`count`) ) ENGINE=MyISAM AUTO_INCREMENT=22 DEFAULT CHARSET=utf8 Link to comment https://forums.phpfreaks.com/topic/192094-my-query-is-lying-to-me/ Share on other sites More sharing options...
Psycho Posted February 15, 2010 Share Posted February 15, 2010 When you query a database, a result is created and what is returned is a resource identifier pointing to the result. So, when you run this: $npn_count = $db->query($npn_count_query); You get a pointer to the result - NOT the result itself. You are apparently using a class to do your database functions, so you should look into what methods you should be using to extract the database results. Link to comment https://forums.phpfreaks.com/topic/192094-my-query-is-lying-to-me/#findComment-1012397 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.