(MySQL) Selecting Data from Multiple Rows of a Single Column Using PDO
Posted by: SocQS (---.dsl.irvnca.pacbell.net)
Date: February 24, 2013 08:50AM

I'm trying to select the data held in column x of every row where column y equals someString. If you could imagine a table with 2 columns (Column1, Column2) and the following entries:

Column1-----Column2

Chuck--------tiger
Chuck--------lion
Matt---------elephant

From this table I would want all the data from Column2 where Column1 equals Chuck (i.e. tiger and lion). When I run my code only the data from the first instance of Chuck (where Column2 is tiger) is retrieved. What code can I use to retrieve both the tiger and lion values?

Here is my code thus far (minus some bits impertinent to this post):

$prepared = $database->prepare("SELECT Column2 FROM DatabaseName WHERE Column1 = Chuck"winking smiley;
$prepared->execute();
$toReturn = $prepared-> fetch(PDO::FETCH_ASSOC);
return $toReturn;

Thanks

Edit-Smiley face is unintentional; should be a )



Edited 1 time(s). Last edit at 02/24/2013 08:53AM by SocQS.

Options: ReplyQuote
Re: (MySQL) Selecting Data from Multiple Rows of a Single Column Using PDO
Posted by: stevenmartin99 (Moderator)
Date: February 24, 2013 08:54AM

THIS IS NOT A SITE FOR CODING HELP!!!!

this is basic basic stuff you are looking for. DO A GOOGLE SEARCH!

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: (MySQL) Selecting Data from Multiple Rows of a Single Column Using PDO
Posted by: SocQS (---.dsl.irvnca.pacbell.net)
Date: February 24, 2013 08:57AM

Apologies

I've been searching for the past couple of hours and that problem still hasn't been resolved.

Could you point me in the right direction?

Options: ReplyQuote
Re: (MySQL) Selecting Data from Multiple Rows of a Single Column Using PDO
Posted by: stevenmartin99 (Moderator)
Date: February 24, 2013 09:17AM


Options: ReplyQuote
Re: (MySQL) Selecting Data from Multiple Rows of a Single Column Using PDO
Posted by: SocQS (---.dsl.irvnca.pacbell.net)
Date: February 24, 2013 09:43AM

Thanks for the link. After quite a few variations a useful array still hasn't been produced. I'll keep searching and experimenting.

Options: ReplyQuote
Re: (MySQL) Selecting Data from Multiple Rows of a Single Column Using PDO
Posted by: stevenmartin99 (Moderator)
Date: February 24, 2013 09:48AM

I think your mistake, Your array is BY ROW.

So if you want them all in one array you will need to append onto an array for each loop

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: (MySQL) Selecting Data from Multiple Rows of a Single Column Using PDO
Posted by: SocQS (---.dsl.irvnca.pacbell.net)
Date: February 24, 2013 09:55AM

The code works now. Thanks for your help, it was invaluable.

Options: ReplyQuote


Sorry, only registered users may post in this forum.