Schaarschmidt Posted July 6, 2012 Share Posted July 6, 2012 I am an absolute novice to PHP and am following a tutorial in the Sitepoint book PHP Novice to Ninja. When I followed everything exactly, it worked. Now I'm working through again using my own files and names and am absolutely stuck on my last line of code. I clearly don't understand something. I am trying to retrieve data from my mySQL database. The code in the tutorial is: { $jokes[] = array ('id'=>$row['id'], 'text' => $row['joketext']); } When I was using their data, that worked just fine. Now I'm trying to make it work with my data. Here is the code I'm using now: while ($row = $result->fetch()) { $parks[] = array('id' => $row['A'], 'text' => $row['B']); } The columns in my database are called A and B What am I doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/265323-problem-with-creating-an-array-from-fetched-data/ Share on other sites More sharing options...
Pikachu2000 Posted July 6, 2012 Share Posted July 6, 2012 What am I doing wrong? Hard to tell without a description of the actual problem, the error messages, etc. Quote Link to comment https://forums.phpfreaks.com/topic/265323-problem-with-creating-an-array-from-fetched-data/#findComment-1359698 Share on other sites More sharing options...
jcbones Posted July 6, 2012 Share Posted July 6, 2012 How do you know it isn't working? Do you have error_reporting and display errors on full in your php.ini? It should be for development. Of course you can set these at runtime with. error_reporting(-1); ini_set('display_errors',1); Now on to your particular problem. Does the book use mysqli or just mysql? I cannot tell with your snippet. I am assuming that you are using mysqli as you didn't define the fetch properties for PDO (they both have a fetch() method). So, did you bind the results prior to calling the fetch() method? It would be easier to help you if you posted the entire script you are working with. Minus any passwords or usernames of course. Quote Link to comment https://forums.phpfreaks.com/topic/265323-problem-with-creating-an-array-from-fetched-data/#findComment-1359702 Share on other sites More sharing options...
Schaarschmidt Posted July 6, 2012 Author Share Posted July 6, 2012 Thanks for your attempt at help. I feel like I don't even know enough to ask intelligent questions. Sometimes I feel like I'm going to be great at this, and sometimes I feel too dumb even to speak. However, in this case, I was actually able to identify the problem. I was asking for information from an associative array, but earlier I was only defining one parameter of the association. I'm sure that I'll be able to say all of this in a way that makes sense at some point, but at least at this point I'm past this and off to other problems. In the future I'll be sure to post the entire script and try to be more specific in my question. Thanks again for your help. Quote Link to comment https://forums.phpfreaks.com/topic/265323-problem-with-creating-an-array-from-fetched-data/#findComment-1359708 Share on other sites More sharing options...
jcbones Posted July 6, 2012 Share Posted July 6, 2012 No problem, we all start somewhere. Cheers, Happy Coding, JC Quote Link to comment https://forums.phpfreaks.com/topic/265323-problem-with-creating-an-array-from-fetched-data/#findComment-1359714 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.