テーブルからデータを取り込み、それを使ってhtmlテキストの文字列を置き換えるのに問題があります。私はテーブルから最後の4行を取得し、str_replaceを使って自動的にhrefを作成する必要があります。 1つの列はURL、1つはタイトル、1つは説明などです。次に、各行から4つの別々の階層を作成します。私が今までに持っていたことは、最後の結果のためだけに働くでしょう。どのように私は4すべてのためにそれを働かせるのですか?私は出力$ TITLE2、$リンク2、$ TITLE3にできるようにしたいと思いテーブルから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);
など
どこに 'str_replace()'があり、どこにHTMLがありますか? – DaveRandom
申し訳ありませんが、str_replaceを含めるのを忘れていました。私はそれを底に付け加えた。 –