[Chugalug] Newbie question

Tyler Mittan flashbatmanquestion at gmail.com
Sun Aug 18 22:24:06 UTC 2013


I used print_r and I got this:
Array ( [0] => Array ( [year] => 2013 [0] => 2013 [make] => Ford [1] =>
Ford [model] => Fusion [2] => Fusion [color] => White [3] => White [price]
=> 20000.00 [4] => 20000.00 ) [1] => Array ( [year] => 2013 [0] => 2013
[make] => Acura [1] => Acura [model] => NSX [2] => NSX [color] => black [3]
=> black [price] => 20000.00 [4] => 20000.00 ) [2] => Array ( [year] =>
2013 [0] => 2013 [make] => Audi [1] => Audi [model] => A4 [2] => A4 [color]
=> Black [3] => Black [price] => 30000.00 [4] => 30000.00 ) [3] => Array (
[year] => 2013 [0] => 2013 [make] => Audi [1] => Audi [model] => S5 [2] =>
S5 [color] => Black [3] => Black [price] => 40000.00 [4] => 40000.00 ) [4]
=> Array ( [year] => 2013 [0] => 2013 [make] => Tesla [1] => Tesla [model]
=> Model S [2] => Model S [color] => Black [3] => Black [price] =>
100000.00 [4] => 100000.00 ) )

at least that shows it as an array, though. That makes me think maybe it's
the coding from the table. I changed took out the FETCH_OBJ and just left
it empty, but it's still just returning one from the table as opposed to
the remaining few. I also changed it from -> to ['']


On Sun, Aug 18, 2013 at 6:06 PM, Randy Yates <lpcustom at gmail.com> wrote:

