topical media & game development
[] readme course(s) preface I 1 2 II 3 4 III 5 6 7 IV 8 9 10 V 11 12 afterthought(s) appendix reference(s) example(s) resource(s) _

talk show tell print

portal-xml-getcontent.php



  <?php
  
   header ("content-type: text/xml");
  
  mysql_connect("tornado","mwg400","48458749") or die ("Kan niet connecten.");
  tabellen = mysql_list_tables( "mwg400-dbs");
  
  mysql_select_db("mwg400-dbs") or die ("Verdorie, kan de database 
  niet openen");
  
      now = mktime();
      date = date("d-m-Y, H:i:s",now);
   echo "<document>
      <author>S. Bankras</author>
      <date>".date."</date>
      ";
      
  if(_GET['content_id']){
      content_row = vindContent(_GET['content_id']);
      printXMLContent(content_row);
  }
  if(_GET['category']){ 
  
  sql = "SELECT content_id FROM content_matrix WHERE "._GET['category']." = 1 ORDER BY content_id DESC";
      
      if(_GET['size']){
          sql .= " LIMIT 0,"._GET['size'];
      }
      result = mysql_query(sql);
      aantal = 0;
      while (row = mysql_fetch_array (result)) {
          content_rowArray[] = vindContent(row['content_id']);
          aantal++;
      }    
      echo "<size>".aantal."</size>\n";
      foreach(content_rowArray as content_row){
          printXMLContent(content_row);
      }        
  }
  
          echo "</document>";
  
  function printXMLContent(content_row){
  
      
          echo "<item>\n";
      foreach(content_row as key => value){
          if(!is_int(key)){
              value = str_replace('\n', ' ', value);
              echo "<".key.">".value."</".key.">\n";
          }
      }
      
          echo "</item>\n";
  }
  
  function vindContent(content_id){
      now = mktime();
      date = date("d-m-Y, H:i:s",now);
      
      result = mysql_query("SELECT * FROM content WHERE content_id = ".content_id);
      content_row = mysql_fetch_array (result);
          
          categoryString = categoryArray = null;
          result2 = mysql_query("SELECT * FROM content_matrix WHERE content_id = ".content_id);
          while (row2 = mysql_fetch_array (result2)) {
              foreach(row2 as key => value){
                  if(value == 1 && !is_int(key) && (key != 'content_id')){
                      categoryArray[] = key;
                  }
              }
          }
          
          
          
          keywordString = keywordArray = null;
          result2 = mysql_query("SELECT keyword_id FROM content_keywords WHERE content_id = ".content_id);
          while (row2 = mysql_fetch_array (result2)) {
              result3 = mysql_query("SELECT keyword_name FROM keywords WHERE keyword_id = ".row2['keyword_id']);
              while (row3 = mysql_fetch_array (result3)) {
                  keywordArray[] = row3['keyword_name'];
              }
          }
          
          content_row['content_binary']   = strip(content_row['content_binary']);
  
      content_row['derived_keywordstring'] = implode(", ", keywordArray);
     content_row['derived_categorystring'] = implode(", ", categoryArray);
          
          return content_row;
  }
  /*
  else {
  
      
      Tellertje en loop om de tabellen te tonen.
      
      echo "<fieldset><legend><b>List of all tables in the database</b></legend>";
      i=0;
      while (i < mysql_num_rows(tabellen)){
          t_name[i] = mysql_tablename (tabellen, i);
          echo "<a target='goalWin' href='getdb.php?table=".t_name[i]. "'>".t_name[i]."</a><br />\n";
          i++;
      }   
      echo "</fieldset>";
      mysql_free_result (result);
  }
  
  if(!_GET['table']){
  ?>
  <hr />
  Created for MMC2007
  <div>
    <img
          src="http://www.w3.org/Icons/valid-xhtml10"
          alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a>
          </div>
  </body>
  </html>
  <?php 
  } 
  */
  
  function strip(text){
      text = str_replace("&ndash;", "&#45;",text);
      text = str_replace("&acirc;", "NULL",text);
      text = str_replace("&Acirc;", "NULL",text);
      return text;
  }
  
  ?>


(C) A. Eliëns 2/9/2007

You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.