Answer the question
In order to leave comments, you need to log in
Website php + AJAX, have you arrived?
Throughout the week, the guys helped me, answering my questions (thanks again Alexey Skobkin , Andrey Surzhikov , MaEcTPo !).
I understood everything how it works and it works, but now the problem is in the implementation. After a couple of hours, it just became hard to look at the code, I even heard Satan screaming - "You are the best!".
In general code:
<?php
function news(){
$data = '';
$data .= '<div style="color: #23374f; font-weight: bold; font-size: 15px; padding: 0 0 20px 10px;">Политика</div><div>';
$sql = mysql_query("SELECT news_id, title, description, photo FROM news WHERE category='1' ORDER BY news_id DESC LIMIT 10") or die(mysql_error());
$kol = mysql_num_rows($sql);
$margin = 0;
for ($i=1; $i <= $kol; $i++) {
$margin++;
$news = mysql_fetch_assoc($sql);
if ($margin == 5) {$data .= '<div class="card news fl" style="margin-right: 0;">'; $margin = 0;}
else {$data .= '<div class="card news fl">';}
$data .= '<div class="newsPhoto">';
$data .= '<img src="'.getImgUrl($news['photo']).'">';
$data .= '</div>';
$data .= '<div class="card_content">';
$data .= '<div class="newsTitle">'.$news['title'].'</div>';
$data .= '<div class="newsText">'.$news['description'].'</div>';
$data .= '</div>';
$data .= '</div>';
}
$data .= '</div>';
return $data;
}
function news_menu(){
$data ='<div class="card" style="height: 30px;">
<a href="#">Город</a>
<a href="#">Происшествия</a>
<a href="#">Закон</a>
<a href="#">Мероприятия</a>
<a href="#">Наука и техника</a>
<a href="#">Игры</a>
<a href="#">Авто</a>
<a href="./addNews">[Добавить новость]</a>
</div>';
return $data;
}
if (isAJAX() == false) {
echo head('Новости',array('common.css', 'news.css'),array('common.js'));
echo body();
echo news_menu();
echo news();
echo footer();
}
else {
$data = news_menu().news();
$dataAJAX = array ('Новости',array('common.css', 'news.css'),array('common.js'),$data);
echo json_encode($dataAJAX);
}
?>
Answer the question
In order to leave comments, you need to log in
There is very, very much that can be brought to the divine form. You should probably try some not very complex MVC framework to get started.
So far, all the code is a mess, a little easier to maintain than if everything was in one file, but still much more complicated than the solutions already worked out.
$data .= '<div class="newsPhoto">';
$data .= '<img src="'.getImgUrl($news['photo']).'">';
$data .= '</div>';
// ...
if (isAJAX() == false) {
echo head('Новости',array('common.css', 'news.css'),array('common.js'));
echo body();
echo news_menu();
echo news();
echo footer();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question