Erlendftw

testkode php mysql

Oct 5th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.86 KB | None | 0 0
  1. <?php
  2.  
  3.     $con = mysqli_connect('localhost', 'root', 'root', 'test_bjorn');
  4.  
  5.     $sqlGetArticles = "SELECT * FROM `articles` ORDER BY `id` DESC LIMIT 0,10";
  6.     $resultGetArticles = mysqli_query($con, $sqlGetArticles);
  7.    
  8.     $index = 0;
  9.     while ($objectGetArticles = mysqli_fetch_assoc($resultGetArticles))
  10.     {
  11.         $index += 1;
  12.  
  13.         if ($index == 1)
  14.         {
  15.             //Stor nyhet (første)
  16.             $indexString = 'Stor nyhet';
  17.         } else
  18.         {
  19.             //Liten nyhet (resten)
  20.             $indexString = 'Liten nyhet';
  21.         }
  22.  
  23.         echo '
  24.             <h3>' . $indexString . '</h3>
  25.             <ul>
  26.                 <li><span style="font-weight: bold;">Title: </span> ' . $objectGetArticles['title'] . '</li>
  27.                 <li><span style="font-weight: bold;">Forfatter: </span> ' . $objectGetArticles['author'] . '</li>
  28.                 <li><span style="font-weight: bold;">Innhold: </span> ' . $objectGetArticles['content'] . '</li>
  29.             </ul>
  30.         ';
  31.     }  
  32.  
  33.  
  34. ?>
Advertisement
Add Comment
Please, Sign In to add comment