FRIHOSTFORUMSSEARCHFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

How to call the method?

 


bukaida
I have a javascript code something like this
Code:


var Utf8 = {
 
   // public method for url encoding
   encode : function (string) {
      string = string.replace(/\r\n/g,"\n");
      var utftext = "";
 
      for (var n = 0; n < string.length; n++) {
 
         var c = string.charCodeAt(n);
 
         if (c < 128) {
            utftext += String.fromCharCode(c);
         }
         else if((c > 127) && (c < 2048)) {
            utftext += String.fromCharCode((c >> 6) | 192);
            utftext += String.fromCharCode((c & 63) | 128);
         }
         else {
            utftext += String.fromCharCode((c >> 12) | 224);
            utftext += String.fromCharCode(((c >> 6) & 63) | 128);
            utftext += String.fromCharCode((c & 63) | 128);
         }
 
      }
 
      return utftext;
   },
 
   // public method for url decoding
   decode : function (utftext) {
      var string = "";
      var i = 0;
      var c = c1 = c2 = 0;
 
      while ( i < utftext.length ) {
 
         c = utftext.charCodeAt(i);
 
         if (c < 128) {
            string += String.fromCharCode(c);
            i++;
         }
         else if((c > 191) && (c < 224)) {
            c2 = utftext.charCodeAt(i+1);
            string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
            i += 2;
         }
         else {
            c2 = utftext.charCodeAt(i+1);
            c3 = utftext.charCodeAt(i+2);
            string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
         }
 
      }
 
      return string;
   }
 
}

Now when I am trying to call the encode by the statement
Code:

$get = mysql_query("SELECT DISTINCT(author)FROM bibdata")or die(mysql_error());
    $get=Utf8.encode($get);

I am getting an error of calling to undefined function encode.
Please help.
rickylau
Did you realize that you're going to call Javascript functions inside PHP (I hope your last piece of code is a fragment of PHP code, it should be a piece of PHP code)? It is impossible to do so as Javascript runs on client side while PHP runs on server side. Also I'm quite curious that you got undefined function error rather than syntax error if you have embedded/included your Javascript code in PHP script. And the other thing is as I see in your Javascript code Utf8.encode should be converting a text into unicode, but what PHP function mysql_query returns is a resource not a string. Therefore, I'm sorry that I'm not sure what you are doing and I can't help you to solve the problem.
bukaida
I think my approach was wrong.To be more specific click the following link
http://www.compcon-asso.in/projects/biblio/search_by_author_form.php

If you type A in the textbox, it shows all the name begining with A. but when I try to search with that, nothing returns. My Database, connection string, tables and php script all are UTF8 complient. The code for search_by_author_form.php is
Code:

<? header("Content-Type: text/html; charset=UTF-8"); ?>
<?php
include("connect.php");
include("menu.php");
?>   
<html><head>
<script src="javascript/prototype.js" type="text/javascript" charset="utf8"></script>
 <script src="javascript/scriptaculous.js" type="text/javascript" charset="utf8"></script>
 <link rel="stylesheet" href="autosuggest.css" type="text/css" media="screen" charset="utf-8">
 </head>
 <body>
<div>
<label for="id"></label>
 <form name="form1" method="post" action="display_by_author.php">
  <label for="id"></label>
<h2><font color="green">Enter the Author name</font></h2><input type="text" name="id" value="" size="100" autocomplete="off" >
  </p>
</div>
  <label></label>
  <input type="submit" name="submit" value="Show">
</form>
<div class="page_name_auto_complete" id="id2"></div>

  <?php

    echo "<script type=\"text/javascript\">
    new Autocompleter.Local('id', 'id2',[";
    ?>
  <?php
    $get = mysql_query("SELECT DISTINCT(author)FROM bibdata")or die(mysql_error());
    while($r = mysql_fetch_array($get)){
    echo "'$r[author]',";}
    echo "'No REC'],{}";
    echo "); \n</script>";
    include 'footer.php';
?>
</body>
</html>

and the corresponding display_by_author.php is
Code:

<? header("Content-Type: text/html; charset=UTF-8"); ?>
<?
include 'menu.php';
include 'connect.php';
if(isset($_POST['submit'])){
  if(!empty($_POST['id'])){
    $auth=$_POST['id'];
    $query="SELECT *
    FROM bibdata
    WHERE author='$auth'
   group by b_id;";
    $result=mysql_query($query)or die(mysql_error());
    $num=mysql_num_rows($result);
    echo '
<html>
<head>
<title> Bengali Bibliographic System</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head><body>';

    if($num>0){
  echo'<div align="center"><strong><font face="Sylfaen" color="#800000" size="+3"><u>List of Books for the Author:&nbsp;&nbsp;';
  echo $auth;
  echo '</u></div><br><br><hr>';
  echo'<table align="center" border="1">
    <tr><td align="center"><b> Book ID</b> </td>
    <td align="center"><b>Subject</b></td>
    <td align="center"><b> Series</b></td>
    <td align="center"><b> Title</b></td>
    <td align="center"><b> Author</b></td>
    <td align="center"><b> Year of Publication</b></td>
    <td align="center"><b> Call Number</b></td>
   </tr>';

      $bg='#eeeeee';

      while($myrow=mysql_fetch_array($result)){
        extract($myrow);
        $bg=($bg=='#eeeeee' ? '#ffffff' : '#eeeeee');
       
        $query2="SELECT *
    FROM bibdata
    WHERE b_id='$myrow[0]';";
   
    $result2=mysql_query($query2)or die(mysql_error());
    $myrow2=mysql_fetch_array($result2);
   
    echo "<tr bgcolor=$bg>
<td align=\"center\"><a href=\"detail_by_auth.php?id=$myrow[0]\">$myrow[0]</a></td>
        <td align=\"left\">".stripslashes($myrow[1])."</td>
        <td align=\"left\">".stripslashes($myrow[2])."</td>
        <td align=\"left\">".stripslashes($myrow[3])."</td>
         <td align=\"left\">".stripslashes($myrow[5])."</td>
         <td align=\"left\">".stripslashes($myrow[7])."</td>
         <td align=\"left\">".stripslashes($myrow[16])."</td>
      
       </tr>";
}
}else{
  echo'<p><font color="red" size="+3">There is currently no Book record for the Author:&nbsp;&nbsp;';echo $cls;echo'</font></p>';
}

echo'</table></body></html>';
}
}
include 'footer.php';
 ?>

The two js files used here are
http://pastebin.com/m45ed175c
Please help.
Related topics

writing COM components in Perl
Python
Javascript Switch Method
Microsoft gunning for Adobe's PDF format?
Lantern Festival

FCC requires VoIP to clean up its 911 act
php variables
PHP Validation Class
witch game is better
What games our you looking foward to?

Another Joke-Duck Call
One Side of a Phone Call between James Bond...
Call of duty 2 VS UT 2007
Tutorial: Image Rollovers w/ Javascript
Ads problem
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.