> Also, I've not used PDO::Fetch_OBJ. I'm not sure it works correctly with
> fetchAll(). It's a normal parameter of fetch() but that only gets one row.
> I typically just use fetchAll() which will return an array and then you can
> loop through that like you have it. You'll just have to change your object
> syntax to array syntax. So instead of entry->make you'd use entry['make'].
>
>
> On Sun, Aug 18, 2013 at 6:02 PM, Randy Yates <lpcustom at gmail.com> wrote:
>
>> After you save the results to the $results variable, do:
>> print_r($results);
>>
>> or
>>
>> var_dump($results);
>>
>> I know you are learning, that's why I suggested that you learn about
>> mysql users and privileges. You never want to access a database with the
>> root user from a web app, just like you would never want to use root to log
>> into a linux desktop environment.
>>
>>
>>
>> On Sun, Aug 18, 2013 at 5:59 PM, Randy Yates <lpcustom at gmail.com> wrote:
>>
>>> That's not an array. You are fetching objects.
>>>
>>>
>>> On Sun, Aug 18, 2013 at 5:51 PM, Tyler Mittan <
>>> flashbatmanquestion at gmail.com> wrote:
>>>
>>>> Thanks, Randy. I am just trying to get the hang of php and mysql. When
>>>> I get a better handle on it, I will really challenge myself. Clearly,
>>>> though, I don't have that great of a grip on it yet, but I am working on
>>>> it! I made sure that E_ALL is set, and I made it display errors on the
>>>> php.ini
>>>>
>>>> Do I need to create the actual array in one of the php files or will
>>>> the fetchall function do that? Maybe that's why I am having such a hard
>>>> time. If you need to see the code, it's pretty much the same, but I updated
>>>> the last pastebin:
>>>> http://pastebin.com/LUMDKejf
>>>>
>>>>
>>>> On Sun, Aug 18, 2013 at 5:25 PM, Randy Yates <lpcustom at gmail.com>wrote:
>>>>
>>>>> If you are selected everything in the table, it should work. You can
>>>>> run the fetchAll() without an argument and it will return an array. I'd
>>>>> have to see your code to see why it's not working.
>>>>>
>>>>> You should also get in the habit of creating a user specifically for
>>>>> the database, instead of using the root user. Throwing root at it is easy,
>>>>> but force yourself to do the tedious stuff. Create a database user and
>>>>> grant it privileges to just that database.
>>>>>
>>>>> Also check your php.ini and see what the error_reporting is set to.
>>>>> You may want to set it to show more information so that you can debug your
>>>>> code easier. If it's not already, set it to E_ALL
>>>>>
>>>>>
>>>>> On Sun, Aug 18, 2013 at 5:18 PM, Tyler Mittan <
>>>>> flashbatmanquestion at gmail.com> wrote:
>>>>>
>>>>>> I am trying to use a foreach loop, but it's not showing the entire
>>>>>> database. Is this because I incorrectly used fetchall?
>>>>>>  On Aug 18, 2013 4:47 PM, "Tyler Mittan" <
>>>>>> flashbatmanquestion at gmail.com> wrote:
>>>>>>
>>>>>>> THANK YOU!
>>>>>>> On Aug 18, 2013 4:43 PM, "Randy Yates" <lpcustom at gmail.com> wrote:
>>>>>>>
>>>>>>>> On the second problem, your connection string for PDO is incorrect.
>>>>>>>> You are missing "dbname=" before the variable containing your database name.
>>>>>>>>
>>>>>>>>
>>>>>>>> On Sun, Aug 18, 2013 at 4:21 PM, Tyler Mittan <
>>>>>>>> flashbatmanquestion at gmail.com> wrote:
>>>>>>>>
>>>>>>>>> Finally got that problem fixed. Wanted to thank you guys for
>>>>>>>>> bearing with me. The problem was just working on Android. I am not sure the
>>>>>>>>> specific problem, but I moved over to OS X and that problem is gone. I do
>>>>>>>>> have another issue I was wondering if somebody might be able to help. Two
>>>>>>>>> actually:
>>>>>>>>>
>>>>>>>>> http://pastebin.com/cvssKyYj <--- no errors come up on this one,
>>>>>>>>> really. The problem is that when I just try to add to the database, I am
>>>>>>>>> getting the else statement. I guess it's just part of my coding.
>>>>>>>>>
>>>>>>>>> http://pastebin.com/Vw3rMBKs <-- gives me the error "*Fatal error*:
>>>>>>>>> Call to a member function fetchAll() on a non-object in *
>>>>>>>>> /Applications/MAMP/htdocs/inventorylist.php* on line *11" but I
>>>>>>>>> though I was referring to everything I needed to be that was defined.
>>>>>>>>> *
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Sat, Aug 17, 2013 at 3:32 PM, Dave Brockman <dave at brockmans.com
>>>>>>>>> > wrote:
>>>>>>>>>
>>>>>>>>>> -----BEGIN PGP SIGNED MESSAGE-----
>>>>>>>>>> Hash: SHA1
>>>>>>>>>>
>>>>>>>>>> On 8/17/2013 1:45 PM, Tyler Mittan wrote:
>>>>>>>>>> > Okay, I created it. What should I do with it now?
>>>>>>>>>> >
>>>>>>>>>>
>>>>>>>>>> Execute it in a browser.  Peruse it.  These are your PHP
>>>>>>>>>> environmental
>>>>>>>>>> settings.  Which libraries are active, location of INI file,
>>>>>>>>>> memory
>>>>>>>>>> limits, all kinds of fun things.  I'm pretty sure it will answer
>>>>>>>>>> at
>>>>>>>>>> least one other question posted to you.
>>>>>>>>>>
>>>>>>>>>> Regards,
>>>>>>>>>>
>>>>>>>>>> dtb
>>>>>>>>>> -----BEGIN PGP SIGNATURE-----
>>>>>>>>>> Version: GnuPG v2.0.17 (MingW32)
>>>>>>>>>> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
>>>>>>>>>>
>>>>>>>>>> iQEcBAEBAgAGBQJSD8+5AAoJEMP+wtEOVbcdfvUIAJRD7U6VyXR7nTkvNHhS8ZXs
>>>>>>>>>> o1J/jWB9OXIqFlYXMxjXVODnt+MQTILpKtivf5k+XJNr3vWjYjlrFIXxLPAX9ZRv
>>>>>>>>>> t73OO/EGZzQRK8I6kTjIAbZjWoc9PNBNVgzLPiZRqr5XKUoT1YiI1+sy6wk1pvPs
>>>>>>>>>> 4PJXC9OgoyRDjqDjyNEgzr59VTmaNx3UwzzS0n6XMcNWtv1VnxoDdhg+0hApJJzs
>>>>>>>>>> kosrnsKj22hzlVcguiF2zp19nclDwcVufK5LjFKZMrwGmoSB22hHPwOP3yLlJ4lX
>>>>>>>>>> i2/J7KHhu+waKXgQzLd8xG44otspXynXxN8wtLWUkEfpiHCjYrvsb+PcxYZQcsg=
>>>>>>>>>> =Qob9
>>>>>>>>>> -----END PGP SIGNATURE-----
>>>>>>>>>> _______________________________________________
>>>>>>>>>> Chugalug mailing list
>>>>>>>>>> Chugalug at chugalug.org
>>>>>>>>>> http://chugalug.org/cgi-bin/mailman/listinfo/chugalug
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> _______________________________________________
>>>>>>>>> Chugalug mailing list
>>>>>>>>> Chugalug at chugalug.org
>>>>>>>>> http://chugalug.org/cgi-bin/mailman/listinfo/chugalug
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> Google reads my email!
>>>>>>>>
>>>>>>>> _______________________________________________
>>>>>>>> Chugalug mailing list
>>>>>>>> Chugalug at chugalug.org
>>>>>>>> http://chugalug.org/cgi-bin/mailman/listinfo/chugalug
>>>>>>>>
>>>>>>>>
>>>>>> _______________________________________________
>>>>>> Chugalug mailing list
>>>>>> Chugalug at chugalug.org
>>>>>> http://chugalug.org/cgi-bin/mailman/listinfo/chugalug
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Google reads my email!
>>>>>
>>>>> _______________________________________________
>>>>> Chugalug mailing list
>>>>> Chugalug at chugalug.org
>>>>> http://chugalug.org/cgi-bin/mailman/listinfo/chugalug
>>>>>
>>>>>
>>>>
>>>> _______________________________________________
>>>> Chugalug mailing list
>>>> Chugalug at chugalug.org
>>>> http://chugalug.org/cgi-bin/mailman/listinfo/chugalug
>>>>
>>>>
>>>
>>>
>>> --
>>> Google reads my email!
>>>
>>
>>
>>
>> --
>> Google reads my email!
>>
>
>
>
> --
> Google reads my email!
>
> _______________________________________________
> Chugalug mailing list
> Chugalug at chugalug.org
> http://chugalug.org/cgi-bin/mailman/listinfo/chugalug
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://chugalug.org/pipermail/chugalug/attachments/20130818/09e974e7/attachment.html>


More information about the Chugalug mailing list