|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
Weird case with empty valuesDear all,
I am trying to get some data from my mysql databse. This goes pretty well, here's my query: $db =Zend_Db_Table_Abstract::getDefaultAdapter(); $sql = "SELECT * FROM evenementen LEFT JOIN inschrijvingen ON "; $sql.= "inschrijvingen.evenement_id= evenementen.evenement_id;"; $result = $db->fetchAll($sql); When I dump my result, this is what I get: http://paste2.org/p/40914 And this is what worries me:["evenement_id"] => NULL, Evenement_id is always filled, since it is my primary key. So I tested the same query straight on my database with phpMyAdmin and this is what I got: http://sanders-albek.nl/pics/result.JPG And as you can see, what probebly happends is that a evenement_id wich is in my evenementen table always filled, gets overwritten by an empty one from my second table (inschrijvingen) How can I resolve this problem? -- Thanks J Sanders |
|
|
RE: Weird case with empty valuesHello,
It's not Zend Framework problem but MySQL related. Any way you don't need to use wildcard (*) in JOIN statements in this case. Specify your tables and fields explicitly. The example: SELECT evenementen.evenement_id , evenementen.evenement_naam , evenementen.datum_aanvang , evenementen.tijd_aanvang ... and so on... , inschrijvingen.persoon_id , inschrijvingen.status_id FROM evenementen LEFT JOIN inschrijvingen ON inschrijvingen.evenement_id = evenementen.evenement_id; I can't guess the structure of your tables but I hope you've got the point. Thanks, Joseph -----Original Message----- From: Jigal sanders [mailto:jigalroecha@...] Sent: Thursday, June 19, 2008 3:37 PM To: fw-db@... Subject: [fw-db] Weird case with empty values Dear all, I am trying to get some data from my mysql databse. This goes pretty well, here's my query: $db =Zend_Db_Table_Abstract::getDefaultAdapter(); $sql = "SELECT * FROM evenementen LEFT JOIN inschrijvingen ON "; $sql.= "inschrijvingen.evenement_id= evenementen.evenement_id;"; $result = $db->fetchAll($sql); When I dump my result, this is what I get: http://paste2.org/p/40914 And this is what worries me:["evenement_id"] => NULL, Evenement_id is always filled, since it is my primary key. So I tested the same query straight on my database with phpMyAdmin and this is what I got: http://sanders-albek.nl/pics/result.JPG And as you can see, what probebly happends is that a evenement_id wich is in my evenementen table always filled, gets overwritten by an empty one from my second table (inschrijvingen) How can I resolve this problem? -- Thanks J Sanders |
|
|
Re: Weird case with empty valuesOne solution is to specify an alias for the second instance of the column: SELECT e.*, i.evenement_id AS evenement_id_from_i FROM evenementen AS e LEFT JOIN inschrijvingen AS i USING (evenement_id) Note this means you must spell out all columns from i. You can't give an alias for one column and simultaneously use a wildcard for the others. Another solution would be to list all columns from i explicitly, excluding evenement_id. Regards, Bill Karwin |
|
|
Re: Weird case with empty valuesI thought of a third solution: fetch the results as a plain array instead of an associative array. That's the reason the column from the right table is overwriting the entry from the left table. You can specify the Zend_Db fetch mode as FETCH_NUM, to make it return each row as a plain array indexed by integer. See the documentation for more on fetch modes: http://framework.zend.com/manual/en/zend.db.html#zend.db.adapter.select.fetch-mode Regards, Bill Karwin |
|
|
|
| Free Forum Powered by Nabble | Forum Help |