테이블에서 데이터를 가져 와서 html 텍스트의 문자열을 바꾸는 데 문제가 있습니다. 테이블에서 마지막 4 개의 행을 검색 한 다음 str_replace를 사용하여 자동으로 href를 작성해야합니다. 하나의 열은 url이고, 하나는 제목이고, 하나는 설명입니다. 그런 다음 각 행에서 4 개의 개별 hrefs를 만듭니다. 내가 지금까지 가지고있는 것은 마지막 결과만을 위해 일할 것이다. 어떻게 4에 모두 적용 할 수 있습니까?테이블에서 str_replace로 행 검색
$query = "SELECT * FROM LINKS ORDER BY id DESC LIMIT 4";
if(!$result = mysql_query($query)){
// query failed, handle the error here...
$errors[] = "A fatal error occurred and this page is non-functional at this time!";
trigger_error("Query failed: $query<br /> Due to: " . mysql_error()); // application error
} else {
// query worked
if(!mysql_num_rows($result)){
// no matching rows
$main_content .= "No rows were found!\n";
} else {
// query matched at least one row, use the results from the query here...
$row = mysql_fetch_assoc($result);
$title1 .= $row['title'];
$link1 .= $row['url'];
}
}
//string replace arrays
$placeholders = array('LINK1','LINK2', 'LINK3','LINK4');
$replacevals = array($link1, $link2, $link3, $link4);
//replace the areas of the template with the posted values
$page = str_replace($placeholders,$replacevals,$template);
나는 등 출력 $의 직책 2, $의 링크 2, $ TITLE3,
어디에서'str_replace()'가 있고 HTML는 어디에 있습니까? – DaveRandom
죄송합니다. str_replace를 포함하는 것을 잊었습니다. 나는 그것을 바닥에 더했다. –