-1

Like the titles describes, I'm trying to output multiple URL links from a database. But recieving an error.

PHP

$link_select = mysql_query("SELECT link FROM links WHERE sigaren_id = " .$resultaat_fetch_id_sigaren);                  
while ($link = mysql_fetch_array($link_select)) 
{
    $resultaat_link = $link['link'];
    $link .= "<a href='".$link."'>$link</a>";
}   

HTML

<b>Links</b><br><br>
<?php echo $link;  ?> 

ERROR

Notice: Array to string conversion
user3360972
  • 107
  • 2
  • 13
  • `$link = mysql_fetch_ARRAY($link_select)`. You are trying to append a string with an array, bruv. As a matter of fact, you are also trying to append an array with a string. It doesn't work like that. –  Aug 17 '15 at 19:01
  • Your code is very messy. You're `echo`ing an array, your `Notice` just said that. – al'ein Aug 17 '15 at 19:01
  • 3
    possible duplicate of [How to solve error 'Notice: Array to string conversion in.....'](http://stackoverflow.com/questions/20017409/how-to-solve-error-notice-array-to-string-conversion-in) – nomistic Aug 17 '15 at 19:02

1 Answers1

2

Because, you're treating an array as a string.

$link is an array, but you're referring to it as a string.

To fix it, change the code like this:

$link_select = mysql_query("SELECT link FROM links WHERE sigaren_id = " .$resultaat_fetch_id_sigaren);                  
while ($link = mysql_fetch_array($link_select)) 
{
    $resultaat_link = $link['link'];
    $linkData .= "<a href='".$resultaat_link."'>$resultaat_link</a>";
}   

<b>Links</b><br><br>
<?php echo $linkData;  ?> 

Side note: Stop using mysql_* functions because they are deprecated. Move on to PDO or MySQLi instead.

codez
  • 1,440
  • 2
  • 19
  • 34