Jump to content

janggu

Members
  • Posts

    18
  • Joined

  • Last visited

    Never

Posts posted by janggu

  1. Hi there,

     

    I was wondering if anyone could help me with creating a script for switching two languages. I am thinking of using a folder structure or an extension of file names in URL. For example, this script will look for the different extension or the folder structure as follow.

     

    about-e.php | about-f.php or

    en/about.php | fr/about.php

     

    I am open for any other suggestions and thank you!

  2. Hi there,

     

    I created a bilingual site and connect two different language tables by two language session variables. However, when a language sesssion is created, population of data is being delayed. Basically, I have to refresh my web browser a couple of times manually in order to see the change of the language. Please see my code below and tell me if this can be fixed. Thanks very much in advance!!!

     

    // Trigger language sessions

    <?

    if (isset ($_SESSION["lang"]))

    {

    if ($_SESSION['lang'] == "en")

    {

    echo '<a href='.$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'].'&lang=fr>Francais</a>';

    }

    else

    {

    echo '<a href='.$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'].'&lang=en>English</a>';

    }

    }

    ?>

     

    // Create sessions

    <?

    session_start();

     

    $lg = $_GET['lang'];

     

    if (!isset($_SESSION["lang"]))

    {

    $_SESSION['lang'] = "en";

    if ($lg=="en")

    {

    $_SESSION['lang'] = $lg;

    }

    if ($lg=="fr")

    {

    $_SESSION['lang'] = $lg;

    }

    }

    else

    {

    if ($_SESSION["lang"] == "en" && $lg == "fr")

    {

    session_destroy();

    $_SESSION["lang"] = $lg;

    }

    if ($_SESSION["lang"] == "fr" && $lg == "en")

    {

    session_destroy();

    $_SESSION["lang"] = $lg;

    }

    }

    ?>

     

    // Connect two language tables by session variable

    <?

    session_start();

      $conn = db_connect();

    if (isset ($_SESSION["lang"]))

    {

    if ($_SESSION['lang'] == "en")

    {

    $query = "select * from tbl_page_en where qs = '$qs'";

    }

    if ($_SESSION['lang'] == "fr")

    {

    $query = "select * from tbl_page_fr where qs = '$qs'";

    }

    }

      else

      {

      $query = "select * from tbl_page_en where qs = '$qs'";

      }

    ?>

  3. This is what have so far. Basically, I have two links of English/French with a query string called "lang". When one of these links is clicked, my script is supposed to create or update the session variables. Howerver, this is not working... PLEASE HELP!!!

     

    <?

    session_start();

    $lg = $_GET['lang'];

     

    if (!isset($_SESSION["lang"]))

    {

    $_SESSION['lang'] = "en";

    }

    else

    {

    if ($_SESSION["lang"] == "en" && $lg == "fr")

    {

    session_destroy();

    $_SESSION["lang"] = "fr";

    }

    if ($_SESSION["lang"] == "fr" && $lg == "en")

    {

    session_destroy();

    $_SESSION["lang"] = "en";

    }

    }

    ?>

     

  4. Thanks for your help but how can I add a condition? For instance,

    Select record between '05/01/06' to '05/10/06' and/or subject = 'Information'

    Is this possible? Perhaps, there is a PHP function???

    Thanks again!


    [!--quoteo(post=375028:date=May 18 2006, 06:30 PM:name=litebearer)--][div class=\'quotetop\']QUOTE(litebearer @ May 18 2006, 06:30 PM) [snapback]375028[/snapback][/div][div class=\'quotemain\'][!--quotec--]
    Might be a sledge hammer approach, but...

    Your text file

    [code]05/01/06,14.47:41 subject: Request received from mail@hotmail.com<br>05/01/06,14.47:41 subject: Request received from mail@hotmail.com<br>05/01/06,14.47:41 subject: Information received from mail@hotmail.com<br>[/code]

    the php file

    [code]
    <?PHP
    $file = "some.txt";
    $fp = f open($file, 'r');
    $contents = f read($fp, filesize($file));
    f close($fp);
    $needle="subject:";
    $delimiter = "|";
    $contents = str_replace($needle,$delimiter,$contents);
    $needle="received from";
    $delimiter = "|";
    $contents = str_replace($needle,$delimiter,$contents);
    $new_array = explode("<br>",$contents);
    $count = count($new_array);
    if(strlen(trim($new_array[$count-1]))<1) {
    array_pop($new_array);
    }
    $count = count($new_array);
    $i=0;
    for($i=0;$i<$count;$i++){
      $next_array[$i] = explode("|",$new_array[$i]);
    ?>
    <Pre>
    <?PHP

      print_r($next_array[$i]);
    ?>
    </pre>
    <?PHP
    }
    ?>[/code]

    the display

    [code]Array
    (
        [0] => 05/01/06,14.47:41
        [1] =>  Request
        [2] =>  mail@hotmail.com
    )

    Array
    (
        [0] => 05/01/06,14.47:41
        [1] =>  Request
        [2] =>  mail@hotmail.com
    )

    Array
    (
        [0] => 05/01/06,14.47:41
        [1] =>  Information
        [2] =>  mail@hotmail.com
    )[/code]
    Lite...
    [/quote]
  5. I am sorry for late response. Apparently, each record is ended by <br> tag and the search will be performed by date and subject. Below is how records are structure in text file.

    -----------
    [b]05/01/06[/b],14.47:41 [b]subject: Request[/b] received from mail@hotmail.com<br>05/01/06,14.47:41 subject: Request received from mail@hotmail.com<br>05/01/06,14.47:41 [b]subject: Information[/b] received from mail@hotmail.com<br>
    -----------
    Is it enough information to start?

    Thanks so much!!!

    [!--quoteo(post=374327:date=May 16 2006, 04:17 PM:name=obsidian)--][div class=\'quotetop\']QUOTE(obsidian @ May 16 2006, 04:17 PM) [snapback]374327[/snapback][/div][div class=\'quotemain\'][!--quotec--]
    it is fairly simple to read a text file and search the contents using PHP. the best method would most likely be to read the file line by line (assuming you have one record per line) and simply displaying the lines that have a match. could you be more specific in what you are after? for instance, give us an example of how your file is formatted and what you might be searching for. once we have that information, we may be able to help you with the details.
    [/quote]
  6. Hello,

    Does anyone know if it is possible to search data in text file and get result back with PHP? The search function will have to look for a specific word in a text file and dispay a list records that contain the word.

    Or, should I export this text file into MySQL and manipulate data from there? Any thought???
  7. [!--quoteo(post=373023:date=May 10 2006, 06:13 PM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ May 10 2006, 06:13 PM) [snapback]373023[/snapback][/div][div class=\'quotemain\'][!--quotec--]
    That wasn't so hard, was it?

    Your while loop is never going to go anywhere. You set it to 1 and then immediately check to see if it's less than 1.

    Better:[code]
    if (isset($_POST['id']))
    {
        foreach($_REQUEST['id'] as $val)
       {
        $sql = "UPDATE client2 SET
        FA = '1'
        WHERE id='$val'
        ";
        $result = mysql_query($sql) or die("Invalid query: " . mysql_error());
       }
    }
    [/code]
    [/quote]

    It works great. Thanks a lot!!!

    There is another issue though... I unchecked the boxes and saved it with the following code but it didn't work.
    [code]
    if (isset($_POST['id']))
    {
        foreach($_REQUEST['id'] as $val)
       {
        $sql = "UPDATE client2 SET
        FA = '1'
        WHERE id='$val'
        ";
        $result = mysql_query($sql) or die("Invalid query: " . mysql_error());
       }
    }
    else
    {
        foreach($_REQUEST['id'] as $val)
       {
        $sql = "UPDATE client2 SET
        FA = '0'
        WHERE id='$val'
        ";
        $result = mysql_query($sql) or die("Invalid query: " . mysql_error());
        }
    }
    [/code]
  8. Ok. I lied. Here is what I have so far.

    client.php page
    [code]
    <form action="update.php" method="post" enctype="multipart/form-data">
              <table width="100%">               
                <tr>            
                  <th valign="bottom" align="center" nowrap>Date</th>
                  <th valign="bottom" align="center" nowrap>Name</th>
                  <th valign="bottom" align="center" nowrap>Email</th>
                  <th valign="bottom" align="center" nowrap>Subscribe</th>
                  <th valign="bottom" align="center" nowrap>Action</th>              
                </tr>            
                
                 <?php
                  
                  if (mysql_num_rows($getClient) <> 0) {
                  
                      // display
                      while ($r = mysql_fetch_array($getClient)) {
                          echo "<tr>";                    
                        echo "<td align='center' valign='top'>" .$r['date']. "</td>";
                        echo "<td align='center' valign='top'>" .$r['name']."</td>";
                        echo "<td align='center' valign='top'>" .$r['email']. "</td>";
                        echo "<td align='center' valign='top'><input type='checkbox' name='id[]' value=".$r['id']."></td>";                    
                        echo "<td valign='top' align='center'><a href='view.php?id=".$r["id"]."'>View</a>";                        
                        echo "</td>";
                        echo "</tr>";
                        echo "<tr><td colspan='5'><hr size='1' noshade></td></tr>";
                    }
                    }
                        
                  ?>        
               <tr>
                   <td align="center" colspan="5">
               <input type="submit" value="Update">
                   </td>
               </tr>      
             </table>
             </form>
    [/code]

    update.php page

    [code]
    if (isset($_POST['id']))
    {
    $counter = 1;
    while ($counter < 1) {
    if ($_POST[$id] != "") {
    $id = "id" . $counter;

    $sql = "UPDATE client2 SET
    FA = '1'
    WHERE id='$id'
    ";
    $result = mysql_query($sql) or die("Invalid query: " . mysql_error());
    }
    $counter++;
    }
    }
    [/code]
  9. I have a list of client on a page and need to add checkboxes on each client. My intention is when users click the checkboxes, the page passes ids of the clients so that I could update the client info – let’s say the checkbox is for getting newsletter. The main purpose of this feature is users can simply click the checkboxes and update info without going into each client’s detailed page.

    Could anyone please tell me some directions with an example?

    Thanks a lot!
  10. Thanks a lot! That resolved the issue. However, I have another problem that the text is broken up.

    "You men tioned in your last message that he should register again in order to receiv e the"

    I tried to find a pattern and looks like it happens every 14 characters.

    Please help!!! :(

    [!--quoteo(post=362631:date=Apr 7 2006, 07:22 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Apr 7 2006, 07:22 PM) [snapback]362631[/snapback][/div][div class=\'quotemain\'][!--quotec--]
    You have magic quotes (see [a href=\"http://www.php/net/get_magic_quotes_runtime\" target=\"_blank\"]get_magic_quotes_runtime[/a]) turned on in your php.ini file. Use the function [a href=\"http://www.php.net/stripslashes\" target=\"_blank\"]stripslashes[/a]() to remove the slashes.

    Ken
    [/quote]
  11. Thanks for your info but I am not sure how to increment a session (I am still new in PHP). Could you please give me a detailed example?

    [!--quoteo(post=345463:date=Feb 13 2006, 08:04 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Feb 13 2006, 08:04 PM) [snapback]345463[/snapback][/div][div class=\'quotemain\'][!--quotec--]
    If your using sessions then create an extra session var, called [b][i]attempts[/i][/b] and increment attempts by 1 every time the user tries to login, then check whether $_SESSION['attampts'] is equal to three, if it is display error messages, else carry on.
    [/quote]
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.