2016-07-19 6 views
0
  1. 여기 내 뉴스 웹 사이트 메인 페이지 코드 (here is an image)
    나는 내 웹 사이트 예를 들어
  2. 에 현재의 위치에 뉴스를 표시 할 입니다 ... 그의 단면도에있는 이차 뉴스, 그의 단면도에있는 매일 뉴스.
  3. 그래서 관리자는 ... 그들이
  4. 나는 그것을 달성 할 수있는 방법 마음을 해달라고 도와주세요 이전 소식으로 자신의 위치에 추가됩니다 보조 또는 매일 뉴스를 추가 할 때마다 어떻게 이전 후를 추가합니다 .. .데이터를 표시

    <div class="container" style="padding-top:60px; height: auto;"> 
        <div class="row" id="main"> 
         <div class="row"> 
          <div class="col-lg-12"> 
           <marquee bgcolor="red" behaviour="scroll" direction="left" style = "color:white; font-family: 'Roboto', sans-serif;" > 
            <p> 
             <strong> 
              Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
              sed do eiusmod tempor incididunt ut labore e 
              t dolore magna aliqua.Lorem ipsum dolor sit amet 
              Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
              sed do eiusmod tempor incididunt ut labore e 
              t dolore magna aliqua.Lorem ipsum dolor sit amet 
              Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
              sed do eiusmod tempor incididunt ut labore e 
              t dolore magna aliqua.Lorem ipsum dolor sit amet 
              Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
              sed do eiusmod tempor incididunt ut labore e 
              t dolore magna aliqua.Lorem ipsum dolor sit amet  
              Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
              sed do eiusmod tempor incididunt ut labore e 
              t dolore magna aliqua.Lorem ipsum dolor sit amet 
              Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
              sed do eiusmod tempor incididunt ut labore e 
              t dolore magna aliqua.Lorem ipsum dolor sit amet        
             </strong>    
            </p> 
           </marquee> 
          </div> 
         </div> 
         <div class="col-md-3"> 
          <h3 style=" font-family: 'Lora', serif">Ads Here</h3> 
          <iframe src="" width="100%" height="300px"></iframe> 
    
           <h3 style=" font-family: 'Lora', serif">Secondary News Here</h3> 
           <div class="secondary-left clearfix"> 
            <a href="#"><h3>Header Text</h3><img src="Images/girl-791231_1920.jpg" width="50%" class="pull-left"></a>    
             <p> 
              Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
              sed do eiusmod tempor incididunt ut labore e 
              t dolore magna aliqua.Lorem ipsum dolor sit amet 
              Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
              sed do eiusmod tempor incididunt ut labore e                 
             </p> 
           </div> 
           <div class="secondary-left clearfix"> 
            <a href="#"><h3>Header Text</h3><img src="Images/newspaper-595478_1920.jpg" width="50%" class="pull-left"></a> 
             <p>    
              Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
              sed do eiusmod tempor incididunt ut labore e 
              t dolore magna aliqua.Lorem ipsum dolor sit amet 
              Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
              sed do eiusmod tempor incididunt ut labore e 
              t dolore magna aliqua.Lorem ipsum dolor sit amet  
              Lorem ipsum dolor sit amet, consectetur adipiscing elit,                 
             </p> 
          </div> 
    
    
         </div>   
         <div class="col-md-6" id="center"> 
          <div id="sliderWrapper" style="display:none"> 
          <h2 style=" font-family: 'Lora', serif" class="text-center">Breaking News</h2>    
           <div id="breakingSlider" class="owl-carousel" > 
            <div class="item"> 
             <div class="sliderText"> 
              <h2>Breaking Heading</h2> 
               <p> 
                Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
                sed do eiusmod tempor incididunt ut labore e 
                t dolore magna aliqua.Lorem ipsum dolor sit amet  
               </p> 
             </div> 
             <a href="#"><img src="Images/asia-1177088_1920.jpg" class="img-responsive"></a> 
            </div> 
            <div class="item"> 
             <div class="sliderText"> 
              <h2>Breaking Heading</h2> 
               <p> 
                Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
                sed do eiusmod tempor incididunt ut labore e 
                t dolore magna aliqua.Lorem ipsum dolor sit amet        
               </p> 
             </div> 
             <a href="#"><img src="Images/newspaper-664620_1920.jpg" class="img-responsive"></a> 
            </div> 
            <div class="item"> 
             <div class="sliderText"> 
              <h2>Breaking Heading</h2>     
               <p> 
                Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
                sed do eiusmod tempor incididunt ut labore e 
                t dolore magna aliqua.Lorem ipsum dolor sit amet        
               </p> 
             </div> 
             <a href="#"><img src="Images/news-1172462_1920.jpg" class="img-responsive"></a> 
            </div> 
           </div>   
          </div> 
           <div class="daily clear-fix"> 
             <a href="#"><img src="Images/business-1031754_1920.jpg" class="img-responsive"><h3>Daily news heading</h3></a> 
              <p> 
               Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
               sed do eiusmod tempor incididunt ut labore e 
               t dolore magna aliqua.Lorem ipsum dolor sit amet 
               Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
               sed do eiusmod tempor incididunt ut labore e 
               t dolore magna aliqua.Lorem ipsum dolor sit amet  
               Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
               sed do eiusmod tempor incididunt ut labore e 
               t dolore magna aliqua.Lorem ipsum dolor sit amet  
               Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
               sed do eiusmod tempor incididunt ut labore e 
               t dolore magna aliqua.Lorem ipsum dolor sit amet                  
              </p> 
           </div> 
           <div class="daily clearfix">  
            <a href="#"><img src="Images/man-1386201_1920.jpg" class="img-responsive"><h3>Daily news heading</h3></a> 
             <p> 
              Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
              sed do eiusmod tempor incididunt ut labore e 
              t dolore magna aliqua.Lorem ipsum dolor sit amet 
              Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
              sed do eiusmod tempor incididunt ut labore e 
              t dolore magna aliqua.Lorem ipsum dolor sit amet  
              Lorem ipsum dolor sit amet, consectetur adipiscing elit,                
             </p>  
          </div>                        
    
         </div>      
    
    
         <!-- Simple Currency Rates Table START --> 
    
    
         <div class="col-md-3 clearfix"> 
    
          <h3 style=" font-family: 'Lora', serif">Exchange Rates</h3> 
    
    
    <div id="erscrt2"><div id="erscrt2-widget"></div><div id="erscrt2-infolink"><a href="http://www.exchangerates.org.uk/British-Pound-GBP-currency-table.html" target="_new" ><img src='http://www.exchangerates.org.uk/widget/logo-333333.png' alt='ExchangeRates.org.uk'></a></div> 
    <script type="text/javascript"> 
    var tz = 'userset'; 
    var w = '180'; 
    var mc = 'GBP'; 
    var nb = '10'; 
    var c1 = 'USD'; 
    var c2 = 'EUR'; 
    var c3 = 'AUD'; 
    var c4 = 'JPY'; 
    var c5 = 'INR'; 
    var c6 = 'CAD'; 
    var c7 = 'ZAR'; 
    var c8 = 'NZD'; 
    var c9 = 'SGD'; 
    var c10 = 'CNY'; 
    var t = 'Exchange Rates'; 
    var tc = '333333'; 
    var bdrc = '000000'; 
    var mbg = 'FFFFFF'; 
    var fc = '111D33'; 
    
    var ccHost = (("https:" == document.location.protocol) ? "https://www." : "http://www."); 
    document.write(unescape("%3Cscript src='" + ccHost + "exchangerates.org.uk/widget/ER-SCRT2-1.php' type='text/javascript'%3E%3C/script%3E")); 
    </script> 
    </div> 
    
    <!-- Simple Currency Rates Table END -->  
    
    
          <h3 style=" font-family: 'Lora', serif">Secondary News Here</h3> 
          <div class="secondary-right clearfix"> 
           <a href="#"><h3>Header Text</h3><img src="Images/man-791440_1920.jpg" width="50%" class="pull-left"></a>     
            <p>    
             Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
             sed do eiusmod tempor incididunt ut labore e 
             t dolore magna aliqua.Lorem ipsum dolor sit amet 
             Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
             sed do eiusmod tempor incididunt ut labore e                 
            </p> 
          </div> 
          <div class="secondary-right clearfix"> 
           <a href="#"><h3>Header Text</h3><img src="Images/How-This-Introvert-Built-a-Successful-Career-as-a-Journalist_SOURCE_pixabay.jpg" width="50%" class="pull-left"></a>     
            <p> 
             Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
             sed do eiusmod tempor incididunt ut labore e 
             t dolore magna aliqua.Lorem ipsum dolor sit amet 
             Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
             sed do eiusmod tempor incididunt ut labore e 
             t dolore magna aliqua.Lorem ipsum dolor sit amet  
             Lorem ipsum dolor sit amet, consectetur adipiscing elit,                 
            </p> 
          </div> 
          <h3 style=" font-family: 'Lora', serif">Weather</h3> 
    <a href="http://www.accuweather.com/en/us/new-york-ny/10007/weather-forecast/349727" class="aw-widget-legal"> 
    
    </a><div id="awcc1468436013708" class="aw-widget-current" data-locationkey="" data-unit="c" data-language="en-us" data-useip="true" data-uid="awcc1468436013708"></div><script type="text/javascript" src="http://oap.accuweather.com/launch.js"></script> 
    
         </div> 
         <div class="row"> 
          <div class="col-lg-12"> 
           <marquee bgcolor="red" behaviour="scroll" direction="left" style = "color:white; font-family: 'Roboto', sans-serif;" > 
            <p> 
             <strong> 
              Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
              sed do eiusmod tempor incididunt ut labore e 
              t dolore magna aliqua.Lorem ipsum dolor sit amet 
              Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
              sed do eiusmod tempor incididunt ut labore e 
              t dolore magna aliqua.Lorem ipsum dolor sit amet 
              Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
              sed do eiusmod tempor incididunt ut labore e 
              t dolore magna aliqua.Lorem ipsum dolor sit amet 
              Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
              sed do eiusmod tempor incididunt ut labore e 
              t dolore magna aliqua.Lorem ipsum dolor sit amet  
              Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
              sed do eiusmod tempor incididunt ut labore e 
              t dolore magna aliqua.Lorem ipsum dolor sit amet 
              Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
              sed do eiusmod tempor incididunt ut labore e 
              t dolore magna aliqua.Lorem ipsum dolor sit amet 
             </strong>    
            </p> 
           </marquee> 
          </div> 
         </div> 
        </div> 
    </div> 
    
  5. 나는 개인적으로 MySQL을의 PDO 내가 가지고 더 많은 경험을 사용
