HELP: PHP&MYSQL website problem

Discussion in 'PHP' started by sam127, May 13, 2010.

  1. #1
    Hi, i am designing an international website with different languages as button or flag. i have all my factlets in diff languages saved in database already, all i need now is a function that will load my selected language on the click button or flag to the front page,each time the button or flag is click, i wont corresponding language to language to load from database.
    here is my code:
    (
    )
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="robots" content="noindex, nofollow" />
    <style type="text/css">
    
    
    div.container{
      width:100%;
      background-color:#e7ffcd;}
    div.header{
      background-color:#700000;
      font-size:1.5em;
      padding:0.4em 1.5em 0.4em 1.5em;
      border-style:outset;}
    div.nav{
      background-color:#600000;
      width:8em;
      min-height:51.5em;
      em;
      float:left;}
    div.content{
      background-color:#383838 ;
      margin-left:8em;
      min-height:50em;
      padding:0.4em 1.5em 0.4em 1.5em;
      border-style:inset;
      line-height:150%;}
    div.footer{
      background-color:#700000;
      clear:left;
      padding:0.4em 1.5em 0.4em 1.5em;
      border-style:outset;}
    div.nav-button{
      margin:5% 5% 5% 15%;}
    div.nav-button-mark{
      background-color:#ffaaaa;
      margin:5% 0% 5% 15%;}
    </style>
    <title>Framework: DIV based</title>
    </head>
    </style>
    <title>Framework: DIV based</title>
    </head>
    <body>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="robots" content="noindex, nofollow" />
    <title> PHP & MySQL </title>
    </head>
    <body>
    
    
    <center>
    
    
    <div class="container">
      <div class="header" align=center>
      ADAPTIVE INTERNATIONALISED WEBSITE
    <marquee direction="left" height="26" scrolldelay="90" scrollamount="6" behavior="alternate" loop="0";" id="Marquee1"><font style="font-size:13px" color="#00FF00" face="Arial Black"><i>University Library in Chinese, Japanese, French and Afrikaans.</i></font></marquee>
    
    <div class="header" align=left>
    <font style="font-size:15px" color="#FF" face="Tahoma">
    <select name="Languages" size="1" id="Combobox1" onselect="ShowObject('Combobox1', 1);return false;">
    <option type='selected' method='POST' name='$row[3]'>French</option>
    <option type='selected' method='POST' name='$row[1]'>Chinese(simplified)</option>
    <option type='selected' method='POST' name='$row[2]'>Japanese</option>
    <option type='selected' method='POST' name='$row[0]'>English</option>
    </select>
    <input type="submit" id="Button1" name="Button1" value="GO" style="postion:absolute;left:82px;width:35px;height:24px;font-family:Tahoma;font-size:13px;z-index:0">
    
    <?php
    
    
    
    
    /**
    
     * Just add this in your page where you
    
     * want the date/time to appear
    
     *
    
     * For more configuration options look
    
     * in the PHP manual at http://uk2.php.net/date
    
     */
    
    
    
    // Displays in the format Saturday, November 22, 2003 11.38
    
    echo date("l, F d, Y H:i " ,time());
    
    
    
    ?>
    
    </font>
      </div>
    
      <div class="nav">
        <!-- You may want to include the php echo $_SERVER['PHP_SELF'] so that one has the
             full URL rather than leave it to the Browser to complete  -->
        <div class="nav-button"><a href='?page=home'>home</a></div>
        <div class="nav-button"><a href='href='?page=page1'>gallery</a></div>
        <div class="nav-button"><a href='?page=page2'>business</a></div>
        <div class="nav-button"><a href='?page=page3'>contact us</a></div>
      </div>
    
      <div class="content">
    <?php
    "../../group01.php" ;
    $mysql_hostname="*************";
    $mysql_username="******";
    $mysql_password="*******";
    $link_id_resource=mysql_connect($mysql_hostname, $mysql_username, $mysql_password);
    if($link_id_resource === false){exit("Cannot make connection to the MySQL server");}
    mysql_query("SET NAMES 'utf8';", $link_id_resource); //utf8 stuff
    
    // Selecting a MySQL database
    
    $mysql_database="group05";
    $database_selected=mysql_select_db($mysql_database,$link_id_resource);
    mysql_query("SET NAMES 'utf8';", $link_id_resource); //utf8 stuff
    
    echo '<h2>• UNIVERSITY LIBRARY •</h2>';
    
    $sql_query = "SELECT Chinese FROM `Table`";
    $result=mysql_query($sql_query);
    while ($row=mysql_fetch_row($result)){
    echo $row[0]."<br/>";
       
    
    
    };
    mysql_close($link_id_resource);
    ?>
    
    
       
        
    
       
    </div>
    <div class="text">
    <font style="font-size:11px" color="#FF" face="Tahoma">
        © 2010 GroupOne. All right reserved
    </font>
      </div>
    
    </div>
    </body>
    </html> 
    (
    PHP:
    )


    urgent help needed as i need to submit it soon....thanks
     
    Last edited: May 13, 2010
    sam127, May 13, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    Repost your code within the php bbcode tags. ([ php ]code [ / php ]) - (remove spaces)
     
    danx10, May 13, 2010 IP
  3. sam127

    sam127 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    sorry, i dont understand what you mean
     
    sam127, May 13, 2010 IP
  4. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #4
    danx10, May 13, 2010 IP
  5. sam127

    sam127 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    done,thanks......any help please?
     
    sam127, May 13, 2010 IP
  6. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #6
    Try this:

    <?php
      //mysql connection...
      $mysql_hostname = "co-project.lboro.ac.uk";
      $mysql_username = "group05";
      $mysql_password = "gmp66env";
      
      $link_id_resource = mysql_connect($mysql_hostname, $mysql_username, $mysql_password);
      
      $mysql_database = "group05";
      $database_selected = mysql_select_db($mysql_database, $link_id_resource);
      
      function set_language($language)
      {
          global $link_id_resource, $database_selected;
          //escape to avoid sql parsing issues...
          $language = mysql_real_escape_string($language);
          $query = "SELECT " . $language . " FROM Table";
          $result = mysql_query($query);
          while ($row = mysql_fetch_row($result)) {
          //display language...
           echo $row[0];
          }
      }
      
      //ensure form is submitted...
      if (isset($_POST['submit'])) {
          //ensure excess whitespace is stripped and input is lowercase...
          $language = strtolower(trim($_POST['language']));
    
          //array of allowed/accepted languages...
          $languages = array('english', 'french', 'chinese', 'japanese');
          
          //validate input...
          if (in_array($language, $languages)) {
              set_language($language);
          } else {
              echo "Error, Unsupported language.";
          }
      }
      
    ?>
    <form method="post">
    <select name="language">
    <option value="english" selected="selected">English</option>
    <option value="french">French</option>
    <option value="chinese">Chinese (simplified)</option>
    <option value="japanese">Japanese</option>
    </select>
    <input type="submit" name="submit" value="Switch Language">
    </form>
    PHP:
     
    Last edited: May 13, 2010
    danx10, May 13, 2010 IP
  7. sam127

    sam127 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    thanks, but i tried it and not was displayed on my webpage. Please I want English as default language to be displayed and as other languages are selected and click switch language,it will load straight from database.
    Thanks a lot
     
    sam127, May 13, 2010 IP