2014-03-29 2 views
0

테이블에서 두 colomns의 텍스트를 내보내고 html로 포맷 한 다음 새 테이블의 단일 컬럼으로 병합하려고합니다.PHP와 MySQL은 한 테이블에서 다른 테이블로 가져오고 다른 테이블로 가져 오기

모든 것을 내보낼 수 있었지만 $ text_comp를 post_content에 제대로 삽입 할 수 없습니다. 이 코드는 각 행에 대해 0을 post_content 열에 삽입합니다.

function clean_string($value) { 
if(get_magic_quotes_gpc()) { 
     $value = stripslashes($value); 
} 
return mysql_real_escape_string($value); 
} 



$result = mysqli_query($con,"SELECT * FROM table8"); 
if (!$result) { 
    printf("Error: %s\n", mysqli_error($con)); 
    exit();} 




while($row = mysqli_fetch_array($result)) 
    { 



$id_article_c = $row['id_article_complement']; 
$id_article_n = $row['id_article']; 
$text_comp = "<h3>". $row['titre_article_complement']."</h3><p>".$row['contenu_article_complement'] ."</p>"; 



$test_insert = mysqli_query($con,'INSERT INTO wordpress_test(post_content, id_article,id_article_complement) VALUES("'.clean_string($text_comp).'", "'.$id_article_n.'","'.$id_article_c.'")'); 
if (!$test_insert) { 
    printf("Error: %s\n", mysqli_error($con)); 
    exit();} 
} 

편집 :

여기 내 코드 내 나쁜,이 코드는 작동합니다. 문제는 데이터 형식을 잘못 설정 한 SQL 테이블에서 발생했습니다. 정확히 기억할 수는 없지만 TEXT 대신 int과 같았습니다.

+0

죄송합니다. 실제로이 코드는 작동하지만, 문제는 MySQL 테이블의 구조에서 왔습니다. –

답변

0

왜 두 가지 쿼리를 사용합니까? SQL은 하나의 쿼리에서 이것을 수행 할 수 있습니다.

관련 문제