Canadian Posted February 15, 2010 Share Posted February 15, 2010 I have used the following select statement to get data from my database. $npn_count_query = "SELECT * FROM npn ORDER BY count DESC LIMIT 1"; $npn_count = $db->query($npn_count_query); I'm getting this when I echo $npn_count. Which is the pointer not the data. Object id #2 How do I extract the DATA from the pointer? Do I use something like... $data = $npn_count->fetch(); Any help would be greatly appreciated. Thanks Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted February 15, 2010 Share Posted February 15, 2010 How do I extract the DATA from the pointer? Do I use something like... $data = $npn_count->fetch(); I guess so. I cant tell you the exact method you need to use in order to extract your results from your query. You seem be using a database class object. What is the database class you're using? Is it a custom class or the built in mysqli class? Quote Link to comment Share on other sites More sharing options...
Canadian Posted February 15, 2010 Author Share Posted February 15, 2010 Oh trust me, at my level it's nothing custom. I'm 99% sure it's the built in mysqli class. I got it from the book "PHP and MySQL Web Development". I don't necessarily have to use OOP PHP. Is there an easier/better way to do this? Should I try using procedural PHP? If so any suggestions? Thanks again. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted February 15, 2010 Share Posted February 15, 2010 If you're reading the book it should be explaining to you how to use the mysqli class properly, maybe you skipped too far in the book or missed a chapter. If you're stuck at any time on how to use a PHP function then have read of the PHP manual on that particular function. So for all documention on mysqli is here. You can use the built in mysqli class or use mysqli procedurally. Quote Link to comment Share on other sites More sharing options...
Canadian Posted February 15, 2010 Author Share Posted February 15, 2010 Let me re-read the chapter tonight. Thanks guys. I'll follow up when I do. Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 15, 2010 Share Posted February 15, 2010 Try using fetch_object: $npn_count_query = "SELECT * FROM npn ORDER BY count DESC LIMIT 1"; $npn_count_result = $db->query($npn_count_query); $npn_count_dataObj = $npn_count_result->fetch_object(); echo $npn_count_dataObj->field1; echo $npn_count_dataObj->field2; echo $npn_count_dataObj->field3; Replace field1, field2, field3 with the field names from your database that you need to access. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.