PHP - Calling Function In Middle Of Mysql Query.
Hi All,
I am working on system where i am storing column names in one table of database. To retrieve value of columns with separation of comma (exp. clol1, col2,col3..). for this i am using one function which i am calling middle of mysql query. but i am not getting fetch result over there. Below is the function i have to fetch column names. Code: [Select] function retrieve_columns() { $brand_id = $_SESSION['SESS_PRODUCT_CODE']; global $columnlist; $columns_query= "Select column_name from columns_list_to_display where brand_id=$brand_id"; $result=mysql_query($columns_query); $row_num=mysql_num_rows($result); $i=0; while ($row = mysql_fetch_array($result)) { $columnlist = ""; $i++; if($i != $row_num) { echo $row['column_name'].", "; } else { echo $row['column_name'].""; } } } I am writting query like as below: Code: [Select] $query = "SELECT " . $columnlist . "FROM $userlead_table LEFT JOIN notes ON $userlead_table.id = notes.leads_id LEFT JOIN lead_status ON $userlead_table.status = lead_status.status_code WHERE ((Date(a.submitted)>='$datefrom' AND Date(a.submitted)<='$dateto')) ORDER BY a.submitted DESC"; Please let me know where i am doing wrong. Hope one of this forum member would have proper solution for it. Thanks in advance. Regards, Jitendra Similar TutorialsI've created a function getsub(). The idea is that this function contains a query that grabs records from the categories table, using the $row['cat_id'] that I pass to it from within an existing while ($row=mysql_fetch_assoc($res)) loop. Heres the function: function getsub($rowid,$catsort) { global $system, $LANGUAGES, $subres; $subquery = "SELECT * FROM webid_categories WHERE parent_id = " . $rowid . " " . $catsort; $subres = mysql_query($subquery); $system->check_mysql($subres, $subquery, __LINE__, __FILE__); return $subres; } And heres the code that calls this function and passes the $row['cat_id'] value to it: // prepare categories list for templates/template // Prepare categories sorting if ($system->SETTINGS['catsorting'] == 'alpha') { $catsorting = ' ORDER BY cat_name ASC'; } else { $catsorting = ' ORDER BY sub_counter DESC'; } $query = "SELECT cat_id FROM " . $DBPrefix . "categories WHERE parent_id = -1"; $res = mysql_query($query); $system->check_mysql($res, $query, __LINE__, __FILE__); $query = "SELECT * FROM " . $DBPrefix . "categories WHERE parent_id = " . mysql_result($res, 0) . " " . $catsorting . " LIMIT " . $system->SETTINGS['catstoshow']; $res = mysql_query($query); $system->check_mysql($res, $query, __LINE__, __FILE__); while ($row = mysql_fetch_assoc($res)) { $subcats = getsub($row['cat_id'],$catsorting); while($subrow = mysql_fetch_assoc($subcats){ $template->assign_block_vars('sublist', array( 'SID' => $subrow['cat_id'], 'SNAME' => $category_names[$getrow['cat_id']] )); } $template->assign_block_vars('cat_list', array( 'CATAUCNUM' => ($row['sub_counter'] != 0) ? '(' . $row['sub_counter'] . ')' : '', 'ID' => $row['cat_id'], 'IMAGE' => (!empty($row['cat_image'])) ? '<img src="' . $row['cat_image'] . '" border=0>' : '', 'COLOUR' => (empty($row['cat_colour'])) ? '#FFFFFF' : $row['cat_colour'], 'NAME' => $category_names[$row['cat_id']] )); } then a .tpl file just references the {sublist.SID} and {sublist.SNAME} variables. BUT.... It ain't working. My page just goes blank. Any help would be massively appreciated. Thanks in advance for help. I have a PHP script that has a function called traverseXMLNodes and it passes an xml string. I want anyone with a username and password to be able to call this function from his website or application or programming. In short i want my site to act as an API(Application Programming Interface). I am really stuck as to how to go about this. There are other functions i would like to call as well so traverseXMLNodes is not the only function i want to my "API" users to access. Below is the code I am using. the filename for my php i called remote.php. I am using the following query string to test and no results are returned. http://localhost/testfolder/remote.php?xmlstring=20 Code: [Select] <?php $allowedfuncs = array('xmlstring','remotefunction2'); if(in_array($_get['xmlstring'], $allowedfuncs)) { $func = $_get['xmlstring']; $output = traverseXMLNodes($func); // This calls $_get['funccall']() echo $output; } else { exit(); } function traverseXMLNodes ($func) { echo "The XML string is"; echo "<br/>"; echo $func; echo "<br/>"; } /* More functions go here */ ?> Okay, this is getting on my nerves now, my head is throbbing probably just need a break from it all now. I'm currently getting the following message; Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\xampp\htdocs\duff3\test3.php on line 25 Can anyone figure out and explain why this isn't working for me, I believe I am calling the function correctly and then putting the result into a while loop. Code: [Select] <?php function getPageContent($selectedPage) { $sql = "SELECT * "; $sql .= "FROM tbl_pages "; $sql .= "WHERE tbl_pages.pageCategoryId = ".$selectedPage." "; $sql .= "AND active = 1 "; $sql .= "LIMIT 1"; $result = mysql_query($sql) or die ("Error in page sql query:". $sql); return $pageSet; } ?> Code: [Select] <?php require_once ''.$_SERVER['DOCUMENT_ROOT'].'/duff3/commonResources/dbConnection/dbQueryClass.php'; ?> <?php #FUNCTIONS IS A TEMP FILE UNTIL OO PHP COMES INTO PLAY require_once ("commonResources/includes/functions.php"); # if page isn't set then set it to default. if(isset($_GET["page"])) { $selectedPage = $_GET["page"]; } else { $selectedPage = 1; } #call function to select all page $pageSet = getPageContent($selectedPage); ?> <!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"> <head> <title> <?php while ($row = mysql_fetch_array($pageSet)) { # Start while loop echo $row["pageTitle"]; ?> </title> <link rel="shortcut icon" href="commonResources/images/container/favicon.ico" /> <link rel="stylesheet" type="text/css" href="<?php $_SERVER["DOCUMENT_ROOT"] ?>/duff3/commonResources/css/style.css" /> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252" /> <!-- PUT COMMON JAVASCRIPT FILES IN AN INCLUDE 05/05/2011 --> <script type="text/javascript" src="commonResources/javaScript/jQuery.js"></script> <script type="text/javascript" src="commonResources/javaScript/jQueryTest/menu.js"></script> <?php require_once ("".$_SERVER["DOCUMENT_ROOT"]."/duff3/commonResources/includes/tinymce.php"); ?> </head> <body> <div id="viewContainer"><!--OPEN DIV FOR VIEW CONTAINER --> <div id="headerContent"><!--OPEN DIV FOR HEADER CONTENT --> <div class="logoContent"><!--OPEN DIV FOR LOGO CONTAINER --> <a href="index.html"><img src="<?php $_SERVER["DOCUMENT_ROOT"] ?>/duff3/commonResources/images/container/logo.png" alt="Hannah Jane Duff" longdesc="Hannah Jane Duff Home Link" /></a> </div><!--CLOSE DIV FOR LOGO CONTAINER --> </div><!--CLOSE DIV FOR HEADER CONTENT --> <!-- TEMP TAKE OUT AND PUT INTO HEADER AREA --> <div id="mainContent"><!--OPEN DIV FOR MAIN CONTENT--> <div class="centreContent"><!--OPEN DIV FOR CENTRE CONTENT--> <div id="menuContent"><!--OPEN DIV FOR MENU CONTENT--> <div id="menu"> <ul class="menu"> <li><a href="index.html" class="main"><span>Home</span></a></li> <li><a href="" class="main"><span>bio</span></a> <div><ul> <li><a href=""><span>violin</span></a></li> <li><a href=""><span>piano</span></a></li> <li><a href=""><span>singing</span></a></li> <li><a href="" class="parent"><span>teaching</span></a> <div><ul> <li><a href="" class="parent"><span>aberdeen</span></a> <div><ul> <li><a href="#"><span>aberdeen 1</span></a></li> </ul></div> </li> <li><a href="" class="parent"><span>bradford</span></a> <div><ul> <li><a href=""><span>bradford 1</span></a></li> </ul></div> </li> <li><a href="" class="parent"><span>leeds</span></a> <div><ul> <li><a href=""><span>leeds 1</span></a></li> </ul></div> </li> </ul></div> </li> <li><a href="" class="parent"><span>influences</span></a> <div><ul> <li><a href=""><span>classical</span></a></li> <li><a href=""><span>folk</span></a></li> </ul></div> </li> <li><a href="" class="parent"><span>other</span></a> <div><ul> <li><a href=""><span>folk′d</span></a></li> <li><a href=""><span>string quaret</span></a></li> </ul></div> </li> </ul></div> </li> <li><a href="" class="main"><span>publicity</span></a> <div><ul> <li><a href="" class="parent"><span>news</span></a> <div><ul> <li><a href=""><span>may 2011</span></a></li> <li><a href=""><span>march 2011</span></a></li> </ul></div> </li> <li><a href=""><span>gallery</span></a></li> <li><a href=""><span>other</span></a></li> </ul></div> </li> <li><a href="" class="main"><span>recordings</span></a> <div><ul> <li><a href=""><span>all</span></a></li> <li><a href=""><span>new york dolls</span></a></li> <li><a href=""><span>classical</span></a></li> </ul></div> </li> <li><a href="" class="main"><span>contact</span></a></li> </ul></div> </div><!--CLOSE DIV FOR MENU CONTENT--> <div class="paraBlock"><!--OPEN DIV FOR PARA BLOCK --> <p><?php echo $row["pageContent"]; ?></p> </div><!--CLOSE DIV FOR PARA BLOCK--> <div class="clearArea"><!--OPEN DIV FOR CLEAR AREA--> </div><!--CLOSE DIV FOR CLEAR AREA--> </div><!-- CLOSE DIV FOR CENTRE CONTENT--> </div><!--CLOSE DIV FOR MAIN CONTENT--> <div id="footerContent"><!--OPEN DIV FOR FOOTER CONTENT--> <div class="leftFooter"><!--OPEN DIV FOR LEFT FOOTER--> © <?php echo date(Y); ?> All Rights Reserved | Design by <a href="http://www.innovationation.co.uk/">Innovationation UK</a> </div><!--CLOSE DIV FOR LEFT FOOTER--> <div class="rightFooter"><!--OPEN DIV FOR RIGHT FOOTER--> <a href="">Copyright | </a> <a href="">Disclaimer | </a> <a href="">Privacy Policy </a> <a href="">Terms of Use | </a> <a href="">Site Map | </a> <a href="loginArea/login.php">Admin</a> </div><!--CLOSE DIV FOR RIGHT FOOTER--> </div><!--CLOSE DIV FOR FOOTER CONTENT--> <?php } ?> </div><!--CLOSE DIV FOR VIEW CONTAINER--> </body> </html> Hi, Doing a Query SELECT * FROM table WHERE field BETWEEN low_number AND high_number If i have three rows with three numbers: IE: 27, 50, 80. and i run the query above, it returns a result of: 27 and 50. How can i get it to return a result of: 27,50, and 80.?? WHY: age range search: i want to return an age range of people = and between the age of say: 20 and 70 but i want to include the 20 and 70. How can i do this? Moodle 2.5 *nix server Theme: Essential ---------------------- Hi Folks I have a small mind bender in how php is returning results from a mysql query. There are two issues: 1) The mysql query from phpmyadmin is correct, while the php function that handles the query from the website is not. 2) It takes a very long time to run this query with php, 30 seconds to over a minute. Phpmyadmin is rather quick (Query took 0.0239 seconds). The query is: SELECT u.firstname AS 'Name' , u.lastname AS 'Surname', c.shortname AS 'Course', ( CASE WHEN gi.itemname LIKE '%summative%' THEN 'SUMMATIVE' WHEN gi.itemname LIKE '%formative 2%' THEN 'FORMATIVE 2' ELSE 'MC' END) AS 'Assessment', from_unixtime(gi.timemodified, '%d/%m/%y') AS 'Date', IF (ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) > 70,'Yes' , 'No') AS Pass, ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) AS 'Mark', ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) AS 'Mark' FROM mdl_course AS c JOIN mdl_context AS ctx ON c.id = ctx.instanceid JOIN mdl_role_assignments AS ra ON ra.contextid = ctx.id JOIN mdl_user AS u ON u.id = ra.userid JOIN mdl_grade_grades AS gg ON gg.userid = u.id JOIN mdl_grade_items AS gi ON gi.id = gg.itemid JOIN mdl_course_categories AS cc ON cc.id = c.category WHERE gi.courseid = c.id AND gi.itemname != 'Attendance' AND u.firstname LIKE '%03%' AND gi.itemname LIKE '%mative%' ORDER BY `Name` , `Surname` , `Course`, `Assessment` ASCWhen I run the query in phpmyadmin , it gives back; Name Surname Category Module Course Assessment Date Competent Mark G03 Itumeleng Velmah Mokwa Fundamentals Communications CO1 119472 FORMATIVE 2 07/04/14 Yes 100.00 G03 Itumeleng Velmah Mokwa Fundamentals Communications CO1 119472 SUMMATIVE 07/04/14 Yes 100.00 G03 Itumeleng Velmah Mokwa Fundamentals Communications CO2 119457 FORMATIVE 2 05/04/14 Yes 100.00 G03 Itumeleng Velmah Mokwa Fundamentals Communications CO2 119457 SUMMATIVE 05/04/14 Yes 88.00 G03 Lally Sheila Mokane Fundamentals Communications CO1 119472 FORMATIVE 2 07/04/14 NYC 59.00 G03 Lally Sheila Mokane Fundamentals Communications CO1 119472 SUMMATIVE 07/04/14 Yes 90.00 G03 Lally Sheila Mokane Fundamentals Communications CO2 119457 FORMATIVE 2 05/04/14 Yes 100.00 G03 Lally Sheila Mokane Fundamentals Communications CO2 119457 SUMMATIVE 05/04/14 Yes 98.00And it is perfect so I have no issues with that. Now in php I call; function print_overview_table_groups($COURSE, $choosegroup, $fromdate, $todate, $numarray) { global $DB; //check data if(!$choosegroup){ die('No Records To Display.'); } $thisgroup = $numarray[$choosegroup]; $sql = "SELECT DISTINCT u.firstname AS 'Name' , u.lastname AS 'Surname', (CASE WHEN cc.parent = '2' THEN 'Fundamentals' WHEN cc.parent = '3' THEN 'Core' WHEN cc.parent = '4' THEN 'Elective' END) AS 'Category', cc.name AS 'Module', c.shortname AS 'Course', (CASE WHEN gi.itemname LIKE '%summative%' THEN 'SUMMATIVE' WHEN gi.itemname LIKE '%formative 2%' THEN 'FORMATIVE 2' ELSE 'MC' END) AS 'Assessment', from_unixtime(gi.timemodified, '%d/%m/%y') AS 'Date', IF (ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) > 70,'Yes' , 'NYC') AS Competent, ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) AS 'Mark' FROM mdl_course AS c JOIN mdl_context AS ctx ON c.id = ctx.instanceid JOIN mdl_role_assignments AS ra ON ra.contextid = ctx.id JOIN mdl_user AS u ON u.id = ra.userid JOIN mdl_grade_grades AS gg ON gg.userid = u.id JOIN mdl_grade_items AS gi ON gi.id = gg.itemid JOIN mdl_course_categories AS cc ON cc.id = c.category WHERE gi.courseid = c.id AND gi.itemname != 'Attendance' AND u.firstname LIKE '%03%' AND gi.itemname LIKE '%mative%' ORDER BY `Name` , `Surname` , `Course`, `Assessment` ASC"; return $DB->get_records_sql($sql); }This is returned to the index.php page from the function call; $lists = print_overview_table_groups($COURSE, $choosegroup, $fromdate, $todate, $numarray); print "<pre>"; print_r($lists); print "</pre>";The result is baffling... Array ( [G03 Itumeleng] => stdClass Object ( [name] => G03 Itumeleng [surname] => Mokwa [category] => Fundamentals [module] => Communications [course] => CO2 119457 [assessment] => SUMMATIVE [date] => 05/04/14 [pass] => Yes [mark] => 88.00 ) [G03 Lally] => stdClass Object ( [name] => G03 Lally [surname] => Mokane [category] => Fundamentals [module] => Communications [course] => CO2 119457 [assessment] => SUMMATIVE [date] => 05/04/14 [pass] => Yes [mark] => 98.00 ) )I only get one record for each student. Can anyone help me solve this? Regards Leon On my web page, there is a variable called $submission. I would like to display exactly 11 rows from the query below: the row where $submission equals $row["title"], 5 rows above it, and 5 rows below it. All ranked by points descending. How can I do this? Code: [Select] $sqlStr = "SELECT title, points, submissionid FROM submission ORDER BY points DESC"; $result = mysql_query($sqlStr); $arr = array(); $count=1; echo "<table class=\"samplesrec\">"; while ($row = mysql_fetch_array($result)) { echo '<tr >'; echo '<td>'.$count++.'.</td>'; echo '<td class="sitename1">'.$row["title"].'</td>'; echo '<td class="sitename2"><div class="pointlink2">'.number_format($row["points"]).'</div></td>'; echo '</tr>'; } echo "</table>"; I need to call usort from a class function, and I'm puzzled about how to define the comparison function. I've tried to define the comparison function in the same class, but I can't get usort to call it. I found one hint that it will work if I make the comparison function static, but I tried that, and it didn't work for me. If I define the comparison function outside the class, it won't have access to object properties that it needs to operate. The only solution I can think of is to define the comparison function outside the class and put the object properties it needs in globals. Is there a cleaner way to do this? Question 1) Is the only and proper way to call a parent function "parent::function()"? Are there other/better ways from within a child function? Question 2) What are the deciding factors for when to make a function or attribute static? How do you make that decision? Assuming 5.3... Thanks. This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=322184.0 I am using simple machines forum, and by placing a link to ssi.php in the top of my php page Code: [Select] <?php require_once('/forum/SSI.php');?>I am able to use some ssi functions. My problem is calling another function from within a function. My first function is this: Code: [Select] <?php $allowed_groups = array(1,5); $can_see = FALSE; foreach ($allowed_groups as $allowed) if (in_array($allowed, $user_info['groups'])) { $can_see = TRUE; break; } if ($can_see) { echo ' <div> this is text that i want certain groups to see </div>'; } else { //message or section to show if they are not allowed. echo 'this is text that i dont want certain groups to see'; } ?> This is my second function: Code: [Select] <?php ssi_welcome(); ?> I want to put the second function inside the first function, like so: Code: [Select] if ($can_see) { echo ' <div> <?php ssi_welcome(); ?> </div>'; this just gives me the "<?php ssi_welcome(); ?>" displayed on the actual site, it is not calling the separate function. I have tried different approaches, e.g. $function ssi_welcome; but all it does is display this as text as well.. Please can some one point me in the right direction. Thank you Hi, I got a little problem with calling a PHP function from a href. I got my site all set up, and am calling the function like this: Code: [Select] <?php echo '<a href="'.changeRecentPosts().'" class="image">' ?> This does indeed work, but it calls the function every time I refresh my page.. Which isn't the effect I was trying to achieve. I tried to change it to : Code: [Select] <?php echo '<a href="#" onClick="'.changeRecentPosts().'" class="image">' ?> But that didn't work either. It also seems it only calls it when I refresh my page, but never when I click it (I guess because PHP is handeled before HTML or something similar?). If you can think of any way (even in AJAX, or whatever other language...) feel free to, I think I can figure it all out. Thank you! I have this piece of code: Code: [Select] function newmessage() { box = new LightFace({ title: 'New message', width: 600, height: 400, content: "<form method='post' action='sendmessage.php'>To: <br><input type='text' name='to'><br><br>Subject: <input type='text' size='94' name='subject'><br><br><textarea name='message' rows='13' cols='63'></textarea><br><br><input type='submit' value='Send' name='send'><input name='from' type='hidden' value='<? echo $username; ?>'></form>", buttons: [ { title: 'Close', event: function() { this.close(); } } ] }); box.open(); } As well as this piece of code: Code: [Select] $userid = mysql_real_escape_string($_SESSION['userid']); //WALLNOT $db2 = "SELECT status FROM comments WHERE touser='$username' AND status='0'"; $db2connect = $database->query($db2); $status2 = "SELECT status FROM friends2 WHERE user2='$username' and status='0'"; $test = $database->query($status2); $statfromdb = "SELECT stat FROM wallposts WHERE person='$username' AND stat='0'"; $status = $database->query($statfromdb); $GetStatus = "SELECT byuser, status, dtime FROM commentstatus WHERE status='$Naw'and person='$username' AND byuser!='$username'"; $ConnectGetStatus = $database->query($GetStatus); $Getmsg = "SELECT status FROM messages WHERE status='0' AND touser='$username'"; $ConnectGetmsg = $database->query($Getmsg); $row = mysql_fetch_array($test); $row2 = mysql_fetch_array($ConnectGetmsg); $getrow = mysql_fetch_array($status); $getrow2 = mysql_fetch_array($db2connect); $StatusComment = mysql_fetch_array($ConnectGetStatus); //Select profile picture $GetProfilePicture = "SELECT profilepicture FROM users WHERE username='$username'"; $ConnectProfilePicture = $database->query($GetProfilePicture); $ProfilePicture = mysql_fetch_array($ConnectProfilePicture); $MyProfilePicture = $ProfilePicture['profilepicture']; That I use in 19 different pages, is there anyway I can put them all into one page, and just them through a function? It takes so much time when loading if I have it on each page? And if you have any other tips how to optimize my loading speed please write them. Thank you in advance! *Edit: Bad grammar. Hi all! First off, sorry if this question is a completely dumb one but i'm really new to PHP. I'll paste the code to start with... function getReasons ($id) { global $link; $rst = mysql_query('SELECT r.name as reason FROM entries_feedback_comments as f LEFT JOIN reasons as r ON r.id = f.reason_id WHERE f.feedback_id ='. $id, $link); while ($row = mysql_fetch_assoc($rst)) { echo $row['reason']; } } later on in the code.... inside a table structure i do this... echo '<tr class="' . ($y?'even':'odd') . '">'; echo '<td colspan="10" class="freetext">'.getReasons($row['id']).'</td>'; echo '</tr>'; echo '<tr class="' . ($y?'even':'odd') . '">'; echo '<td colspan="10" class="freetext">'.$row["freetype"].'</td>'; echo '</tr>'; (I have left put the "freetype" bit of code in to show you that it works with this row but not with the function). Basically, what I see is the result of the function outside of the table itself rather than in the table row. Is there a reason for this? Does a function have to be put in specific places in the code? Thank you for your help. Sam Hi, I was looking around the web for a image resizer script and I came across this one. http://www.scriptol.com/scripts/thumbnail-maker.php The weird thing is, it says to use this syntax to get it to work php resizer.php -j myimage.png Well.. I don't seem to understand how that makes it work, Normally I would run a php script by looking for it's main function and running it like: mainfunction(); Maybe I'm interpreting it wrong, but how is this script suppose to run? Hi guys, I am having a tough time executing the code inside the javascript. Everything is working fine with the Php code and I am able to see the output of variable myValue too.. But the problem is nothing is being executed inside the javascript..Not even the first statement of the javascript..When I look at the output sent by the HTML to the browser, the output is what is listed after this code which is right at the bottom of this page. Please advise. Code: [Select] <html> <head> <title>AES (Rijndael) Encryption Test in JavaScript</title> <script src="aes-enc.js" type="text/javascript" language="JavaScript"></script> <script src="aes-dec.js" type="text/javascript" language="JavaScript"></script> <script src="aes-test.js" type="text/javascript" language="JavaScript"></script> <script type="text/javascript"> function doDecryption() { document.println("Inside Javascript"); var ct, key; var theForm = document.forms[0]; blockSizeInBits=128; keySizeInBits = theForm.keySize[theForm.keySize.selectedIndex].value; if (theForm.key.value.toLowerCase().indexOf("0x") == 0) theForm.key.value = theForm.key.value.substring(2); if (theForm.ciphertext.value.toLowerCase().indexOf("0x") == 0) theForm.ciphertext.value = theForm.ciphertext.value.substring(2); if (theForm.key.value.length*4 != keySizeInBits) { alert("For a " + keySizeInBits + " bit key, the hex string needs to be " + (keySizeInBits / 4) + " hex characters long."); if (theForm.key.select) theForm.key.select(); return; } if (theForm.ciphertext.value.length*4 != blockSizeInBits) { alert("For a " + blockSizeInBits + " bit block, the hex ciphertext string needs to be " + (blockSizeInBits / 4) + " hex characters long."); if (theForm.ciphertext.select) theForm.ciphertext.select(); return; } ct = hex2s(<?php echo $myValue; ?>); document.println("Inside Javascript"); document.write(ct); // key = hex2s(theForm.key.value); // theForm.plaintext.value = byteArrayToHex(rijndaelDecrypt(ct, key, "ECB")); } </script> </head> [syntax=php] <?php mysql_connect("localhost","root",""); mysql_select_db("encryption") or die(mysql_error()); $userId = $_POST['userId']; if (($_SERVER['REQUEST_METHOD'] == 'POST') && ($_POST['key'] == "")) { $query = mysql_query("select * from employee_details where id = '$userId'"); if($row=mysql_fetch_assoc($query)) { echo '<tr>'; foreach($row as $value) echo '<td>'.$value.'</td>'; echo '</tr>'; } else { echo "No rows returned"; }} else if (($_SERVER['REQUEST_METHOD'] == 'POST') && ($_POST['key'])) { $columname = "ciphertext"; $tablename = "employee_details"; function getField($field, $tbl_name, $condition) { $result = mysql_query("SELECT $field FROM $tbl_name WHERE id = ".$condition); return @mysql_result($result, 0); } $myValue = getField($columname,$tablename,$userId); echo "$myValue"; //doDecryption(); } echo '<script type="text/javascript"> doDecryption(); </script>'; echo "whats happening"; ?> </body> </html> [/syntax] <body> CODE THAT IS SENT AS HTML OUTPUT TO THE BROWSWER Code: [Select] <!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>AES (Rijndael) Encryption Test in JavaScript</title> <script src="aes-enc.js" type="text/javascript" language="JavaScript"></script> <script src="aes-dec.js" type="text/javascript" language="JavaScript"></script> <script src="aes-test.js" type="text/javascript" language="JavaScript"></script> <script type="text/javascript" language="JavaScript"> function doDecryption() { document.alert("Inside Javascript"); var ct, key; var theForm = document.forms[0]; blockSizeInBits=128; keySizeInBits = theForm.keySize[theForm.keySize.selectedIndex].value; if (theForm.key.value.toLowerCase().indexOf("0x") == 0) theForm.key.value = theForm.key.value.substring(2); if (theForm.ciphertext.value.toLowerCase().indexOf("0x") == 0) theForm.ciphertext.value = theForm.ciphertext.value.substring(2); if (theForm.key.value.length*4 != keySizeInBits) { alert("For a " + keySizeInBits + " bit key, the hex string needs to be " + (keySizeInBits / 4) + " hex characters long."); if (theForm.key.select) theForm.key.select(); return; } if (theForm.ciphertext.value.length*4 != blockSizeInBits) { alert("For a " + blockSizeInBits + " bit block, the hex ciphertext string needs to be " + (blockSizeInBits / 4) + " hex characters long."); if (theForm.ciphertext.select) theForm.ciphertext.select(); return; } ct = hex2s(<br /> <b>Notice</b>: Undefined variable: myValue in <b>C:\wamp\www\AES4U\Decryptedresults.php</b> on line <b>41</b><br /> ); document.write("Inside Javascript"); document.write(ct); // key = hex2s(theForm.key.value); // theForm.plaintext.value = byteArrayToHex(rijndaelDecrypt(ct, key, "ECB")); } </script> </head> <body> <br /> <b>Notice</b>: Undefined index: userId in <b>C:\wamp\www\AES4U\Decryptedresults.php</b> on line <b>58</b><br /> // Do not worry about this notice because teh value has not been posted it is not able find this value. </body> Code: [Select] <?php class My { public function disp() { echo "ehllo"; } } ?> <html> <head> <script type="text/javascript"> function displaymessage() { document.write(My.disp()); } </script> </head> <body> <form> <input type="button" value="Click me!" onclick="displaymessage()" /> </form> </body> </html> HEllo I wanted to know wheter php function can be call in js functions. Please Help. When ever I try to google this I always get it the other way round "Calling PHP from jQuery" which is now what I need. Basically I want, When the script starts, For PHP to check if an array is empty and if it's not call a jQuery function (This would be the jQuery UI Dialog box). If you can help me here or even post a link to a resource then I will kiss ya. No homo. Thanks in advance! Whenever I want to use AJAX (using jQuery) I store the PHP code in a seperate file and then send an retrieve data from that file using AJAX. However I was wondering if you can just call a PHP function. Then it would save me having to put each function in a seperate file? Thanks for any help. can someone help me I am trying to call a class function using a varible.... example say i go to index.php?page=contact i want to pull that class with out doing a switch statement can someone help me Code: [Select] <?php $Site = page; $Site->getPage($_GET['page']); ?> Code: [Select] <?php class page extends site { function getPage($page) { return $this->$page; } function Contact() { echo '<h2>Contact test</h2>'; echo '<form> </form>'; } } ?> |