+0

이것은 html이지만, php 및 mysql 스크립트에서 데이터베이스에 저장하고 데이터베이스에서 검색하려고 시도한 것은 무엇입니까? – Michael

+0

문제는 내가 PHP 나 어쩌면 자바 스크립트 코드가 어떻게 작동하는지 이해할 수 없다. 누군가가 설명하거나 보여줄 수 있다면 나는 매우 감사 할 것이다. –

+0

PHP 서버가 이미 실행 중입니까? MySQL 설정으로도? – Michael

답변

1

. 대신 mysqli을 사용하려는 경우 필요에 따라이 대답을 적용 할 수 있습니다. 이를 달성하는 방법은 두 가지가 있습니다. 1 - 페이지로드 (권장)의 일부로 뉴스를 가져 오거나 2 - AJAX를 통해 뉴스를 가져옵니다 (좀 더 기술적 인 방법). 나는 첫번째를 설명 할 것이다.

데이터베이스 테이블 :

news 
|=======| 
|id  | 
|title | 
|content| 
|type | //To store 'Daily' or 'Secondary' tag 
|date | //To sort and pull most recent news stories 

당신이 먼저 필요가 데이터베이스에 연결합니다.

<?php 
$config = array(
'host' => 'localhost', //Can also use your IP address 
'username' => 'your username here', 
'password' => 'your password here', 
'dbname' => 'your database name here' 
); 
$db = new PDO('mysql:host='.$config['host'] . ';dbname='. $config['dbname'],$config['username'],$config['password']); 
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); 
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 

그런 다음 당신이 당신의 쿼리 설정에 필요하고 실행할 수 있습니다 : PDO, 당신은 같은 것을 사용하십시오 당신은에 결과를 에코해야합니다, 여기에서

//You can go a couple ways at this point: extract this into a function, pull all news types in one DB query and then in PHP sort the results depending on the type of news and display them based on that type, or perform two DB queries and place those results where they need to be. 
//I'll show the last example for simplicity 
//Pull Daily news types 
$query = $db->prepare("SELECT * FROM news WHERE type = 'daily' ORDER BY date DESC LIMIT 10"); //Limiting the number of news articles that are pulled 
$query->execute(); 
$daily_news = $query->fetchAll(); 

//Pull Secondary news types 
$query = $db->prepare("SELECT * FROM news WHERE type = 'secondary' ORDER BY date DESC LIMIT 10"); //Limiting the number of news articles that are pulled 
$query->execute(); 
$secondary_news = $query->fetchAll(); 

당신의 페이지 :

//At the bottom of your left column 
<div class="secondary-left clearfix"> 
    <a href="#"><h3>Header Text</h3><img src="Images/newspaper-595478_1920.jpg" width="50%" class="pull-left"></a> 
    <p> 
    Lorem ipsum dolor sit amet, consectetur adipiscing elit,sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, consectetur adipiscing elit,                 
    </p> 
</div> 
<div class="secondary-left clearfix"> 
    <a href="#"><h3>Secondary News<h3><img src="Images/newspaper-595478_1920.jpg" width="50%" class="pull-left"></a> 
    <?php 
    foreach($secondary_news as $snews){ //This will loop through every entry that met the criteria in the query and echo a bolded title and the news article 
     $title = $snews['title']; 
     $content = $snews['content']; 
     echo "<p><b>$title</b><br>$content</p>"; 
    } 
    ?> 
</div> 

페이지에서 일일 뉴스를 넣을 곳의 모델로 사용하십시오. 이 시점까지는 귀하의 페이지 여야합니다 :

<?php 
$config = array(
'host' => 'localhost', //Can also use your IP address 
'username' => 'your username here', 
'password' => 'your password here', 
'dbname' => 'your database name here' 
); 
$db = new PDO('mysql:host='.$config['host'] . ';dbname='. $config['dbname'],$config['username'],$config['password']); 
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); 
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 

//Pull Daily news types 
$query = $db->prepare("SELECT * FROM news WHERE type = 'daily' ORDER BY date DESC LIMIT 10"); //Limiting the number of news articles that are pulled 
$query->execute(); 
$daily_news = $query->fetchAll(); 

//Pull Secondary news types 
$query = $db->prepare("SELECT * FROM news WHERE type = 'secondary' ORDER BY date DESC LIMIT 10"); //Limiting the number of news articles that are pulled 
$query->execute(); 
$secondary_news = $query->fetchAll(); 
?> 
<div class="container" style="padding-top:60px; height: auto;"> 
    <div class="row" id="main"> 
     <div class="row"> 
     ... 
     </div> 
     <div class="secondary-left clearfix"> 
      <a href="#"><h3>Header Text</h3><img src="Images/newspaper-595478_1920.jpg" width="50%" class="pull-left"></a> 
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit,sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, consectetur adipiscing elit,                 
      </p> 
     </div> 
     <div class="secondary-left clearfix"> 
      <a href="#"><h3>Secondary News<h3><img src="Images/newspaper-595478_1920.jpg" width="50%" class="pull-left"></a> 
      <?php 
      foreach($secondary_news as $snews){ 
       $title = $snews['title']; 
       $content = $snews['content']; 
       echo "<p><b>$title</b><br>$content</p>"; 
      } 
      ?> 
     </div> 
     ... 
     <!-- Section for the daily news --> 
     <div class="secondary-left clearfix"> 
      <a href="#"><h3>Daily News<h3><img src="Images/newspaper-595478_1920.jpg" width="50%" class="pull-left"></a> 
      <?php 
      foreach($daily_news as $dnews){ 
       $title = $dnews['title']; 
       $content = $dnews['content']; 
       echo "<p><b>$title</b><br>$content</p>"; 
      } 
      ?> 
     </div> 
     ... 
    </div> 
</div> 

적어도 기본 사항을 확인하는 데 도움이되기를 바랍니다.

+0

위대한 설명 .... 대단히 마이클 ... –