PHP - Simple Question On Functions?
Hi i have a function strored in a seperate file (included in my main php page for use), my question is a simple one but i cannot seem to find the answer on the web to this:
I call the function as follows passing the variable $name <?php myfunction($name) ?> The function does somehting simple such as: <?php function myfunction ($name) { if ($name = 'bob') { return true; } else return false; } ?> How do i then obtain the true or false value of the function from back with my main php page? Similar TutorialsHi Guys Simple question. Can anyone tell me why this doesn't work please? Code: [Select] $test = "<HEELOOOO"; $test2 = filter_var("$test", FILTER_SANITIZE_STRING); echo $test2; When I run this get I get nothing echoed back, not even in the source. So can the filter function not be used like this? I thought it would encode the special character and return it but I must be missing something simple here! Thanks, Drongo Hello, i am trying to create a simple funtion that i can all upon to "turn off a website" i am calling the function by <?php siteonline(n); ?> and the function is function siteonline($msg){ $offlinecheck = mysql_query("SELECT * FROM acp") or die(mysql_error()); $siteoffline = mysql_fetch_array($offlinecheck); $ifsiteoffline = $siteoffline['site_offline']; $offline = $siteoffline['offline_msg']; if ($ifsiteoffline == "y") { echo("$offline"); die();} } now this will turn off the site but it shows no message what so ever and i can not figure out why can anyone help? Cheers, Hello all, I finally started learning php and with the little knowledge I have from CPP it's far simpler than it seemed years ago. I need a little bit of help with this function I followed in a tutorial and it's just not working. <?php function writeName($fname) { echo $fname . " Refsnes.<br />"; } echo "My name is "; writeName("Kai Jim"); echo "My sister's name is "; writeName("Hege"); echo "My brother's name is "; writeName("Stale"); ?> It just gives me a blank screen. Now, I figured #fname isnt set, so I did this: <?php $fname = "Refsnes"; function writeName($fname) { echo $fname . " Refsnes.<br />"; } echo "My name is "; writeName("Kai Jim"); echo "My sister's name is "; writeName("Hege"); echo "My brother's name is "; writeName("Stale"); ?> Still, no go, which leads me to think I'm probably mistaking. Help? I don't want to skip out things in a tutorial. Can someone give me an actual time when functions would become handy? Thanks! Hi everyone, Until now i didnt use classes and functions for sql related actions and now i would like to start. I started out with this : class.php --------------------------------------------------- class db { public function connect($database,$user,$password) { $db = mysql_connect("localhost",$user,$password) or die (mysql_error()); mysql_select_db($database); } static function fetch() { function getresults($query) { $resultArray = array(); $fetch = mysql_query($query) or die (mysql_error()); while ($row = mysql_fetch_assoc($fetch)){ $resultArray[] = $row; } return $resultArray; mysql_free_result($fetch); } } } and index.php ---------------------------- <?php require('class.php'); $connection = new db(); $connection->connect("testdb","root","root"); $connection->fetch()->getresults("SELECT * FROM users"); foreach (getresults() as $user) { echo "<div>{$user['user_first_name']}</div>"; } Hi there just wanted to ask you a general question regarding referenced variables and functions in PHP. I have this code: function theRefFunction(&$var){ $var = $var +1; return $var; } $a = 50; echo $thisvalue = theRefFunction($a); Just for learning purposes, as allot of times beginning PHP seriously developers who want to improve on memory consumption in PHP find this tricky, is there any point in using an example like this? I.e. would I really need the &$var as the parameter for the function called 'theRefFunction()'? Just wondered thats all, if not what would be a better way for really using it? It's just so I can go onto maybe doing a loop in it and setting it as a real example like working out tax and stuff like that, just for learning purposes, won't yet be using it. Just wanted to build up as I said earlier a library of things I have done and make maybe my own tutorial site. I look forward to any replies, Jeremy. I have asked this question in 3 different places but I get no answers lol. I hope to find some help here.
i want to only display user role for keymaster and moderator users.
I don't want every participant to have their role shown , only the keymaster and moderators are important enough to me to show their role next to their avatar. The following function code i found, and used... It worked but has some issues:
function role_show () { $displayed_user = bbp_get_reply_author_id() ; $role = bbp_get_user_role( $displayed_user); if ( bbp_is_user_keymaster($displayed_user) ||$role == 'bbp_moderator') $args['show_role'] = true ; else $args['show_role'] = false ; return $args ; } add_filter ('bbp_before_get_reply_author_link_parse_args', 'role_show' )Code Issues: On the Forums topic post lists, This code also removes the avatar from showing in the same cell section as the “last post by” . And it removes the “last post by” name in this same section. How can I fix this ? If needed, I could implement this code again and provide a link to the error so you can see. Thank you for any help. Side notes: Someone told me to try function role_show ($args) {As my first line , but it did not work. It resulted in the following screenshot : as Attached Files functions-picture.png 35.46KB 0 downloads what does the # symbol do in php(e.x index.php?cat=1#privacy)? How can i use it? From what i 've seen you use it for changing a whole div without reloading the page like tabs.. hello all I'm VERY new to php and I just have a simple question how do I bold the output text of this string echo $row['name']."<BR>"; Hello everyone! I am a new user and I have a simple question. How do I set a password for a user to log in to my site with PHP? I have no MySQL database just a iOS code/host app. I know this isn’t secure but only me and my friends are on the site. Any help is appreciated. I've seen this, Code: [Select] <?php } ?> in a lot of scripts at the very end of the script. What does this piece of code do? Hi, I'm working on a product page and I got it to list all the products in one column of a table, but when I add a second column it just duplicates the first column. What do I need to change? Code: [Select] <?php require_once("functions.php"); ?> <!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> td { border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #30C; border-right-color: #30C; border-bottom-color: #30C; border-left-color: #30C; } </style> </head> <body> <form action="" method="post" name="catalog"> <?php DatabaseConnection(); $query = "SELECT * FROM treats"; $result_set = mysql_query($query) or die(mysql_error()); $output = "<table>"; while ($row = mysql_fetch_array($result_set)) { $output .= (" <tr> <td width=\"400px\">" . $row['product_title']."<br /> ".$row['product_Description']."<br />" .$row['price'] . "<br /> Quantity: <input name=\"quantity\" type=\"text\" size=\"2\" /> </td> <td width=\"400px\">" . $row['product_title']."<br /> ".$row['product_Description']."<br />" .$row['price'] . "<br /> Quantity: <input name=\"quantity\" type=\"text\" size=\"2\" /> </td> </tr> "); } $output .= "</table>"; echo $output; ?> </form> </body> </html> I'm teaching myself php and mysql -- and my coding is a little rough. But what i'm trying to do is display information from a mysql table in another table on a website. I can do this just fine simply displaying the table, but i want a little something different. I am only displaying one column of the table, instead of displaying it all in one column, i want to display the information in 5 columns. for example..... the table from mysql has names scott, john, james, mary, simon. with the code I have i can make it display like this: scott scott scott scott scott john john john john john james james james james james mary mary mary mary mary simon simon simon simon simon i want it to diplay like this: scott john james mary simon new names will continue down here is my code: <?php require ("connectigb.php"); $result = mysql_query ("SELECT pledgeName FROM pledgewall"); $fields_num = mysql_num_fields($result); echo "<center> <h1>TSA It Gets Better Pledge Wall</h1>"; echo "<table border='1' align='center' style='width:960px;'><tr>"; while($row = mysql_fetch_row($result)) { echo "<tr>"; // $row is array... foreach( .. ) puts every element // of $row to $cell variable foreach($row as $cell) if ($cell != "") { for ($j=0; $j<5; $j++) { echo "<td>$cell</td>"; } } echo "</tr>\n"; } mysql_free_result($result); echo "</table></center>"; ?> any ideas on what i can do here, i'm sure this is a simply fix. i just haven't come across it yet. thanks for the help in advance. Hello there fellow programmers, I was just wondering if there was any difference between doing this: Code: [Select] echo "Say Something Here"; and this Code: [Select] echo "Say "; echo "Something "; echo "Here"; Thank you in advance. Notice: I am aware of the fact that they will output the same thing, my question is regarding resources. Lets say I have: $var=5; What would an output look like to get me: 1<br> 2<br> 3<br> 4<br> 5<br> Im at a complete loss! Thanks! Hi,
I am trying to convert a php function into perl and need to understand the following line in red :
function pagination($query, $per_page = 10,$page = 1, $url = '?'){ $query = "SELECT COUNT(*) as `num` FROM {$query}"; $row = mysql_fetch_array(mysql_query($query)); $total = $row['num']; $adjacents = "2"; $page = ($page == 0 ? 1 : $page); $start = ($page - 1) * $per_page; $prev = $page - 1; $next = $page + 1; $lastpage = ceil($total/$per_page); $lpm1 = $lastpage - 1; $pagination = ""; if($lastpage > 1) { ......................................... What will be the output of this line above in red. Thank you very much. Regards. Tonya Hi. I have an ID in md5 format but in the database its not. I pass the md5 ID to a page and then I am trying to load the correct record via a look up in the database of that ID. Im wondering is this code possible? <?php $query = mysql_query("SELECT * FROM table WHERE ".md5(tableID)." = $ID"); ?> Thanks Hello to everyone I would like to ask for this simple question.. Im trying to put if and else condition on my php code. However this condition is not working.. Code: [Select] if($file == #3#){ echo "No results found"; }else{ echo "results has been found"; } This variable $file is the result after i used an API.. If the API does not see any results they would return #3# as the result. This means they returned a transaction code of 3 which you can see here http://developer.textapp.net/WebService/TransactionCodes.aspx means that there was nothing to return. The condition does not function well even if i make 3 or #3# as part of the condition. Can you help me guys? thanks Hey! I have a drop down field for my "register" form, but this is clearly easy to edit, I just used tamperdata for firefox and yeah...pretty easy, is there any way that you could prevent tampering with the values when submitting this form!? I can't figure out why im getting an error with this code. if ($notif = mysql_query("SELECT * FROM notifications_1 WHERE recieverid='". $_SESSION['id']."' ORDER BY read ASC, id DESC") or die (mysql_error())); { Code: [Select] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read ASC, id DESC' at line 1 |