PHP - Calling A Function Doesn't Return Expected Results
I created a function called converter. My code doesn't look like it processes anything after the first if . This is what is displayed in browser.
Convert a String original string: roses Are red, violets are blue.... converted string: roses are red, violets are blue.... converted string: roses are red, violets are blue.... converted string: roses are red, violets are blue.... <html> <head> <title>Create a PHP Function to Convert a String</title> </head> <body bgcolor="pink"> <h2>Convert a String</h2> <?php $phrase = "roses Are red, violets are blue...."; function converter($arg1, $arg2){ if($arg1="lower"){ return strtolower($arg2); } elseif ($arg1="upper"){ return strtoupper($arg2); } else /* if($arg1="title")*/{ return ucwords($arg2); } } print "original string: ".$phrase."<br />"; print "converted string: ".converter("upper",$phrase)."<br />"; print "converted string: ".converter("lower",$phrase)."<br />"; print "converted string: ".converter("title",$phrase)."<br />"; ?> </body> </html> Similar TutorialsI have an avatar upload script. The uploading and moving of the image file to the correct directory works fine, but the displaying of the image causes problems. This is the code that is supposed to display the avatar. // _DISPLAY_ avatar - START $query2 = "SELECT * FROM user WHERE user_id = '$dbuser_id'"; $row2 = mysqli_query ($dbc, $query2) or die (mysqli_error($dbc)); $assoc2 = mysqli_fetch_assoc ($row2); $target = AVATAR_UPLOADPATH; $avatar_name = $target . $assoc2['avatar']; if (is_file($assoc2['avatar'])) { echo "<img src='$avatar_name' alt='Avatar' /><br /><br />"; } else { echo "is not a regular file"; } // END The avatar column in the MySQL database says: image.jpg So there's a regular file. What I want to accomplish: I want the script to check if there's an avatar in the database, if NOT, then it should say: "no avatar uploaded yet." But as it is now it's telling me that there's no regular file even if there is, as I said the avatar column has an entry saying: image.jpg. Should I use if !empty instead? The strange thing is it used to work, now for some reason it suddenly doesn't. EDIT: With !empty it works, am I using the is_file function incorrectly? Hello guys, I devised the code block below, to retrieve all US zip codes that are located within a specified radius from the user's own zip code. So basically, the user selects a maximum distance option from a form element (not shown here)which is appended to the variable $distance. What the code below does is as follows: The longitude and latitude corresponding to the user's zip code are retrieved in the first query. Then in the second query, the longitudes and latitudes corresponding to every zip code in the database are retrieved. In the ensuing while loop, a distance calculation is made between the user's zip and every other zip using the longitudes and latitudes and if that distance falls within the selected $distance, that particular zip code is listed in a defined array called $range. Now everything works fine up to this point as tested. The problem is with the very last line. I try to implode the $range array into a string with the same name, separating the array elements with commas (,). Then when I print out the resulting string, I get the list of desired zip codes but not separated by commas. For example: 9001190015900179003490037900439004790048900569006 19006290301 9030190301 90302 Well when I use a foreach loop as follows: foreach ($range as $r) {echo $r.",";} the $range array behaves like any normal array yielding: 90011,90015,90017,90034,90037,90043,90047,90048,90056,90061,90062,90301 ,90301,90301 ,90302, So why in the world is the implode function not working? Here is my code. //Retrieve the zip codes within range. // Connect to the database. require('config.php'); //Retrieve longitude and latitude of logged in member. $query = "SELECT* FROM members INNER JOIN zip_codes ON members.zip = zip_codes.zip WHERE members.member_id = '{$_SESSION['id']}'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $my_lon = $row['lon']; $my_lat = $row['lat']; //Query all longitudes and latitudes in database. $query2 = "SELECT* FROM zip_codes INNER JOIN members ON members.zip = zip_codes.zip "; $result2 = mysql_query($query2); while ($row2 = mysql_fetch_assoc($result2)) { //Define array to hold zips found within range. $range = array(); if((rad2deg(acos(sin(deg2rad($my_lat))*sin(deg2rad($row2['lat'])) +cos (deg2rad($my_lat)) * cos (deg2rad($row2['lat'])) * cos(deg2rad($my_lon - $row2['lon'])) ) ) )*69.09 <= $distance ) { $range[] = $row2['zip']; } //Implode the range arrary. $range = implode(',' , $range); echo $range; }//End of while loop. Hello im receiving the error code, Quote Parse error: syntax error, unexpected ';'on line 58 Code: [Select] <?php mysql_connect("","business",""); mysql_select_db("business") or die("Unable to select database"); $result = mysql_query("SELECT subtype FROM business WHERE type ='restaurant' ORDER BY name"); $number_of_results = mysql_num_rows($result); $results_counter = 0; if ($number_of_results != 0) {while ($array = mysql_fetch_array($result);) //THIS IS LINE 58 IN MY CODE $results_counter++; if ($results_counter >= $number_of_results); ?> Firstly do you know why I would get this error? and secondly how do i call my results. I basically want to return my results and then later on format them into lists. I would also like each result to have a different variable name. eg. result1 = $result1 result 2 = $result2 result3 = $result3 etc. any guidance much appreciated. Im a bit lost. Here is my function which almost works as expected: <?php function find_value($array,$value) { for($i=1;$i<sizeof($array);$i++) { if($array[$i] == $value) { echo "$i . $array[$i]<br />"; return; } } } ?> And I call the function like so: <?php $names = array('Jason','Mike','Joe'); $name = 'Joe'; find_value($names,$name); ?> And the output is: 2 . Joe According to my understanding of Arrays, Joe would be index 3 BECAUSE my counter starts at 1 in my for loop??? Why is the result like this? What am I not understanding here? I'm working on this database that was built by somebody else, and I'm having issues with. I'm attaching a photo of the database. The problem I'm having is that even when I hard-code variables in the statement, it still brings back "Sorry, but we can not find an entry to match your query" Is there something that I'm not seeing, or something that I'm doing wrong here? You can clearly see in the photo that I'm trying to grab the info with the id_pk 300000. Code: [Select] <?php //$search = $_POST['search']; //$search = '300000'; $data = mysql_query("SELECT * FROM page_listings WHERE id_pk = '300000'"); while($result = mysql_fetch_array( $data )) { $name = $result['page_name']; $id = $result['id_pk']; $page = $result['html']; $cat = $result['category']; $dir = $result['directory']; echo "ID: " .$id ."<br>Page: ". $name ."<br>HTML: ". $page ."<br>Category: ". $cat ."<br>Directory: ". $dir ."<br />"; } $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "Sorry, but we can not find an entry to match your query<br><br>"; } ?> Thanks in advance [attachment deleted by admin] Hi I have a query where it returns a few fields based on the location. I created a class for the function and an index page. It does not return any values. Can someone please advise/ THE CLASS Code: [Select] <?php /**************************************** * * WIP Progress Class * * ****************************************/ class CHWIPProgress { var $conn; // Constructor, connect to the database public function __construct() { require_once "/var/www/reporting/settings.php"; define("DAY", 86400); if(!$this->conn = mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD)) die(mysql_error()); if(!mysql_select_db(DB_DATABASE_NAME, $this->conn)) die(mysql_error()); } public function ListWIPOnLocation($location) { $sql = "SELECT `ProgressPoint.PPDescription` AS Description ,`Bundle.WorksOrder` AS WorksOrder, `Bundle.BundleNumber` AS Number, `Bundle.BundleReference` AS Reference,`TWOrder.DueDate` AS Duedate FROM `TWOrder`,`Bundle`,`ProgressPoint` WHERE `Bundle.CurrentProgressPoint`=`ProgressPoint.PPNumber` AND `TWOrder.Colour=Bundle.Colour` AND `TWOrder.Size=Bundle.Size` AND `TWOrder.WorksOrderNumber`=`Bundle.WorksOrder` AND `ProgressPoint.PPDescription` LIKE '" . $location . "%' ORDER BY TWOrder.DueDate DESC"; mysql_select_db(DB_DATABASE_NAME, $this->conn); $result = mysql_query($sql, $this->conn); echo $sql; while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $return[] = $row; } return $return; } } ?> The index page Code: [Select] <?php // First of all initialise the user and check for permissions require_once "/var/www/users/user.php"; $user = new CHUser(7); // Initialise the template require_once "/var/www/template/template.php"; $template = new CHTemplate(); // And create a cid object require_once "/var/www/WIPProgress/DisplayWIPOnLocation.php"; $WIPProgress= new CHWIPProgress(); $content = "Check WIP Status on Location <br>"; $content = "<form action='index.php' method='get' name ='location'> <select id='location' > <option>Skin Room</option> <option>Clicking</option> <option>Kettering</option> <option>Closing</option> <option>Rushden</option> <option>Assembly</option> <option>Lasting</option> <option>Making</option> <option>Finishing</option> <option>Shoe Room</option> </select> <input type='submit' /> </form>"; $wip = $WIPProgress->ListWIPOnLocation($_GET['location']); // Now show the details $content .= "<h2>Detail</h2> <table> <tr> <th>PPDescription</th> <th>Works Order</th> <th>Bundle Number</th> <th>Bundle Reference</th> <th>Due Date</th> </tr>"; foreach($wip as $x) { $content .= "<tr> <td>" . $x['Description'] . "</td> <td>" . $x['WorksOrder'] . "</td> <td>" . $x['Number'] . "</td> <td>" . $x['Reference'] . "</td> <td>" . $x['DueDate'] . "</td> </tr>"; } $template->SetTag("content", $content); echo $template->Display(); ?> thank you I've done pretty much everything I can come up with. The method itself works fine, if I print_r(); just before returning it, it successfully returns the array. But once returned, it's empty. Heres my code: Code: [Select] <?php include_once $_SERVER['DOCUMENT_ROOT'] . "/includes/class_database.php"; include_once $_SERVER['DOCUMENT_ROOT'] . "/includes/values.php"; ?> <?php class User { private $database; public function __construct(MySqlDatabase $database) { //Type Hinting $this->database = $database; } public function hash_password($password) { $result = hash(sha512, $password . SUOLA); return $result; } public function find_all() { $result = $this->database->db_query("SELECT * FROM users"); $final = mysqli_fetch_array($result); return $final; } public function find_by_id($id=1) { $result = $this->database->db_query("SELECT * FROM users WHERE id={$id}"); $final = mysqli_fetch_array($result); return $final; } public function check_required($array) { // this method gets called first if (empty($array['username']) || empty($array['first_name']) || empty($array['last_name']) || empty($array['password']) || empty($array['email']) || empty($array['secret_question']) || empty($array['password2']) || empty($array['secret_answer']) || !($array['email'] === $array['email2']) || !($array['password'] === $array['password2'])) { die("Fill required fields!" . "<br />" . "<a href='javascript:history.go(-1)'>Go back</a>"); } else { $this->database->array_query_prep($array); // it then continues to the next method automatically } } public function create_user($array) { $date = date('d-m-Y H:i:s'); $sql = "INSERT INTO users (username, first_name, "; $sql .= "last_name, password, email, secret_question, "; $sql .= "secret_answer, create_time) VALUES "; $sql .= "('{$array['username']}', '{$array['first_name']}', '{$array['last_name']}', "; $sql .= "'{$array['password']}', '{$array['email']}', '{$array['secret_question']}', '{$array['secret_answer']}', "; $sql .= "'{$date}');"; $this->database->db_query($sql); } } ?> Code: [Select] <?php include_once $_SERVER['DOCUMENT_ROOT'] . "/includes/values.php"; include_once $_SERVER['DOCUMENT_ROOT'] . "/includes/class_user.php"; ?> <?php class MySqlDatabase extends MySQLi { function __construct() { //Check if constants are missing if (!defined("DB_USERNAME") || !defined("DB_SERVER") || !defined("DB_PASSWORD") || !defined("DB_NAME")) { die("One or more of the database constants are missing!"); } //Establish connection if constants are present using the parent class parent::__construct(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME); //Echo error message if connection has failed if ($this->connect_errno) { die("Database connection has failed: " . $this->connect_errno); } } public function db_query($sql) { $result = $this->query($sql); if (!$result) { die("Database query failed: " . $this->errno); } } public function array_query_prep($array) { // continues to this method $result = array_map(array($this, 'real_escape_string'), $array); if (!$result) { die("Preparing query failed: " . $this->errno); } // if i print_r here, it returns the array as it should return $result; } } ?> Code: [Select] <!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> <link rel="stylesheet" type="text/css" href="../stylesheets/main.css"/> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body class="main_body"> <div id="container"> <div id="header"> <div id="top"> <div id="login"> <form action="" method="post" target="/login/"> <label for="username">Username:</label><br /> <input name="username" type="text" class="text" maxlength="20" /><br /> <label for="password">Password:</label><br /> <input name="password" type="password" class="text" maxlength="30" /><br /> <input name="submit" type="submit" class="loginbtn" value="Login" /></form> </div> </div> <div> <h1>Welcome to _________ website!</h1> </div> <?php include_once $_SERVER['DOCUMENT_ROOT'] . "/includes/values.php"; include_once $_SERVER['DOCUMENT_ROOT'] . "/includes/functions.php"; include_once $_SERVER['DOCUMENT_ROOT'] . "/includes/class_database.php"; include_once $_SERVER['DOCUMENT_ROOT'] . "/includes/class_user.php"; ?> <?php $database = new MySqlDatabase(); $user = new User($database); if (isset($_POST['submit'])) { $result = $user->check_required($_POST); //this is where I get nothing back $user->create_user($result); die("Registration was successful!"); } else { $username = ""; $first_name = ""; $last_name = ""; $password = ""; $email = ""; $email2 = ""; $secret_question = ""; $secret_answer = ""; unset($_POST); } ?> <form action="" method="post" target="_self"> Username: <input type="text" name="username" class="text" maxlength="20" value="<?php echo htmlentities($username); ?>" /><br /> First Name: <input type="text" name="first_name" class="text" maxlength="20" value="<?php echo htmlentities($first_name); ?>" /><br /> Last Name: <input type="text" name="last_name" class="text" maxlength="20" value="<?php echo htmlentities($last_name); ?>" /><br /> Password: <input type="password" name="password" class="text" maxlength="30" value="<?php echo htmlentities($password); ?>" /><br /> Enter again: Password: <input type="password" name="password2" class="text" maxlength="30" value="<?php echo htmlentities($password2); ?>" /><br /> Email: <input type="text" name="email" class="text" maxlength="30" value="<?php echo htmlentities($email); ?>" /><br /> Enter again: Email: <input type="text" name="email2" class="text" maxlength="30" value="<?php echo htmlentities($email2); ?>" /><br /> Secret Question: <input type="text" name="secret_question" class="text" maxlength="35" value="<?php echo htmlentities($secret_question); ?>" /><br /> Secret Answer: <input type="text" name="secret_answer" class="text" maxlength="35" value="<?php echo htmlentities($secret_answer); ?>" /><br /> <input type="submit" name="submit" class="submitbtn" value="Submit" /> <?php ?> </div> </div> </body> </html> [/quote] Any ideas? Hello, My current server setup :
PHP version: 7.1.4
From what I read, in order to have MySQL return native datatypes (as opposed to just strings) : Now, I do have mysqlnd, but a simple PDO Prepared statement still returns me all strings, even though some columns are set as INT, VARCHAR, DATETIME, etc.. $stmt = $pdo->prepare("SELECT * FROM tbl_users WHERE id=1"); $stmt->execute(); $user = $stmt->fetch(); var_dump($user); OUTPUT: array(13) { ["id"]=> string(1) "1" ["is_admin"]=> string(1) "1" ["is_active"]=> string(1) "1" ["username"]=> string(5) "jdoe" ... }
I'm not sure what to look for to resolve this issue if I want it to return INT as INT and not STRING, etc. Does having `extension_loaded('mysqlnd') == true`, make my system automatically use this native mysql driver? How can I tell ? Could this be a version problem perhaps?
Much thanks! Pat
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. I am looking to accomplish the following but have been hitting a brick wall: * User enters a single keyword into a text field, and conducts a search keyword search. * The results are pulled from the campusbooks.com API(API docs attached) * result are then output in <div> class and includes all the book details and its corresponding url./img etc I'm trying to simplify this process but I continue to receive syntax errors. A step by step practical explanation would do me justice! I am using Dreamweaver CS4 to build a website. On my contact page, I made a form with spry validation. I used a tutvid tutorial to learn a simple form handler script (I'm a complete newb at PHP) and everything works great. The only problem I'm having is, in my Dreamweaver template, I have an editable region that has the form. When the user clicks to submit the form, a new html page opens up that looks nothing like my website. What I'm trying to accomplish is having the form disappear and be replaced in the same editable region with my "thank you" message. This way, the user just submits, the form disappears, and they get a thank you message on the same page, in the same place where the form was. Here is the form code: Code: [Select] <form id="frmContact" name="frmContact" method="post" action="contact_form.php"> <fieldset><legend>Submit a question or comment...</legend> <p> <label for="name">Name:</label> <span id="spryName"> <input type="text" name="name" id="name" /> <span class="textfieldRequiredMsg">Name is required.</span><span class="textfieldMinCharsMsg">Must have at least 3 characters.</span><span class="textfieldMaxCharsMsg">Must not exceed 20 characters.</span></span></p> <p> <label for="email">Email:</label> <span id="spryPassword"> <input type="text" name="email" id="email" tabindex="10" /> <span class="textfieldRequiredMsg">Email address is required.</span><span class="textfieldInvalidFormatMsg">Not a valid email address.</span><span class="textfieldMinCharsMsg">Not a valid email address.</span><span class="textfieldMaxCharsMsg">Not a valid email address.</span></span></p> <p> <label id="message" for="question">Please tell us how we can help you:</label><br /> <span id="spryText"> <textarea name="question" id="question" cols="45" rows="5" tabindex="20"></textarea><br /> <span class="textareaRequiredMsg">A question or comment is required.</span><span class="textareaMinCharsMsg">Must have 16 characters minimum</span><span class="textareaMaxCharsMsg">Must not exceed 500 characters.</span></span></p> <p> <input type="submit" name="submit" id="submit" value="Submit" tabindex="30" /> </p> </fieldset> </form> Here is the PHP script: <?php /* Subject and Email variables */ $emailSubject = 'Contact Form Response'; $webMaster = 'centerline.computers@gmail.com'; /* Gather Data variables */ $nameField = $_POST['name']; $emailField = $_POST['email']; $questionField = $_POST['question']; $body = <<<EOD <br><hr><br> Name: $nameField <br> Email: $emailField <br> Message: $questionField <br> EOD; $headers = "From: $emailField\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); /* Results rendered as HTML */ $theResults = <<<EOD <html><body> <h2>Thank you for submitting.</h2> <p>We will get back to you as soon as possible.</p> </body> </html> EOD; echo "$theResults"; ?> Thanks for any help you might have for me! Hi Everyone, Well I have a bit of a problem... I have created a search page that I would like to return results from my MySQL database. However for some reason I can not get my page to display the results. Instead I am getting an error page. Below is the code I am using: In addition to this, should I wish for a user to be able to edit the returned results by clicking a link, how would I do that? <?php session_start(); ?> <link rel="stylesheet" type="text/css" href="css/layout.css"/> <html> <?php $record = $_POST['record']; echo "<p>Search results for: $record<br><BR>"; $host = "localhost"; $login_name = "root"; $password = "P@ssword"; //Connecting to MYSQL MySQL_connect("$host","$login_name","$password"); //Select the database we want to use mysql_select_db("schedules_2010") or die("Could not find database"); $result = mysql_query("SELECT * FROM schedule_september_2010 WHERE champ LIKE '%$record%' ") or die(mysql_error()); // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row echo "<br><p>Your Schedule<BR></p><br>"; echo "<table border=1>\n"; echo "<tr> <td bgcolor=#444444 align=center><p><b>Champ</p></td> <td bgcolor=#444444 align=center><p><b>Date</p></td> <td bgcolor=#444444 align=center><p><b>Start Time</p></td> <td bgcolor=#444444 align=center><p><b>End Time</p></td> <td bgcolor=#444444 align=center><p><b>Department</p></td> <td bgcolor=#444444 align=center><p><b>First Break</p></td> <td bgcolor=#444444 align=center><p><b>Second Break</p></td> <td bgcolor=#444444 align=center><p><b>Login ID</p></td> </tr>\n"; do { printf("<tr> <td><p>%s</p></td> <td><p>%s</p></td> <td><p>%s</p></td> <td><p>%s</p></td> <td><p>%s</p></td> <td><p>%s</p></td> <td><p>%s</p></td> <td><p>%s</p></td> </tr>\n" , $row["champ"] , $row["date_time"] , $row["start_time"] , $row["end_time"] , $row["department"] , $row["first_break"] , $row["second_break"] , $row["login_id"] ); } while ($row = mysql_fetch_array($result)); echo "</table>\n"; } else { echo "$champ No Records Found"; } mysql_free_result($result); mysql_close($con); ?> </html> 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 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 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 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. 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. 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. |