garaux Posted April 12, 2013 Share Posted April 12, 2013 Hi there, I am working on a simple application using PHP and MySql. The main table of the database is denominated article. A second table lang is related to the table article using a lookup. I would like to display the values horizontally as shown in the file attached. Here is the code I am using include 'includes/db.inc.php'; try { $query_sql = 'SELECT article_name, author_name, lang_name FROM article INNER JOIN author ON article.author_id = author.id inner join lookuplang on article.id = lookuplang.articleID inner join lang on langID = lang.id ORDER BY article.id ASC'; $result = $GLOBALS['pdo']->query($query_sql); } foreach($result as $row) { $valori[] = array('article_name'=>$row['article_name'],'author_name'=>$row['author_name'], 'lang_name'=>$row['lang_name']); } include 'test.html.php'; <?php foreach($valori as $lista):?> <?php $lingua = $lista['lang_name'] . ': Status'; ?> <tr> <td> <?php echo $lista['article_name']?></td> <td> <?php echo $lista['lang_name']?></td> </tr> <?php endforeach?></table> Could you please help me? Thanks Link to comment https://forums.phpfreaks.com/topic/276865-how-to-display-horizontally-the-values-from-a-database/ Share on other sites More sharing options...
Jessica Posted April 12, 2013 Share Posted April 12, 2013 Try group_concat in mysql, or this tutorial I wrote on parent-child lists if you need to do anything besides just list the names. http://thewebmason.com/tutorial-parent-child-lists/ Link to comment https://forums.phpfreaks.com/topic/276865-how-to-display-horizontally-the-values-from-a-database/#findComment-1424345 Share on other sites More sharing options...
garaux Posted April 12, 2013 Author Share Posted April 12, 2013 Thank you for your answer. I will have a look at your file...Thanks! Link to comment https://forums.phpfreaks.com/topic/276865-how-to-display-horizontally-the-values-from-a-database/#findComment-1424347 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.