PHP - Built In Functions.
I wonder if is out there function in php that is doin this .
function like strpos that is does not notice from CAPITAL words to small words. function like strpos that does finds all matchs and not only 1. function like strpos that is search inside connected words like "strposfunction" so if i search "function" it will find it. thanks , Mor. Similar TutorialsHi everyone. Good day for coding? I created this tiny script just for self-learning purposes but I'd like to improve it. Here is the script: Code: [Select] <?php include_once 'dbinfo.php'; if(isset($_POST['submit'])) { $label = $_POST['label']; $stm = $connect->prepare("INSERT INTO words(word) VALUES (?)");//$stm = $connect->prepare("INSERT INTO words VALUES (?,?)"); $stm->bind_param('s', $label);//$stm->bind_param('ss', $label, $user);http://php.net/manual/en/mysqli-stmt.bind-param.php $stm->execute(); printf("%d Label inserted.\n", $stmt->affected_rows); $stm->close(); $connect->close(); } ?> <form action="" name="submit_label" method="POST"> <p>Submit a Label:<input type="text" name="label" value=""></p> <input name="submit" type="submit" value="Submit label"> <p></p> <a href="wordlist.php" >The List of labels</a> </form> <?php if ($stm = $connect->prepare("SELECT word, label_id FROM words ORDER BY label_id")){ $stm->execute(); $stm->bind_result($labelcol, $labelcol2); while($stm->fetch()){ printf("%s %s</br>", $labelcol, $labelcol2); } $stm->close(); } $connect->close(); ?>It submits words and insert them in a table called words. It also outputs the table content, the submitted words. An image of a database structure is attached to this post. What I'd like to do is to count the how many times the same words are repeatedly submitted and output the the repeated word next to the number of times it is repeated. For example: user 1 submitted 'awesome' 3 times so it shows awesome (3) user2 submitted 'bad' 45 times so it shows bad (45).... and so on I'm guessing that I should use arrays and and built in functions and things like that but my question which functions should I use to get started or just give me some hint how to use arrays in this case. Thank you very much in advance. [attachment deleted by admin] Hi I'm new. These are some of the example strings I'm dealing with "update online SJ" "Change account GBBCDL" "CRM L" I was wondering if there is a built-in function or function(s) that could help me strip all the CAPS from the right of each string til it finds the first space. I'm not worried about those and would look much nicer to just display everything without that. Thanks from Jennifer But I need some help. I built part of this script off a tut, and did the rest myself however, I want it so it send the information into a database. What I want is, once a user uploads an image, it can also be deleted by that user with the code given. I have made the html, bbcode & direct link. I want an option for a box where it shows Delete link.... maniaupload.net here's my FULL php upload script. Quote <?php define ("MAX_SIZE","100000"); function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } $errors=0; if(isset($_POST['Submit'])) { $image=stripslashes($_FILES['image']['name']); if ($image) { $filename = stripslashes($_FILES['image']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "mov") && ($extension !="PNG") && ($extension !="bmp") && ($extension != "png") && ($extension != "gif")) { echo '<font color="red"><b>Extension not allowed</b></font><br>'; $errors=1; } else { $size=filesize($_FILES['image']['tmp_name']); if ($size > MAX_SIZE*100000) { echo 'You have exceeded the size limit!'; $errors=1; } $image_name=time().'.'.$extension; $newname="images/".$image_name; $fullname="http://www.maniaupload.net/".$newname; $copied = copy($_FILES['image']['tmp_name'], $newname); if (!$copied) { echo '<font color=\"red\"><b>Upload Unsuccessful! Try Again?</b></font>'; $errors=1; }}}} if(isset($_POST['Submit']) && !$errors) { echo "File Uploaded Successfully! <br /><br /> <img src=\"$newname\" /> <br /><br /> <b>Direct Image Link:</b><br/><table width=\"338\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" id=\"Table1\"> <tr> <td align=\"center\" valign=\"middle\"><textarea readonly name=\"message\" rows=\"1\" cols=\"50\">$fullname</textarea></td> </tr> </table></center><br> <b>HTML Code:</b><br/><table width=\"338\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" id=\"Table1\"> <tr> <td align=\"center\" valign=\"middle\"><textarea readonly name=\"message\" rows=\"1\" cols=\"50\"> <a href=\"$fullname\" target=\"_blank\"><img border=\"0\" src=\"$fullname\"></a> </textarea></td> </tr> </table><br> <b>BBCode <font color=\"red\">*NEW*</font></b><br> <table width=\"338\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" id=\"Table1\"> <tr> <td align=\"center\" valign=\"middle\"> <textarea readonly name=\"message\" rows=\"1\" cols=\"50\"> </textarea></td> </tr> </table><br> "; } ?> I made the appropriate databases in the myadmin area, i just need a starting point to where it injects the image that was uploaded into the database. Basically the ID and all that crap. I have more code but its not needed, its outside of the php tags. But can anyone help please. It's just adding a delete link so users can delete it if they choose. I'm thinking it's MYSQL involved, but I'm still learning. Anyone know how I could do this? Thanks. Hello I am using joomla with sobi2. im working in the sobi2 details template. I am having some difficulties with the like button. maybe i'm going about it all wrong but ill show you what i got and hopefully you can lend me some advise. This works <?php echo '<p><iframe src="http://www.facebook.com/plugins/like.php?href='; ?> <?php echo 'www.google.com'; ?> <?php echo '&layout=standard&show_faces=false&width=450&action=like&colorscheme=light&height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:35px;" allowTransparency="true"></iframe></p>'; ?> output ---- (working like button) ---- this works <?php $testv='www.google.com' ?> <?php echo $testv ?> <?php echo '<p><iframe src="http://www.facebook.com/plugins/like.php?href='; ?> <?php echo $testv; ?> <?php echo '&layout=standard&show_faces=false&width=450&action=like&colorscheme=light&height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:35px;" allowTransparency="true"></iframe></p>'; ?> output ------ www.google.com (working like button) ------- This doesn't work <?php $testv=$fieldsFormatted['field_street']; ?> <?php echo $testv ?> <?php echo '<p><iframe src="http://www.facebook.com/plugins/like.php?href='; ?> <?php echo $testv; ?> <?php echo '&layout=standard&show_faces=false&width=450&action=like&colorscheme=light&height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:35px;" allowTransparency="true"></iframe></p>'; ?> output ------- www.google.com (not working like button) -------- facebook gives me an error "The page at http://<span%20%20id=/ could not be reached." is there a way of calling this function but just returning the classes you've loaded and not already built in classes with php please? Code: [Select] Array ( [0] => stdClass [1] => Exception [2] => ErrorException [3] => COMPersistHelper [4] => com_exception [5] => com_safearray_proxy [6] => variant [7] => com [8] => dotnet [9] => DateTime [10] => DateTimeZone [11] => ReflectionException [12] => Reflection [13] => ReflectionFunctionAbstract [14] => ReflectionFunction [15] => ReflectionParameter [16] => ReflectionMethod [17] => ReflectionClass [18] => ReflectionObject [19] => ReflectionProperty [20] => ReflectionExtension [21] => LibXMLError [22] => __PHP_Incomplete_Class [23] => php_user_filter [24] => Directory [25] => SimpleXMLElement [26] => DOMException [27] => DOMStringList [28] => DOMNameList [29] => DOMImplementationList [30] => DOMImplementationSource [31] => DOMImplementation [32] => DOMNode [33] => DOMNameSpaceNode [34] => DOMDocumentFragment [35] => DOMDocument [36] => DOMNodeList [37] => DOMNamedNodeMap [38] => DOMCharacterData [39] => DOMAttr [40] => DOMElement [41] => DOMText [42] => DOMComment [43] => DOMTypeinfo [44] => DOMUserDataHandler [45] => DOMDomError [46] => DOMErrorHandler [47] => DOMLocator [48] => DOMConfiguration [49] => DOMCdataSection [50] => DOMDocumentType [51] => DOMNotation [52] => DOMEntity [53] => DOMEntityReference [54] => DOMProcessingInstruction [55] => DOMStringExtend [56] => DOMXPath [57] => RecursiveIteratorIterator [58] => IteratorIterator [59] => FilterIterator [60] => RecursiveFilterIterator [61] => ParentIterator [62] => LimitIterator [63] => CachingIterator [64] => RecursiveCachingIterator [65] => NoRewindIterator [66] => AppendIterator [67] => InfiniteIterator [68] => RegexIterator [69] => RecursiveRegexIterator [70] => EmptyIterator [71] => ArrayObject [72] => ArrayIterator [73] => RecursiveArrayIterator [74] => SplFileInfo [75] => DirectoryIterator [76] => RecursiveDirectoryIterator [77] => SplFileObject [78] => SplTempFileObject [79] => SimpleXMLIterator [80] => LogicException [81] => BadFunctionCallException [82] => BadMethodCallException [83] => DomainException [84] => InvalidArgumentException [85] => LengthException [86] => OutOfRangeException [87] => RuntimeException [88] => OutOfBoundsException [89] => OverflowException [90] => RangeException [91] => UnderflowException [92] => UnexpectedValueException [93] => SplObjectStorage [94] => XMLReader [95] => XMLWriter [96] => Autoloader )[code] Hello all, I've run into a problem with what seems to be a basic script. I want to display two different tables of data, side by side. Each table is built with a while loop, pulling data from an MySQL query. When I try to wrap the first table in a div the result is a div that appears empty when there is really a table with 60 rows of data I expect it to wrap around. I can't get this to work, I've tried to insert the div tag in many places to no avail. Also, I wanted to add some blank space at the bottom of the page so that there was room between the end of the table and the actual bottom of the page. I tried adding some <br />'s at the end of the code but that didn't work. I guess I'm confused because the code is acting as if the 60 rows of table data isn't there. When I tried to add my page layout around the script (as includes at the top and bottom of the script) the layout acts as if the table isn't there, either. That is to say that my "header" and "footer" appear bunched up at the top of the page as if there wasn't content on the screen. Hopefully someone can help! Thanks. Code: [Select] <?php echo "<br /> <a href='index.php'> Back Home </a> <br /> <br />"; // -------------------------- Connect to DB include ('connect_script.php'); // ------------------------------ Color variable for alternating table colors $color = 1; // ------------------------- Query Parameters $select = "SELECT (number) AS id, (first_name) AS fn, (last_name) AS ln, (position) AS position FROM table WHERE position = 'X' "; $get = @mysqli_query ($dbc, $select); // ------------------------- Run Query if ($get) { // ------------------------Start table echo " <div style='border-style: solid;'> <table align='left' border='1'> <tr> <td>People</td> </tr> <tr> <td>ID</td><td>First Name</td><td>Last Name</td><td>Position</td> </tr>"; // ------------------------ Retrieve People while ($row = mysqli_fetch_array($get, MYSQLI_ASSOC)) if ($color==1) {echo ' <tr bgcolor= #47EA7D> <td>' . $row['id'] . '</td><td>' . $row['fn'] . '</td><td>' . $row['ln'] . '</td><td>' . $row['position'] . '</td> </tr>'; $color = '2';} else {echo ' <tr bgcolor= #A4C8B0> <td>' . $row['id'] . '</td><td>' . $row['fn'] . '</td><td>' . $row['ln'] . '</td><td>' . $row['position'] . '</td> </tr> '; $color= '1';} // ----------------------- Close table echo "</div> </table>"; mysqli_free_result ($get); } // -------------------- IF ERROR WITH QUERY else {echo "Didn't connect";} // ---------------------- Spaces --> This is the code that doesn't appear to affect the space at the bottom of the table echo "<br /> <br /> <br />"; ?> Can anyone please help me write out a php script exactly as described below? In the submission form, users are required to filled in two infos,.. Name and email address. As soon as the 'submit' button is been clicked, the php script should be able to grab the filled infos and stores it on the server in a txt file and at the same time, it should sends out confirmation email to the email address so filled in the submission form. Also, can anyone devise a method as how to retrieve the message body of the confirmation email from the previous php script and then pass it on again to the display of the next page as when the submission button is clicked? Thank you so much in advance. I have a script I am putting together that simulate a cricket game. The only issue is, that there are a huge number of functions because there doesn't seem to be any other way to do this properly. As well as this, there a while() loop and all this seems to be leading to the page reaching a max 30 second timeout when generating the result. My code is attached below, it is quite messy at the moment because i've just be working on it, but I was wondering if anyone has any solutions of how I can speed this up or change to prevent a timeout: <?php // Error reporting error_reporting(E_ALL); // Connect DB mysql_connect("wickettowicket.adminfuel.com", "rockinaway", "preetha6488") or die(mysql_error()); // Select DB mysql_select_db("wickettowicket") or die(mysql_error()); // MySQL queries to find batsmen and bowlers $array_batsmen = mysql_query('SELECT id, name, ability, strength FROM wtw_players WHERE team_id = 1 ORDER BY id ASC'); $array_bowlers = mysql_query('SELECT id, name, ability, strength FROM wtw_players WHERE team_id = 2'); // Start table for data $data = '<table width="600px">'; // Create blank scorecard while ($array_bat = mysql_fetch_array($array_batsmen)) { $data .= '<tr><td>'.$array_bat['name'].'</td><td></td><td></td><td>0</td></tr>'; } // Set up arrays for players $current_batsman = $current_bowler = array(); // Reset query mysql_data_seek($array_batsmen,0); $in_one = $in_two = $it = ''; function currentBatsman($id, $name, $ability, $strength, $out, $in, $runs) { global $current_batsman; $current_batsman = array ( 'id' => $id, 'name' => $name, 'ability' => $ability, 'strength' => $strength, 'out' => $out, 'in' => $in, 'runs' => $runs ); echo 'set current'; } // Set up arrays of batsmen while ($array = mysql_fetch_array($array_batsmen)) { if ($it < 3 && $in_one == '') { currentBatsman($array['id'], $array['name'], $array['ability'], $array['strength'], 0, 1, 0); $batsmen[$array['id']] = array ( 'id' => $array['id'], 'name' => $array['name'], 'ability' => $array['ability'], 'strength' => $array['strength'], 'out' => 0, 'in' => 1, 'runs' => 0 ); $in_one = $array['id']; $current = $array['id']; $it++; } else if ($it < 3 && $in_two == '') { $batsmen[$array['id']] = array ( 'id' => $array['id'], 'name' => $array['name'], 'ability' => $array['ability'], 'strength' => $array['strength'], 'out' => 0, 'in' => 1, 'runs' => 0 ); $in_two = $array['id']; $it++; } else { $batsmen[$array['id']] = array ( 'id' => $array['id'], 'name' => $array['name'], 'ability' => $array['ability'], 'strength' => $array['strength'], 'out' => 0, 'in' => 0, 'runs' => 0 ); } } // Bowler Array while ($array = mysql_fetch_array($array_bowlers)) { $bowlers[] = array ( 'name' => $array['name'], 'ability' => $array['ability'], 'strength' => $array['strength'] ); } // Reset both queries mysql_data_seek($array_bowlers,0); mysql_data_seek($array_batsmen,0); function changeBatsman($just_out) { global $array_batsmen, $batsmen; //Update array $batsmen[$just_out] = array ( 'in' => 1, 'out' => 1 ); while ($array = mysql_fetch_array($array_batsmen)) { if ($just_out != $array['id'] && $batsmen[$array['id']]['out'] != 0) currentBatsman($array['id'], $array['name'], $array['ability'], $array['strength'], 0, 1, 0); } // Reset query mysql_data_seek($array_batsmen,0); echo 'change batsman'; } function swapBatsman($other_batsman) { global $array_batsmen, $batsman; while ($array = mysql_fetch_array($array_batsmen)) { if ($other_batsman != $array['id'] && $batsman[$array['id']]['out'] != 0 && $batsman[$array['id']]['in'] == 1) currentBatsman($array['id'], $array['name'], $array['ability'], $array['strength'], 0, 1, 0); } // Reset query mysql_data_seek($array_batsmen,0); echo 'swap batsman'; } $runs = $outs = $balls = $overs = 0; $played = array(); function selectBowler() { global $bowlers, $current_bowler; // Select random bowler $choose_bowler = array_rand($bowlers, 1); $current_bowler = array ( 'name' => $bowlers[$choose_bowler]['name'], 'ability' => $bowlers[$choose_bowler]['ability'], 'strength' => $bowlers[$choose_bowler]['strength'] ); } /* function selectBatsman(); { global $array_batsmen; while ($array_batsmen[]['out'] != 1) { }*/ function bowl() { global $batsmen, $bowlers, $current_bowler, $current_batsman, $data, $balls, $outs, $runs; if ($current_batsman['out'] == 0) { echo 'bowling'; // Set the initial number $number = rand(0, 190); // Ability of batsman if ($current_batsman['ability'] > 90) $number += 30; else if ($current_batsman['ability'] > 70) $number += 15; else if ($current_batsman['ability'] > 50) $number += 2; else $number = $number; // Strength of batsman if ($current_batsman['strength'] > 90) $number += 15; else if ($current_batsman['strength'] > 70) $number += 10; else if ($current_batsman['strength'] > 50) $number += 5; else $number = $number; // Depending on overs if ($balls > 270) $number += 30; else if ($balls > 120) $number -= 10; // Ability if ($current_bowler['ability'] > 90) $number -= 30; else if ($current_bowler['ability'] > 70) $number -= 15; else if ($current_bowler['ability'] > 50) $number -= 2; else $number = $number; // If batsman has made a huge total of runs, we need to knock some numbers off - more likely to get out if ($current_batsman['runs'] > 200) $number -= 70; else if ($current_batsman['runs'] > 100) $number -= 30; // Finally sort out runs if ($number > 190) $run = 6; else if ($number > 170) $run = 4; else if ($number > 160) $run = 3; else if ($number > 100) $run = 2; else if ($number > 50) $run = 1; else if ($number > 10) $run = 0; else if ($balls > 120 && $number > 0) $run = 0; else $run = -1; // Increase number of balls $balls += 1; // Are they out? if ($run == -1) { $current_batsman['out'] = 1; $played[] = $current_batsman['id']; $find = '<tr><td>'.$current_batsman['name'].'</td><td></td><td></td><td>0</td></tr>'; $replace = '<tr><td>'.$current_batsman['name'].'</td><td></td><td>'.$current_bowler['name'].'</td><td>'.$current_batsman['runs'].'</td></tr>'; $data = str_replace($find, $replace, $data); changeBatsman($current_batsman['id']); echo 'out'; } else { $current_batsman['runs'] += $run; $runs += $run; if ($run == 1 || $run == 3) { swapBatsman($current_batsman['id']); echo 'time to swap'; } echo $run; } // Count outs if ($current_batsman['out'] == 1) $outs += 1; } } function game() { global $main, $batsmen, $bowlers, $data, $batted, $balls, $outs, $current_batsman; // Check if possible while ($balls <= 295 && $outs < 10) { selectBowler(); // Actually bowl now bowl(); } } game(); echo $data; This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=323879.0 I teaching myself php, but I am coming from java and other compiled languages, so the process has been a little bumpy. I am trying to do something like this: Code: [Select] class my_class { function one () { $two = two (); $three = three (); $five = $two + $three; return $five; } function two () { $two = 2; return $two; } function three () { $three = 3; return $three; } } Unfortunately, I keep getting an error message saying that my call to two () is an undefined function. I am gathering from this that the scope of one () is not aware of the existence of two (). Is there a way to get around this so I can call two () and three () from one ()? Hi, I could use a little guidance here. 1) is a function with values to be sent to 2). 1) <!-- use ajax - OnCalc function to send data to your database. --> function OnCalc(value1,op,value2,total) { 2) php file using above function values <?php header( "refresh:5;url='http://localhost/hom...lcprint.php'"); echo 'You\'ll be redirected in about 5 secs. If not, click <a href="http://localhost/hom...hp">here</a>.'; echo '<script type="text/javascript">' , 'OnCalc();' , '</script>'; No error but code not working? As painfully simple as this may be, I seem to be doing something wrong as always. New to php and decided to start using functions. I'm trying to add functions from an external functions.php file to my other pages and then call the functions where necessary. How should I go about it? I tried something like this: Functions.php: Code: [Select] <?php function field() { echo 'text heherh'; } ?> and then when calling it to when needed for example: include 'includes/functions.php'; // at the top of the page Code: [Select] <?php // and when trying to call the function on a specific line if (!$sname) $errorstring = $errorstring . "<b>Surname:" . field() ; //field being the function name ?> I know this is very simple but I have never used functions before.. tried google, didn't help much and I'm pressed for time so decided to ask here. Thanks in advance When in OOP I have been watching tutorials and some have functions just written like Code: [Select] class user { public $user; public function __construct($u) { $this->user = $u; } } do I need to type public before the function or is it better practice to just put Code: [Select] class user { public $user; function __construct($u) { $this->user = $u; } } Thanks! Hi. I am trying to write a function but they are new to me and confusing me. On multiple pages I am requesting users details. I thought instead of writing out the query every time I want to do this I would include a functions page with the query in it. The only variable I carry from the user is the user name as a session when they log in. The user name is the email address of the person signed in. so here is my first function. As im sure you can see it doesn't work but I don't understand why or how to call it properly. Can someone please explain.... function GetUser($user = "") { $qFindUser = "SELECT * FROM members WHERE email = '$user'"; $rFindUser = mysql_query($qFindUser) or die (mysql_error()); $UserInfo = mysql_fetch_array($rFindUser); } calling the function to return all details of a member as an array. <?php $Name = $_SESSION['MM_Username']; $UserInfo = GetUser($Name); echo $UserInfo['forename']; ?> i am wondering what the '@' is used for when used in front of a function like Function(@$VAR); What is the benefit of the @? Hi, I've got 3 different upload forms in one form. I'm making a function so it just one piece of code. I'm having a bit of a problem changing some of the code so it works for all 3. Here is the function function loadImages ($action, $position) { $link = mysql_connect("","",""); if (!$link) { die('Error: could not connect: ' . mysql_error()); } $db_select = mysql_select_db("",$link); if (!$db_select) { die ("Error: database selection failed: " . mysql_error()); } $page = ($_POST["pageName"]); if ((($_FILES["bfile"]["type"] == "image/gif") || ($_FILES["bfile"]["type"] == "image/jpeg") || ($_FILES["bfile"]["type"] == "image/pjpeg")) && ($_FILES["bfile"]["size"] < 9000000)) { if ($_FILES["bfile"]["error"] > 0) { echo "Return Code: " . $_FILES["bfile"]["error"] . "<br />"; } else { $success = '<p style="font-weight: bold; color: #C00">Upload successful<br />'; // move uploaded temporary file to final destination move_uploaded_file($_FILES["bfile"]["tmp_name"], "uploads/" . $_FILES["bfile"]["name"]); // update database with new filename $filename = $_FILES["bfile"]["name"]; $sql = "UPDATE images SET filename= '$filename' where page = '$page' and position = '$position'"; if (!mysql_query($sql,$link)) { die('Error: ' . mysql_error()); } } } else { $fail = '<p style="font-weight: bold; color: #C00">Invalid file'; } mysql_close($link); } Now the $action is the bit that will determine whether it's updateTop updateMiddle or updateBottom. $position finds out if it's top middle or bottom if (isset($_POST['updateTop'])) { loadImages ($_POST['updateTop'], "top"); } Here is a sample of the html, it's in a switch case "Products": echo "<p>Image Top</p> <input type=\"file\" name=\"file\" id=\"file\" /> <input type=\"submit\" name=\"updateTop\" value=\"Update $page Top\" /> <p>Image Middle</p> <input type=\"file\" name=\"mfile\" id=\"mfile\" /> <input type=\"submit\" name=\"updateMiddle\" value=\"Update $page Middle\" /> <p>Image Bottom</p> <input type=\"file\" name=\"bfile\" id=\"bfile\" /> <input type=\"submit\" name=\"updateBottom\" value=\"Update $page Bottom\" /> "; break; What I need to do is get $_FILES["bfile" into a variable to see whether it's "bfile" "mfile" or "file" but not sure how to write it. Thanks for the help. OK, so if I've got this in my one of my class files: public function userr($user) { $thisquery = mysql_query("SELECT * FROM users WHERE username='". $user ."'"); if(mysql_num_rows($thisquery) == 1) { return true; } return false; } Could I use something like this: if($class->userr($user)) { // Something } If not, how would I go about doing something like it? And is there any way I could use a mysql_fetch_assoc in a function? Can someone tell me by looking at the following code why function pcust() does not work, I am new to programming? Code: [Select] $firstname = "chris"; $surname = "reynolds"; $address1 = "12 birch end"; $town = "Wallington"; $county = "surrey"; $postcode = "wh20 3bg"; $telephone = "01372 854785"; $cust_details = fix_cust($firstname, $surname, $address1,$town, $county, $postcode, $telephone ); function fix_cust($n1, $n2, $n3, $n4, $n5, $n6, $n7) { $n1 = ucfirst(strtolower($n1)); $n2 = ucfirst(strtolower($n2)); $n3 = ucwords(strtolower($n3)); $n4 = ucfirst(strtolower($n4)); $n5 = ucfirst(strtolower($n5)); $n6 = ucfirst(strtoupper($n6)); $n7 = ucfirst(strtolower($n7)); return array($n1, $n2, $n3, $n4, $n5, $n6, $n7); } echo $cust_details[0] . " " . $cust_details[1]; echo "<br />"; echo $cust_details[2]; echo "<br />"; echo $cust_details[3]; echo "<br />"; echo $cust_details[4]; echo "<br />"; echo $cust_details[5]; echo "<br />"; echo $cust_details[6]; echo "<br />"; function pcust(){ $length = count($cust_details ); for ($i = 0; $i < $length; $i++) { echo $cust_details[$i]; echo "<br />"; } } pcust(); I have a function to get some data from the database. However it always comes back with: Code: [Select] Notice: Undefined variable: db in C:\wamp\www\ASF A Simple Forum\functions\functions.php on line 233 Fatal error: Call to a member function query() on a non-object in C:\wamp\www\ASF A Simple Forum\functions\functions.php on line 233 here is the code: require_once(ASF_ROOT."includes/init.php"); // this is where the db connection is function get_db_info($type, $select, $table, $where="", $order="DESC", $limit="") { if (empty($type) || empty($select) || empty($table)) { try { throw new emptyArgs(); } catch (emptyArgs $invalid) { echo "<div style=\"border:1px solid #f00; padding:5px; width:350px; line-height:10px;\">"; echo "<b>$invalid</b>"; echo "<p>get_info() needs atleast 3 arguments (Type, Select and Table) - none supplied</p>"; echo "</div>"; } } else { if ($type == "num") { $query = $db->query(" SELECT $select FROM ".TBL_PREFIX."$table $where $order $limit ") or die($db->error()); $result = $db->num_rows(MYSQLI_NUM); return $result; } else { $query = $db->query(" SELECT $select FROM ".TBL_PREFIX."$table $where $order $limit "); $result = $query->fetch_array(MYSQL_ASSOC); return $result; } } } I have a function for mysqli_real_escape_string above this function and it works with no errors. Have i done something wrong? as you can see i am including the file which holds the connection but it doesnt seem to use it. every other file that uses the connection works fine. Hey guys. Can anyone tell me what this means? function foo { } It is basic php but I don't get it. Should it be called for execution, or does it work automatically, or both? The php manual at w3schools and php.net are too tough for me. That's why I posted here. Thanks! |