Salve a tutti. Premetto che la mia conoscenza di PHP è agli inizi.
Sul sito che sto creando è presente uno slider di contenuti (news). Ciascuna news viene presa direttamente da un DB, a cui l'amministratore può aggiungerne di nuove tramite il seguente codice:
Oltre alle colonne sopra indicate, è presente solo la colonna ID, che ne decide l'ordine.Codice PHP:if(isset($_POST['news_title'])){
$news_title = $_POST['news_title'];
$imgURL = $_POST['imgURL'];
$news_text = $_POST['news_text'];
$articleURL = $_POST['articleURL'];
$sql = "INSERT INTO News SET
news_title='$news_title',
imgURL='$imgURL',
news_text='$news_text',
articleURL='$articleURL',
news_date=CURDATE()";
if(@mysql_query($sql)){
}
else {
echo '<p>Error adding submitted news' . mysql_error() . '</p>';
}
}
Attualmente, le news vengono visualizzate dalla prima all'ultima, partendo quindi dalla più vecchia. Io vorrei invertire tale ordine, così che la prima mostrata sia quella aggiunta più di recente.
Questo è come vengono cercati e stampati i contenuti:
L'idea è quella di inserire i nuovi contenuti al primo posto nel DB, ma non ho idea di come si faccia. Potete aiutarmi?Codice PHP:$result = @mysql_query('SELECT imgURL, news_title, news_date, news_text, articleURL FROM News');
if (!$result) {
exit('<p>Error performing query' . mysql_error() . '</p>');
}
while ($row = mysql_fetch_array($result)) {
echo '<div class="item">';
echo '<img src="' . $row['imgURL'] . '"/>';
echo '<h6>' . $row['news_date'] . '</h6>';
echo '<h4>' . $row['news_title'] . '</h4>';
echo '<h5>' . $row['news_text'] . '</h5>';
echo '<p><a href="' . $row['articleURL'] . '">Leggi di più</a></p>';
echo '</div>';
}

Rispondi quotando