PHP - Do I Need A Parameter In This Function?
Code: [Select]
function fetch_feedback_best() { $sql = "SELECT `like` FROM `feedback` GROUP BY `page` asc LIMIT 10"; while($row = mysql_fetch_assoc($sql)) { $results[] = $row; } return $results; } This doesn't work. My error is "Warning: mysql_fetch_assoc() expects parameter 1 to be resource, string given in /blah.inc.php on line 105 ". Code: [Select] <?php $results = fetch_feedback_best(); foreach ($results as $result) { ?> echo $result['page']; } ?> Similar TutorialsHello I am experiencing some issues with a function and I cannot identify the problem. The function is not receiving any parameter. The URL values are passed correctly. I used echo to display the parameters outside the function and that worked. I also used echo to display the parameters inside the function and no parameter were displayed. So the function is not receiving parameters. Code: [Select] <?php $find = $_REQUEST['u_find']; $field = $_REQUEST['u_field']; $searching = $_REQUEST['u_search']; echo"(1a)$find, (1b)$field, (1c)$searching";//outside function function test_display($searching, $field, $find) { echo"(2a)$find, (2b)$field, (2c)$searching";//inside function } ?> Hi all
Is it possible to have a function with two parameters but and then check if one is passed before using it.
In this code here I want to remove spaces and change to lowercase.
If the $extra parameter is set I want to add that to the end of the string.
function className($nametoUse, $extra){ I'm fairly new to this and I have looked around but I can't find much information on it. Basically I know what an array and a function is but I'm currently working through an oop login and register sytem and I am seeing this quite a lot:
function myFunction($myVariable = array()){
$Firstvariable = $myVariable[0];
$Secondvariable = $myVariable[1];
//etc
}
This is really confusing me and I can't see any examples in any tutorial sites or books of an array and a function being used like this. Can someone just explain how something like this would work in simple terms? I have also checked the manual but I can't see an example an array being used like this. Any help would be much appreciated. Thanks.
HI, i'm using a class to create a database connection etc..
So I have something like this in a common.inc.php file which is include in each page
$db_numbers_args = array(); $db_numbers_args['host'] = "localhost"; $db_numbers_args['user'] = "puser"; $db_numbers_args['pass'] = "nuser"; $db_numbers_args['db'] = "nu_name"; $db_numbers = new db($db_numbers_args,TRUE); From there I can end up making query's like $res = $db_numbers->query($uqs); So that said i'm including another file that contains all functions, when the functions need to do database transactions I always need to put $db_numbers as a paramter to the function and each function I make.. How should I make this better ? If I have a parameter that has a default value, how do I pass nothing such that it uses the default value? Passing NULL does not work. Code: [Select] function test($to = "test@test.com", $from) { echo $to . "<BR>" . $from; } //This will NOT show "test@test.com" but instead an empty line test( NULL, "fake@fake.com" ); how do i enable exec() in php.ini? where is php.ini? cant find it in the directories in my site. One more question. So I have a function with two parameters, $x and $y. Here it is. Code: [Select] function dydx($x,$y){ $equation = 2 * $x; return $equation; } Now here's the problem. I want $equation to be user defined. Easy enough, I use a post command and I get $equation to equal whatever the user inputs. The problem is that if I get input from the user, I'm not sure how to take that input and then have the function parameters work on it. Like if the user inputs "3*$x + 2*$y", i want to be able to let the parameters for the function dydx act on it. How could I go about doing this? Hello,
I recently posted here about an issue I was having with my database orientated products page.
I have now run into another problem where say if, /db.php was typed or /db.php?p=IDoNotExist was typed, it returns blank.
I have in my code the desired content to be displayed, but it just doesn't seem to want to make a show.
I was also wondering if it is possible to show different content for whatever the URL is, so for no parameter, the content about the products, and a non existent one, maybe "Product not found"?
Here is my code:
<?php $db=mysql_connect ("localhost", "webwibco_charlie", "Hello123") or die ('I cannot connect to the database because: ' . mysql_error()); $mydb=mysql_select_db("webwibco_products"); include("header.php"); $status = htmlspecialchars( @$_GET ['p'] ); if ($status == "floorpuzzles") { echo "<h1>Our Floor Puzzles</h1>"; $sql="SELECT ID, Name, Tags, Description, Category FROM products WHERE Category LIKE '%" . FloorPuzzles . "%'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $Name =$row['Name']; $ID =$row['ID']; $Description =$row['Description']; echo "<div class=\"box\">"; echo "<h1>$Name</h1>"; echo "<div class=\"floorbox\"><a href=\"?p=$ID\"><img src=\"images/products/catalogue/big/floorpuzzles/$ID.jpg\" class=\"small\"></a></div>"; echo "<h2>$Description</h2>"; echo "</div>"; } ?> <? }else{ if ($status == $_GET["p"]) { $sql="SELECT ID, Name, Tags, Description, Pieces, Size, Barcode, Category FROM products WHERE ID = '" . $_GET['p'] . "'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $Name =$row['Name']; $ID =$row['ID']; $Description =$row['Description']; $Pieces =$row['Pieces']; $Size =$row['Size']; $Barcode =$row['Barcode']; echo "<div class=\"1\">"; echo "<h1>$Name</h1>"; echo "<div class=\"bigbox\">"; echo "<div class=\"floorbox\"><img src=\"images/products/catalogue/big/floorpuzzles/$ID.jpg\" class=\"big\"></div>"; echo "</div>"; echo "</div>"; echo "<div class=\"2\">"; echo "<p>Puzzle Pieces: $Pieces</p> <p>Puzzle Size: $Size</p> <p>Barcode: $Barcode</p>"; echo "</div>"; } }else{ ?> <? echo"<h1>Our Products</h1> <p>Our jigsaw puzzles are hand cut by skilled craftsmen and therefore each one is unique with self-correcting pieces. There is a strict quality control process at all stages by our highly experienced staff. The puzzles are durable and provide fun and excitement, enhancing learning and a child’s development.<p> <p>All of our jigsaws are made using materials from sustainable resources grown in managed forests. Where possible we support companies in the UK and source our components locally, most of our suppliers are in the East Midlands, many in Derbyshire and Nottinghamshire. We keep packaging to a minimum and take our environmental and ethical responsibilities very seriously.</p> <p>Reducing waste and recycling was a way of life for us before it became fashionable. We are constantly searching for new ideas and consult teachers when developing our jigsaws, which are often used within the national curriculum.</p> <p>As well as making our own range, we manufacture for leading suppliers to the education market. Check for \"Made in Britain\" and it is probably made by us.</p> <p>We have a wide variety of products available for viewing, from classic floor puzzles to innovative inset trays. You can take a look at all our products on this page, simply use the navigation buttons to your left.</p>"; }} include("footer.php"); ?>The final echo is what I wish to be displayed on the URL without or with an invalid parameter. Here is my site URL: http://www.webwib.co...saws/search.php (note that only the "Floor Puzzles" category has content within it). Thank you in advance for assistance. I have the following code just to insert a username and hashed password into the database but somehow I am getting this error and I couldn't find out where I am doing it wrong...can someone please give me a hand?
I tried it in two ways and both errors...
the first few lines are just connecting database which worked fine and a password.php so I can use password_hash() with my php version
$hash = password_hash('xx', PASSWORD_BCRYPT, array('cost' => 10)); $username = 'xx'; $insertQuery = $db->prepare(" INSERT INTO et_todo (username, password) VALUES (:username, :hash) "); $insertQuery->execute(array( 'username' => $username, 'password' => $hash ));also tried $hash = password_hash('xx', PASSWORD_BCRYPT, array('cost' => 10)); $insertQuery = $db->prepare(" INSERT INTO et_todo (username, password) VALUES ('xx', :hash) "); $insertQuery->execute(array( 'username' => 'xx', 'password' => $hash )); Hi! Code: [Select] $url = "http://www.youtube.com/watch?feature=player_embedded&v=IwPHy17Iu6E"; I have code Code: [Select] if (preg_match("/http:\/\/www.youtube.com\/watch\?v=([0-9a-zA-Z-_]*)(.*)/i", $url, $matches)) { return '<object height="'.$embed_height.'" width="'.$embed_width.'">'. '<param name="movie" value="http://www.youtube.com/v/'.$matches[1].'" />'. '<param name="wmode" value="transparent" />'. '<embed src="http://www.youtube.com/v/'.$matches[1].'&autoplay=1" type="application/x-shockwave-flash" wmode="transparent" height="'.$embed_height.'" width="'.$embed_width.'" />'. '</object>'; }How to remove feature=player_embedded& from $url ? Hi guys, please help me to solve my problem. i want to get the url parameter using /
for now i use index.php?category_id=14
how can i change the ?category_id=14 to index.php/14
thank you so much.
Hey guys, I'm dealing a url that is similar to hxxp://domain/directory/?#{$id}. What I'm trying to do is extract $id from that. Its not available as a $_GET variable and $_SERVER['REQUEST_URI'] comes up as "/directory/?". Does anyone know how I could retrieve $id ? Thanks Hi all I have an SQL database with products in and I need to write the PHP script to select from the SQl based on values in the URL. The URL looks like this: product.php?category=32&type=90&colour=10 So I can do the script: if (isset($_GET['category']) && isset($_GET['type']) && isset($_GET['colour'])){ $sqlCommand = "SELECT * FROM products WHERE category = '$category' AND type = '$type' AND colour = '$colour'"; } Which works great, I have also got the other versions if the type and colour are empty. What I can't do is get it to select all from the database where the category = 32 and the type = 90 if the URL looks like this: product.php?category=32&type=90&colour= In other words where the colour is set but is empty. I want the script to show all products that have the category of 32 and the type of 90 if this is the case Please help! Many thanks Pete I am trying to create a simple voting form. Everything goes well until I submit and then I get a Warning: mysqli_error() expects exactly 1 parameter, 0 given on line 79 error. I am assuming it is not pulling the ID correctly but as I am new to php and mysqli I cannot exactly say if it the way the code is written or if I am calling the parameter incorrectly in the query. Again I am new to to this so please be gentle. Below is my code. It pulls the drop down list correctly and echo's correctly but I believe my post query to be a little out of wack. Could someone point me in the correct direction? It would be very appreciated.
<form action="businesstype_update.php" method="post"> <?php if(isset($_POST['voteall'])){ $vote_lg = "update membertest where id={$row_lg['id']} set vote=vote+1"; $run_lg = mysqli_query($con, $vote_lg) or die(mysqli_error()); } $result_lg = mysqli_query($con, "SELECT id, business FROM membertest WHERE businesstype='large'"); echo "Vote for large business of the year! <SELECT name='business'>\n"; echo "<option>Select a large business</option>"; while($row_lg = $result_lg->fetch_assoc()) { echo "<option value='{$row_lg['id']}'>{$row_lg['business']}</option>\n"; } echo "</select></br></br>\n"; echo "<input type='submit' name='voteall' value='voteall'>"; $result_lg->close(); $con->close(); I have a pagination class that uses PHP_SELF to display the proper URLs when generating the pagination buttons. I need PHP_SELF to be a class parameter so that if the page is not defined in the parameter, then use PHP_SELF. The reason for this is because I generate the class in an ajax file and it is returning the URL of the ajax file, not of the page I am running the ajax on. I just don't know how to add the parameter to the class. The class is below: Code: [Select] <?php class Paginator{ var $items_per_page; var $items_total; var $current_page; var $num_pages; var $mid_range; var $low; var $high; var $limit; var $return; var $default_ipp; var $querystring; function Paginator() { $this->current_page = 1; $this->mid_range = 7; $this->items_per_page = (!empty($_GET['ipp'])) ? $_GET['ipp']:$this->default_ipp; } function paginate($default_ipp) { if((isset($_GET['ipp'])) && ($_GET['ipp'] == 'All')) { $this->num_pages = ceil($this->items_total/$default_ipp); $this->items_per_page = $default_ipp; } else { if(!is_numeric($this->items_per_page) OR $this->items_per_page <= 0) $this->items_per_page = $default_ipp; $this->num_pages = ceil($this->items_total/$this->items_per_page); } if(isset($_GET['page'])) { $this->current_page = (int) $_GET['page']; // must be numeric > 0 } if($this->current_page < 1 Or !is_numeric($this->current_page)) $this->current_page = 1; if($this->current_page > $this->num_pages) $this->current_page = $this->num_pages; $prev_page = $this->current_page-1; $next_page = $this->current_page+1; if($_GET) { $args = explode("&",$_SERVER['QUERY_STRING']); foreach($args as $arg) { $keyval = explode("=",$arg); if($keyval[0] != "page" And $keyval[0] != "ipp") $this->querystring .= "&" . $arg; } } if($_POST) { foreach($_POST as $key=>$val) { if($key != "page" And $key != "ipp") $this->querystring .= "&$key=$val"; } } if($this->num_pages > 1) { $this->return = ($this->current_page != 1 And $this->items_total >= 1) ? "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$prev_page&ipp=$this->items_per_page$this->querystring\">« Previous</a> ":"<!--<span class=\"inactive\" href=\"#\">« Previous</span>-->"; $this->start_range = $this->current_page - floor($this->mid_range/2); $this->end_range = $this->current_page + floor($this->mid_range/2); if($this->start_range <= 0) { $this->end_range += abs($this->start_range)+1; $this->start_range = 1; } if($this->end_range > $this->num_pages) { $this->start_range -= $this->end_range-$this->num_pages; $this->end_range = $this->num_pages; } $this->range = range($this->start_range,$this->end_range); for($i=1;$i<=$this->num_pages;$i++) { if($this->range[0] > 2 And $i == $this->range[0]) $this->return .= " ... "; // loop through all pages. if first, last, or in range, display if($i==1 Or $i==$this->num_pages Or in_array($i,$this->range)) { $this->return .= (($i == $this->current_page) And (isset($_GET['page'])) And ($_GET['page'] != 'All')) ? "<a title=\"Go to page $i of $this->num_pages\" class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" title=\"Go to page $i of $this->num_pages\" href=\"$_SERVER[PHP_SELF]?page=$i&ipp=$this->items_per_page$this->querystring\">$i</a> "; } if($this->range[$this->mid_range-1] < $this->num_pages-1 And $i == $this->range[$this->mid_range-1]) $this->return .= " ... "; } $this->return .= (($this->current_page != $this->num_pages And $this->items_total >= 1) //And ($_GET['page'] != 'All') ) ? "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$next_page&ipp=$this->items_per_page$this->querystring\">Next »</a>\n":"<!--<span class=\"inactive\" href=\"#\">» Next</span>-->\n"; //$this->return .= ((isset($_GET['page'])) And ($_GET['page'] == 'All')) ? "<a class=\"current\" style=\"margin-left:10px\" href=\"#\">All</a> \n":"<a class=\"paginate\" style=\"margin-left:10px\" href=\"$_SERVER[PHP_SELF]?page=1&ipp=All$this->querystring\">All</a> \n"; } else { for($i=1;$i<=$this->num_pages;$i++) { $this->return .= ($i == $this->current_page) ? "<a class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$i&ipp=$this->items_per_page$this->querystring\">$i</a> "; } $this->return .= "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=1&ipp=All$this->querystring\">All</a> \n"; } $this->low = ($this->current_page-1) * $this->items_per_page; if(isset($_GET['ipp'])) { $this->high = ($_GET['ipp'] == 'All') ? $this->items_total:($this->current_page * $this->items_per_page)-1; $this->limit = ($_GET['ipp'] == 'All') ? "":" LIMIT $this->low,$this->items_per_page"; } else { $this->high = ($this->current_page * $this->items_per_page)-1; $this->limit = " LIMIT $this->low,$this->items_per_page"; } } function display_items_per_page() { $items = ''; $ipp_array = array(10,25,50,100,'All'); foreach($ipp_array as $ipp_opt) $items .= ($ipp_opt == $this->items_per_page) ? "<option selected value=\"$ipp_opt\">$ipp_opt</option>\n":"<option value=\"$ipp_opt\">$ipp_opt</option>\n"; return "<span class=\"paginate\">Items per page:</span><select class=\"paginate\" onchange=\"window.location='$_SERVER[PHP_SELF]?page=1&ipp='+this[this.selectedIndex].value+'$this->querystring';return false\">$items</select>\n"; } function display_jump_menu() { for($i=1;$i<=$this->num_pages;$i++) { $option .= ($i==$this->current_page) ? "<option value=\"$i\" selected>$i</option>\n":"<option value=\"$i\">$i</option>\n"; } return "<span class=\"paginate\">Page:</span><select class=\"paginate\" onchange=\"window.location='$_SERVER[PHP_SELF]?page='+this[this.selectedIndex].value+'&ipp=$this->items_per_page$this->querystring';return false\">$option</select>\n"; } function display_pages() { return $this->return; } } Hi all, I have received this error, and I could clearly recall I did not actually change any content in the file. May I know how should I debug it? Thanks Warning: mysqli_error() expects exactly 1 parameter, 0 given in D:\inetpub\vhosts\abc.com\httpdocs\inc\php\tutor\t_reg_post1.php on line 163 Hi, I have the following mqsql query which works fine on my page called property.php <?php $result = mysql_query("SELECT * FROM properties WHERE Property_Name='Test Hotel'") or die(mysql_error()); $row = mysql_fetch_array( $result ); echo "Property Name: ".$row['Property_Name']; echo "<br>Property Rating: ".$row['Property_Rating']; echo "<br>Property Address: ".$row['Property_Address']; ?> Where I use the value of 'Test Hotel' for Property Name in above, how can I insert this value from a url parameter like /property.php?propertyname=Test Hotel? Thanks so much. Hi all I am working on a filter system that when a user selects a drop down menu item it automatically updates the page taking the value from the form and sending it through the URL parameter to update the page accordingly: <form id="category_filter" name="category_filter" method="post" action=""> <label for="category_filter"></label> <select name="category_filter" id="category_filter" style="width: 160px" onchange="this.form.submit();" > <option value="" selected class="meter-calc-text">Category</option> <?php $fetchcategories=mysql_query("SELECT * FROM `categories` ORDER BY position ASC"); while($returnedcategories=mysql_fetch_array($fetchcategories)) { echo "<option value=\"".$returnedcategories['name']."\" >".$returnedcategories['name']."</option>"; } ?> </select> </form> The only thing is, it doesn't pass the value to the url, it remains blank Many thanks for your help. Pete This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=358276.0 Hi there im using dream weaver and ive created a form that can be updated: Code: [Select] if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) { $updateSQL = sprintf("UPDATE ships SET FleetName=%s, HealthA=%s, HealthB=%s WHERE ShipID=%s", GetSQLValueString($_POST['select'], "text"), GetSQLValueString($_POST['textfield'], "int"), GetSQLValueString($_POST['textfield2'], "int"), GetSQLValueString($_POST['hiddenField'], "int")); mysql_select_db($database_swb, $swb); $Result1 = mysql_query($updateSQL, $swb) or die(mysql_error()); $updateGoTo = "fleet.php"; if (isset($_SERVER['QUERY_STRING'])) { $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $updateGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $updateGoTo)); } I want to parse a parameter after its updated and directed to another page but i cant seem to get it to work: Code: [Select] $updateGoTo = "fleet.php?recordID=$row_Ship['FleetName']"; Please help Thanks |