Advertisement
Guest User

PHP array

a guest
Oct 18th, 2011
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.38 KB | None | 0 0
  1. <?php
  2.  
  3. function retrieveEntries($db, $id=NULL)
  4. {
  5.     /*
  6.      * If an entry ID was supplied, load the associated entry
  7.      */
  8.     if(isset($id))
  9.     {
  10.         $sql = "SELECT title, entry
  11.                 FROM entries
  12.                 WHERE id=?
  13.                 LIMIT 1";
  14.         $stmt = $db->prepare($sql);
  15.         $stmt->execute(array($_GET['id']));
  16.  
  17.         // Save the returned entry array
  18.         $e = $stmt->fetch();
  19.  
  20.         // Set the fulldisp flag for a single entry
  21.         $fulldisp = 1;
  22.     }
  23.  
  24.     /*
  25.      * If no entry ID was supplied, load all entry titles
  26.      */
  27.     else
  28.     {
  29.         $sql = "SELECT id, title
  30.                 FROM entries
  31.                 ORDER BY created DESC";
  32.  
  33.         // Loop through returned results and store as an array
  34.         foreach($db->query($sql) as $row) {
  35.             $e[] = array(
  36.                 'id' => $row['id'],
  37.                 'title' => $row['title']
  38.             );
  39.         }
  40.  
  41.         // Set the fulldisp flag for multiple entries
  42.         $fulldisp = 0;
  43.  
  44.         /*
  45.          * If no entries were returned, display a default
  46.          * message and set the fulldisp flag to display a
  47.          * single entry
  48.          */
  49.         if(!is_array($e))
  50.         {
  51.             $fulldisp = 1;
  52.             $e = array(
  53.                 'title' => 'No Entries Yet',
  54.                 'entry' => '<a href="admin.php">Post an entry!</a>'
  55.             );
  56.         }
  57.     }
  58.  
  59.     // Add the $fulldisp flag to the end of the array
  60.     array_push($e, $fulldisp);
  61.  
  62.     return $e;
  63. }
  64.  
  65. function sanitizeData($data)
  66. {
  67.     if(!is_array($data))
  68.     {
  69.         return strip_tags($data, "<a>");
  70.     }
  71.     else
  72.     {
  73.         return array_map('sanitizeData', $data);
  74.     }
  75. }
  76.  
  77. ?>
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement