goldfishdancer Posted March 2, 2013 Share Posted March 2, 2013 [edit] i believe ive posted this in the wrong section D: please could a mod delete or move it! thanks! ----------------------- Hi Im trying to get : - title, newstext, authorId from indexNews - id, forename, surname from users where authorId is id im using pdo, which is where im stuck here is what I've done so far : try { $sql = "SELECT i.title, i.newstext, i.authorId, u.id, u.forename, u.surname FROM indexNews as i JOIN users AS u ON (i.authorId = u.id)"; //$sql = "SELECT * FROM indexNews"; foreach ($db->query($sql) as $row) { echo '<div class="announceTitle">'; echo $row['i.title'] .' - '. $row['i.authorId'] . '<br />'; echo $row['u.surname'].' '.$row['u.forename'].'<br />'; echo '</div> <div class="announceText">'; echo $row['i.newstext']; echo '</div> <br /> <br />'; } } catch(PDOException $e) { echo $e->getMessage(); } when i run this i get : Notice: Undefined index: i.title in <document path>/index.php on line 100 Notice: Undefined index: i.authorId in <document path>/index.php on line 100 line 100 is echo $row['i.title'] .' - '. $row['i.authorId'] . '<br />'; i think that the issue might be with the array? but i'm not sure. I've tried googling and have been looking for a tutorial, but haven't found an answer. could anyone give me some hints as to where i'm going wrong? Thanks for your time Link to comment https://forums.phpfreaks.com/topic/275118-selecting-information-from-2-tables-in-1-sql-statement-pdo/ Share on other sites More sharing options...
mikosiko Posted March 2, 2013 Share Posted March 2, 2013 Take the i. and u. Out of every $ row [] $row ['i.title'] must be $row['title'] same for the rest Link to comment https://forums.phpfreaks.com/topic/275118-selecting-information-from-2-tables-in-1-sql-statement-pdo/#findComment-1415991 Share on other sites More sharing options...
goldfishdancer Posted March 2, 2013 Author Share Posted March 2, 2013 Thanks so much! That works now Link to comment https://forums.phpfreaks.com/topic/275118-selecting-information-from-2-tables-in-1-sql-statement-pdo/#findComment-1415993 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.