-1

I had an multidimensional array which contained titles, links and descriptions for a collaboration of news stories crawled from the BBC News site.

I then used a function to implode it into a string, then defined the called function into a variable and inserted it into a database. But there is nothing being inserted. I have used the die(mysql_error()) and nothing is being returned and I am struggling to think what I am doing wrong.

If I echo the variable I am inserting, I receive input similiar to the following: title, description, (where keywords should be), link, title, description, keywords link, title description, keywords, link.

Do you have any idea? Am I having some sort of quotation problem here?

 function r_implode( $glue, $pieces ) 
{ 
foreach( $pieces as $r_pieces ) 
{ 
    if( is_array( $r_pieces ) ) 
    { 
        $retVal[] = r_implode( $glue, $r_pieces ); 
    } 
    else
    { 
        $retVal[] = "'".$r_pieces."'";  //Here add quotes
    } 
} 
return implode( $glue, $retVal ); 
} 

$data = r_implode( ' , ', $news_stories); //And Here remove quotes
$query = mysql_query("INSERT INTO news_story (title, description, keywords, link) VALUES (". $data .")") or die(mysql_error());
4

1 回答 1

0

我认为这里会有报价问题

function r_implode( $glue, $pieces ) 
{ 
    foreach( $pieces as $r_pieces ) 
    { 
        if( is_array( $r_pieces ) ) 
        { 
            $retVal[] = r_implode( $glue, $r_pieces ); 
        } 
        else
        { 
            $retVal[] = "'".$r_pieces."'";  //Here add quotes
        } 
    } 
    return implode( $glue, $retVal ); 
} 

$data = r_implode( ' , ', $news_stories); //And Here remove quotes
$query = mysql_query("INSERT INTO news_story (title, description, keywords, link) VALUES (". $data .")") or die(mysql_error());
于 2012-12-22T12:45:47.543 回答