Welcome Guest, Not a member yet? Register   Sign In
Display MySQL rows
#1

[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.
#2

[eluser]rogierb[/eluser]
Ae you refering to looping through a result set?
Code:
foreach($resul_set->result() as $row )
{
echo $row->field;
}

Can you show us the code?
#3

[eluser]Assim[/eluser]
[quote author="rogierb" date="1266850050"]Ae you refering to looping through a result set?
Code:
foreach($resul_set->result() as $row )
{
echo $row->field;
}

Can you show us the code?[/quote]
Here's my code.

Controller:
Code:
$PageReferences = $this->db->query("SELECT URL FROM pagereferences WHERE PageID = '$PageID'");
$data['References'] = $PageReferences->result_array();
$this->load->view('references', $data);

This is what I wrote in the view:
Code:
<?php foreach($References as $URL): ?>
&lt;?php echo $URL; ?&gt;<br />
&lt;?php endforeach; ?&gt;

The value of $URL is "Array" when echoed.
#4

[eluser]rogierb[/eluser]
Try: $URL['URL'];
#5

[eluser]Assim[/eluser]
[quote author="rogierb" date="1266850732"]Try: $URL['URL'];[/quote]
Still doesn't work.

I also tried &lt;?php foreach($References['URL'] as $URL): ?&gt; but I got a unidentified index: URL error.
#6

[eluser]rogierb[/eluser]
Try

Code:
&lt;?php print_r($References); ?&gt;<br />
&lt;?php foreach($References as $URL): ?&gt;
&lt;?php print_r($URL); ?&gt;<br />
&lt;?php echo $URL; ?&gt;<br />
&lt;?php endforeach; ?&gt;

To see what the array is composed of.

It might be the array is empty.
#7

[eluser]Assim[/eluser]
[quote author="rogierb" date="1266852028"]Try

Code:
&lt;?php print_r($References); ?&gt;<br />
&lt;?php foreach($References as $URL): ?&gt;
&lt;?php print_r($URL); ?&gt;<br />
&lt;?php echo $URL; ?&gt;<br />
&lt;?php endforeach; ?&gt;

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 ) )
Array ( [URL] => http://assim.me )
Array
Array ( [URL] => http://destinationoman.com )
Array

Those are what in my DB. So how can I display them?
#8

[eluser]rogierb[/eluser]
Based on the array I would say:

[code]
&lt;?php foreach($References as $array=>$row): ?&gt;
&lt;?php echo $row['URL']; ?&gt;<br />
&lt;?php endforeach; ?&gt;
#9

[eluser]Assim[/eluser]
Wow, thanks! It worked. Smile I have been trying to make this work for days, and thanks for helping me.




Theme © iAndrew 2016 - Forum software by © MyBB