PHP - Help Making Number Ranges With Different Steps
i am trying to make a range of numbers which have a step of 11 then 7 then 11 which can then be compared. the result im after is 1, 12, 19, 30. Is there a way i could do this without storing the sets in an array and looping though them? Any help would be greatly appreciated, thanks.
Similar TutorialsI'm getting the dreaded " Invalid parameter number: number of bound variables does not match number of tokens" error and I've looked at this for days. Here is what my table looks like:
| id | int(4) | NO | PRI | NULL | auto_increment | | user_id | int(4) | NO | | NULL | | | recipient | varchar(30) | NO | | NULL | | | subject | varchar(25) | YES | | NULL | | | cc_email | varchar(30) | YES | | NULL | | | reply | varchar(20) | YES | | NULL | | | location | varchar(50) | YES | | NULL | | | stationery | varchar(40) | YES | | NULL | | | ink_color | varchar(12) | YES | | NULL | | | fontchosen | varchar(30) | YES | | NULL | | | message | varchar(500) | NO | | NULL | | | attachment | varchar(40) | YES | | NULL | | | messageDate | datetime | YES | | NULL |Here are my params: $params = array( ':user_id' => $userid, ':recipient' => $this->message_vars['recipient'], ':subject' => $this->message_vars['subject'], ':cc_email' => $this->message_vars['cc_email'], ':reply' => $this->message_vars['reply'], ':location' => $this->message_vars['location'], ':stationery' => $this->message_vars['stationery'], ':ink_color' => $this->message_vars['ink_color'], ':fontchosen' => $this->message_vars['fontchosen'], ':message' => $messageInput, ':attachment' => $this->message_vars['attachment'], ':messageDate' => $date );Here is my sql: $sql = "INSERT INTO messages (user_id,recipient, subject, cc_email, reply, location,stationery, ink_color, fontchosen, message,attachment) VALUES( $userid, :recipient, :subject, :cc_email, :reply, :location, :stationery, :ink_color, :fontchosen, $messageInput, :attachment, $date);"; And lastly, here is how I am calling it: $dbh = parent::$dbh; $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); if (empty($dbh)) return false; $stmt = $dbh->prepare($sql); $stmt->execute($params) or die(print_r($stmt->errorInfo(), true)); if (!$stmt) { print_r($dbh->errorInfo()); }I know my userid is valid and and the date is set above (I've echo'd these out to make sure). Since the id is auto_increment, I do not put that in my sql (though I've tried that too), nor in my params (tried that too). What am I missing? I feel certain it is something small, but I have spent days checking commas, semi-colons and spelling. Can anyone see what I'm doing wrong? Hi all, I am sure this is simple, but I just can't wrap my head around a suitable way of doing this! Basically I have my JSON result as something like : Code: [Select] Array ( [result] => success [source] => gotBits [success] => 64 ) What I simply want to do is get the [success] output and store it as a variable. I have been looking at json_decode, but I cant find any examples for arrays, just strings? Can you push me in the right direction? I am creating an add on to a 3rd party CMS called Concrete5. Normally, when I have client issues, I can trace them to the server and fix them, however, this not doing so well on these issues. The following errors are being displayed in Chrome console:
Checking the server’s folder directory, it is true there is no concrete/fonts directory but there is a concrete/css/fonts directory with a couple of the missing files (but not glyphiconshalflings-regular.woff2).
Back to the errors, clicking the line number (i.e. 927, 3115, and 1), chrome blames apparently innocent line numbers.
What steps would you recommend taking to identify the cause and fix these errors? So I've recently started looking into Character Encoding, after never really bothering with it, and I've got a few questions. After checking out my site it seems I've been using UTF-8 without really realising it, and I'm going to stick with UTF-8. However, when I jump into phpMyAdmin to check out my MySQL tables I run into a few problems. Originally, for my database, the collation was set to latin1_swedish_ci. I have since changed this to utf8_general_ci. This however only affects newly created tables, not the 150 or so tables I currently have which are still latin1_swedish_ci. Do I need to convert the collation of these already existing tables to UTF-8, and if so what's the best method? This takes me to my text editor, NetBeans 7. Do I need to alter anything here, I've not been successful with finding information relating to this? Cheers guys. Hello guys. I'm in need of help. I want to know who to make a full working session. When a player logs in, the session starts. There will be a new button "My Page", he can go there at any time. When he logs off, that button disappears ( Session over ). I'm so bad at explaining stuff. Hope y'all really understood me. This piece of code is used to log the user in: Code: [Select] <?php session_start(); include("config.php"); if(isset($_SESSION["Username"])) { $user = $_SESSION["Username"]; $pass = md5($_SESSION["Password"]); } else { $user = $_POST["User"]; $pass = md5($_POST["Password"]); $_SESSION['Username'] = $user; $_SESSION['Password'] = $pass; $escuser = mysql_real_escape_string($user); $escpass = mysql_real_escape_string($pass); } $result = mysql_query("SELECT * FROM playerinfo WHERE user = '$escuser'"); $num_rows = mysql_num_rows($result); if($num_rows == 0) { echo('That username does not exist...'); echo '<a href="http://yu-ki-ko.com/fsns/""> Go back!</a>'; unset($_SESSION['Username']); unset($_SESSION['Password']); die; } $row = mysql_fetch_row($result); if($row[1] !== $escpass) { echo('Wrong Password!...'); echo '<a href="http://yu-ki-ko.com/fsns/""> Go Back!</a>'; unset($_SESSION['Username']); unset($_SESSION['Password']); die; } ?> Not sure if its working properly or not. I'm stuck at that part. A friend of mine is looking at relaunching a site he used to run and I am going to try to persuade him to move over to a dynamic site. The site is a Football Clubs history site and contains around 2,000 games and several hundred players. The obvious advantage of a dynamic site is that even the bits I just mentioned run to around 2,500 static pages, which could be reduced to just 2 pages if dynamically driven. I am fairly confident that I can do the conversion, but there is one thing that I already know I may struggle with and that is the page which shows game, births and deaths on this day in history. A rough example (using a very heavy Javascript code) can be found at http://follyball.co.uk/jeff/. In a simplified form (ignoring for now the foreign keys to relationships that these tables actually have) there will be two tables GAMES game_id | date | competition | opponent | score | attendance PLAYERS player_id | surname | firstname | date of birth | date of death What I would be looking for is a way to take todays date, and find any corresponding records in games.date, players.date of birth, players.date of death on the same date in previous years. This would be simple to do as three different queries but as I would like to actually mix the three and show them in date order, I would like to do it in one query, presumably using UNIONS. On top of this, I would also like a slightly different output for each different set, for example, if it was a game I would like year, competition, opponent, score, attendance, Whereas if it is a players birth or death, I would like it to show something like firstname surname was born in year Before I go delving too deep into how it may be done, I would like to know if it can be done! I cannot see why it would not be able to generate this but if it is going to be way out of my ability, then I will look for another option! Thanks in advance Steve Hello,
I have problem durring binding update query. I can't find what is causing problem.
public function Update(Entry $e) { try { $query = "update entry set string = $e->string,delimiter=$e->delimiter where entryid= $e->id"; $stmt = $this->db->mysqli->prepare($query); $stmt->bind_param('ssi',$e->string,$e->delimiter,$e->id); $stmt->close(); } catch(Exception $ex) { print 'Error: ' .$ex->getMessage(); } }When I run function update I'm getting next error:Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement Can you help me to solve this problem ? Edited by danchi, 17 October 2014 - 10:25 AM. I need to display a number(the number is retrieved from the db) in the form input field such that only the last 4 digits is visbile, the remaining can be masked as * or X or whatever is applicable. I know the last 4 can be obtained as follows: Code: [Select] $number=substr($number,-4,4); But when i hit the submit button the form validates the input field and checks if the number is a valid number of a specific format. Therefore when I click on the submit button then I should still be able to unmask the masked numbers or do something similar that would help me validate the whole number. Code: [Select] <input type="text" name="no" value="<?php if(!empty($number)){ echo $number;} ?>"> Hey I have a string that looks like the following: Quote top-php-tutorials-2.html I have a script that cycles through each page. The 2 in the quote above is the page number. How can I extract the number between the - and the .html and replace it with another number? I've tried Code: [Select] substr($engine->selectedcaturl, 0,-6).$v.".html"But then I realised this only works for numbers that are 1 digit long Any input would be appreciated hello, i have a start time and an end time (no dates). the following works great, except for when the start time is at night, and the end time is in the morning. im thinking if i can do an if the number is negative, add 24, that it will resolve my issue. any ideas? Code: [Select] $tbilled = $tfinish - $tstart; Hi, I am trying to make a search based on information about a user in the database. Here is my code so far, notice any words like "and" or "the" in a multiword entry would mess it up. Any advice greatly appreciated. Ideally I would like a list of the matches by user name, and put the word "match" next to the matching data, because I used the OR statement it is going to bring back all of the user's info if one of the criteria matches. Any tutorials on the subject or keywords for google would be greatly appreciated. thanks. here is the search code. Code: [Select] <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); $host = " ; $database = " "; $username = " "; $password = " "; $tbl_name = "users"; $conn = mysql_connect($host, $username, $password) or die("Could not connect: " . mysql_error()); if($conn) { mysql_select_db($database); echo "connected to database!!"; } else { echo "failed to select database"; } //include('bouncer.php'); //$currentUser = $_SESSION['myusername']; if(isset($_POST['submit'])) { $dob = mysql_real_escape_string( $_POST['dob']); $gender = mysql_real_escape_string( $_POST['gender']); $ethnic = mysql_real_escape_string( $_POST['ethnic']); //THE SEARCH FUNCTION $sql = mysql_query ( "SELECT * FROM users WHERE dob LIKE '%$dob%' OR gender LIKE '%$gender%' OR race LIKE '%$ethnic%' OR dob LIKE '%$dob%' ") or die(mysql_error()); $result = mysql_query($sql) or die( "<br>Query: $sql<br>Failed with error: " . mysql_error() ); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } // While a row of data exists, put that row in $row as an associative array // Note: If you're expecting just one row, no need to use a loop // Note: If you put extract($row); inside the following loop, you'll // then create $userid, $fullname, and $userstatus while ($row = mysql_fetch_assoc($result)) { echo $row["dob"]; echo $row["gender"]; echo $row["race"]; } }//if(isset($_POST['submit'])) ?> <html> <body> <p>Login Successful</p> <p> </p> <form action="login_success7.php" method="post"> <p> <input name="dob" type="text" size="20" id="dob" /> Date of Birth<br /> <input type="text" name="gender" size="20" id="gender" /> Gender <br /> <input type="text" name="ethnic" size="20" id="ethnic" /> Ethnicity <br /> <input type="submit" name="submit" value=" search" /> <input type="reset" value="Reset fields" /> </p> </form> </body> </html> Good evening, Im using GenRandomString, and wondered how I can get $confirm to keep its first value throughout my script. I have put comments on the lines that use $confirm. Do I need to change $confirm to a constant and how can I go about this? $firstname = $_GET['firstname']; $lastname = $_GET['lastname']; $companyname = $_GET['companyname']; $doornumber = $_GET ['doornumber']; $street = $_GET ['street']; $town = $_GET['town']; $postcode = $_GET['postcode']; $useremail = $_GET ['usermail']; $telephone = $_GET['telephone']; $shortcode = substr($postcode,0,2); function genRandomString() { $length = 10; $characters = '0123456789abcdefghijklmnopqrstuvwxyz'; $string = ""; for ($p = 0; $p < $length; $p++) { $string .= $characters[mt_rand(0, strlen($characters))];} return $string;} $confirm = genRandomString(); //creating a random number $query =mysql_query ("INSERT INTO treesurgeons (firstname, lastname, companyname, doornumber, street, town, postcode, useremail, telephone, Id) VALUES ('$firstname', '$lastname', '$companyname','$doornumber', '$street', '$town', '$postcode', '$useremail', '$telephone', '$confirm')");//1st Value echo mysql_error(); echo "<p>Thankyou for submiting your details.\r\n Please check your inbox and click on your confirmation link.</p>"; $message = "The following details have been submited to the tree directory and are awaiting confirmation; \r\n Please click on the link below to confirm these details are correct\r\n '$firstname', '$lastname', '$companyname','$doornumber', '$street', '$town', '$postcode', '$usermail', '$telephone' <a href='http://www.mywebsite.co.uk/confirmed.php?Id=$confirm'>"; //2nd Value $subject = "Your tree directory details"; $to = "$useremail"; $email = "$emailad"; mail( "$to", "$subject","$message", "$headers"); ?></body></html> I havent really played around with constants before, so please an advice appreciated! Im guessing im using DEFINE but im unsure how I would combine this with GenRandomString in my code. Let's try something simple: I have a form that retrieves data from database and organizes the numbers inside of a table (sometimes in an input box). Is there a simple code so that VALUES > zero will be in BOLD font? Ok here are my 3 php pages: set.php <?php $Month = 2592000 + time(); $value = '1'; setcookie("cs_hpage", $value, $Month); ?> get.php <?php if (isset($_COOKIE["cs_hpage"])) { $cookie = $_COOKIE["cs_hpage"]; print("Received a cookie: ".$cookie."\n"); } else { print("Fail!.\n"); } ?> clear.php <?php setcookie ("cs_hpage", "", time()-60000); ?> It all works like charm but i dont know how to set if $cookie == 1 echo "Cookie here!" and if other then 1 echo "Fail!" All i managed to do is as you can see to echo the cookie :/ And question no.2: How can i set a cookie through a button?? (Like when pressed set cookie to value "1") Thanks.. Hi guys! new to forum and to coding. I have poured over the forums and lots of places for an answer. I am not sure if this is due to my thus far limited understanding or, nto a specific enough question was asked. Basically it was suggested to me to make a link on a site from this: Search our Catalog: It was asked that I tie a link to that text and make it sort of a button so that when clicked, it takes someone to our catalog. The site is built with Drupal 6 and uses Danland theme and and a WYSIWYG. WHen I open the gear to edit this section I see: "<P align=right><a href="https://catalog.ncpl.lib.oh.us/polaris/logon.aspx"> Access Library Account</a> - <a href="https://catalog.ncpl.lib.oh.us/polaris/patronaccount/selfregister.aspx?"> Get a Card</a> - <a href="http://catalog.ncpl.lib.oh.us/polaris/search/default.aspx">Search Catalog</a></P> <!-- // Start of Search form --> <script language="javascript"> String.prototype.trim = function() { return this.replace(/^\s*|\s*$/g,''); } function ProcessInput(e) { if (window.event) // IE keyNum = e.keyCode; else if (e.which) // Netscape/Firefox/Opera keyNum = e.which; if (keyNum == 13) { e.returnValue = false; e.cancelBubble = true; DoKeywordSearch('KW'); return false; } return true; } function DoKeywordSearch() { if (document.getElementById('textboxTerm').value.trim() != '') { var strURL = 'http://catalog.ncpl.lib.oh.us/polaris/search/searchresults.aspx?ctx=1.1033.0.0.1'; var strWindex = document.getElementById('Windex').value; var strTerm = escape(document.getElementById('textboxTerm').value); window.location = strURL + "&type=Keyword&limit=TOM=*&sort=PD_TI&Page=0&by=" + strWindex + "&term=" + strTerm; } else { alert('Please enter a search term'); document.getElementById('textboxTerm').focus(); } } </script> <noscript>JavaScript must be enabled for catalog!</noscript> <table border="0"> <tr> <td> <label for="search">Search our Catalog:</label> <input class="search" type=text id=textboxTerm size=30 onkeypress="return ProcessInput(event)" /> <select class="search" id="Windex"> <option value="KW" selected="selected"> Anywhere </option> <option value="SU"> Subject </option> <option value="TI"> Title </option> <option value="AU"> Author </option> <option value="KW&fic=1"> Fiction </option> <option value="KW&fic=0"> Nonfiction </option> </select> <input type="submit" class="button" value="Go!" name="submit" onclick="DoKeywordSearch()" /> </td> </tr> </table> <!--// End of Search form -->" My question is where would the code for the link go and is there a good resource i can use to figure out how to write it? Any help is greatly appreciated, thank you. Hello. I want to make a web-based rpg with mysql and php but need alot of help, I tryed once and failed. Please msn me: cginbarrhaven@hotmail.com I need LOTS of help. Im stuck! Zeroth What kinds of things can I do to make Logging-In and being Logged-In *secure*?? I get the whole form validation thingy, but what about from the standpoint of how/where I store data in my database and how I keep track of who is logged in and where they can go, and so on? Thanks, Debbie Hi, Im trying to make pages switch. Read data from database and but every 10 data in 1 pages. I got my way on making pages by using PHP, but my way is not efficient. Please teach me and tell me the correct way or concept to do it. Or is there any website teaching this? Appreciate for the help thanks. Hi there,
Can somebody please help me with the writing of a code for the following text?
4 I am having a dilemma. I am working on a script for a client. It is a match making system. It takes all the teams, minimum of 20 teams. 10 matches a season. No team can play the same team in the season. Here is my code I have so far. If it does not make sense ask me, I will try to explain more in depth.
<?php error_reporting(E_ALL); include("security/config.php"); //create season for testing purposes $sql_season = "insert into season (`season`) values ('1')"; $conn->query($sql_season) or die($conn->error); $season = 1; //testing purpose echo "Season 1:<br />"; //testing purpose //get number of teams $sql_teams = "select * from teams"; $rs = $conn->query($sql_teams) or die($conn->error); $num_of_teams = $rs->num_rows; echo " Number of teams this season: {$num_of_teams}<br />"; //testing purpose //put all teams in array $teams = array(); while($ts = $rs->fetch_array(MYSQLI_ASSOC)){ $teams[] = $ts; } if($num_of_teams % 2 != 0){ $teams[] = array('name' => 'bye week', 'id' => 0); $sql_dummy = "insert into teams (`name`) values ('bye week')"; $conn->query($sql_dummy); } //how many matches $weeks = 10; $matches = 10; echo " This Seaon will be {$weeks} consisting of {$matches} matches<br /><br />"; //testing purpose for($i = 0; $i < $weeks; $i++){ //mix up teams $teams1 = $teams; $teams2 = $teams; shuffle($teams1); shuffle($teams2); $week = $i + 1; //$sql_week = "insert into weeks (`number`, `season_id`) values ('{$week}', '{$season}')"; //$conn->query($sql_week) or die($conn->error); //$weekID = $conn->insert_id; echo " Week {$week} Created:<br />"; //$matchup = array(); for($x = 0; $x < $matches; $x++){ shuffle($teams1); shuffle($teams2); $team_1 = array_pop($teams1); $team_2 = array_pop($teams2); $rs = false; $rs = ($team_1['id'] == $team_2['id'] ? true : false); $sql_search = "select * from matches where season_id = '{$season}' " $sql_search .= "and team_1 = ('{$team_1['id']}' or '{$team_2['id']}') "; $sql_search .= "and team_2 = ('{$team_1['id']}' or '{$team_2['id']}')"; $rss = $conn->query($sql_search) or die($conn->error); if(!$rs || !$rss){ $sql_create = "insert into matches (`team_1`, `team_2`, `week`, `season_id`) values ('{$team_1['id']}', '{$team_2['id']}', '{$week}', '{$season}')"; $rs = $conn->query($sql_create); if($rs){ echo " "; //testing purpose echo "{$team_1['name']} vs {$team_2['name']}<br />"; //testing purpose } else{ echo 'error: ' . $conn->error . '<br />'; //testing purpose } } else{ $teams1[] = $team_1; $teams2[] = $team_2; $x--; } } } |