![]() |
Display MySQL rows - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Display MySQL rows (/showthread.php?tid=27828) |
Display MySQL rows - El Forum - 02-22-2010 [eluser]Assim[/eluser] This could be the most simplest questions any one can ask but when I do, the rows from the MySQL table are not shown but the word "Array" is shown instead. It works when I use the parser, but when I write it in PHP tags in the view it doesn't. I don't want to make it a long, but here's what I wanted to do. I have a table called links with a column named URL, how do I display the URL in rows in the view. Here's the query that I would use: SELECT * FROM links Just a simple example of how to use might solve this problem. Display MySQL rows - El Forum - 02-22-2010 [eluser]rogierb[/eluser] Ae you refering to looping through a result set? Code: foreach($resul_set->result() as $row ) Can you show us the code? Display MySQL rows - El Forum - 02-22-2010 [eluser]Assim[/eluser] [quote author="rogierb" date="1266850050"]Ae you refering to looping through a result set? Code: foreach($resul_set->result() as $row ) Can you show us the code?[/quote] Here's my code. Controller: Code: $PageReferences = $this->db->query("SELECT URL FROM pagereferences WHERE PageID = '$PageID'"); This is what I wrote in the view: Code: <?php foreach($References as $URL): ?> The value of $URL is "Array" when echoed. Display MySQL rows - El Forum - 02-22-2010 [eluser]rogierb[/eluser] Try: $URL['URL']; Display MySQL rows - El Forum - 02-22-2010 [eluser]Assim[/eluser] [quote author="rogierb" date="1266850732"]Try: $URL['URL'];[/quote] Still doesn't work. I also tried <?php foreach($References['URL'] as $URL): ?> but I got a unidentified index: URL error. Display MySQL rows - El Forum - 02-22-2010 [eluser]rogierb[/eluser] Try Code: <?php print_r($References); ?><br /> To see what the array is composed of. It might be the array is empty. Display MySQL rows - El Forum - 02-22-2010 [eluser]Assim[/eluser] [quote author="rogierb" date="1266852028"]Try Code: <?php print_r($References); ?><br /> To see what the array is composed of. It might be the array is empty.[/quote] This is what I got: Code: Array ( [0] => Array ( [URL] => http://assim.me ) [1] => Array ( [URL] => http://destinationoman.com ) ) Those are what in my DB. So how can I display them? Display MySQL rows - El Forum - 02-22-2010 [eluser]rogierb[/eluser] Based on the array I would say: [code] <?php foreach($References as $array=>$row): ?> <?php echo $row['URL']; ?><br /> <?php endforeach; ?> Display MySQL rows - El Forum - 02-22-2010 [eluser]Assim[/eluser] Wow, thanks! It worked. ![]() |