PHP - Number Diamond
Hi all
I am trying to print a pattern shown below: 1 23 456 7891011 1213141516 17181920 212223 2425 26 Any know how to do it? I'm a bit stuck, I completed it with asterix. 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? 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. Im trying to make a PHP code that will find the average number. What I want is, a lot of input fields where you can write a number in. Then my code should take these numbers and divide them with the amount of input fields that has been written in. So that some fields you don't have to write a number, and the code will still give you a correct average. My code so far: Code: [Select] <?php if (isset($_POST['calc'])) { $m=$_POST['mat']; $e=$_POST['da']; $s=$_POST['eng']; $f=$_POST['fys']; $h=$_POST['bio']; $p=$_POST['geo']; $ave=($m+$e+$s+$f+$h+$p)/; } ?> <a href="" onclick="return hs.htmlExpand(this, { headingText: 'Beregn dit Gennemsnit:' })"> <b>Beregn dit Gennemsnit: <?php echo $ave;?></b><br></br> </a> <div class="highslide-maincontent"> <form id="gennemsnit" name="form1" method="post" action=""> Matematik<input name="math" type="text" id="mat" size="3" maxlength="4" /><br /> Dansk<input name="eng" type="text" id="da" size="3" maxlength="4" /><br /> Engelsk<input name="sci" type="text" id="eng" size="3" maxlength="4" /><br /> Fysik<input name="fil" type="text" id="fys" size="3" maxlength="4" /><br /> Biologi<input name="he" type="text" id="bio" size="3" maxlength="4" /><br /> Geografi<input name="pe" type="text" id="geo" size="3" maxlength="4" /></td><br /> <input name="calc" type="submit" id="calc" value="Beregn"/><br /><br /> </form> What I need is the code of how to divide with the amount of input fields that has been written in. thanks for any help $insertCount=0; foreach($results[1] as $curName) { if($insert){$insertCount++;} echo <<< END $curName<BR> END; } Right now the results would show up as... Bill Fred Jessica James John How do you make them show up like... 1 Bill 2 Fred 3 Jessica 4 James 5 John I have these numbers in an array: 14042 11130 10100 10100 9506 How can I add them all together? Was thinking about a while loop. Derp. >array_sum solved! I am trying to create a registration form where users put their name, email and password only.
but i want to write an auto generated account number into database table for each user e.g; XY1234567 where XY should not change 1234567 auto generated random number and no duplicates (in numbers only).
example...
XY1234567
XY2345678
XY2233455
i found code
$num_of_ids = 10000; //Number of "ids" to generate. $i = 0; //Loop counter. $n = 0; //"id" number piece. $l = "AAA"; //"id" letter piece. while ($i <= $num_of_ids) { $id = $l . sprintf("%04d", $n); //Create "id". Sprintf pads the number to make it 4 digits. echo $id . "<br>"; //Print out the id. if ($n == 9999) { //Once the number reaches 9999, increase the letter by one and reset number to 0. $n = 0; $l++; } $i++; $n++; //Letters can be incremented the same as numbers. Adding 1 to "AAA" prints out "AAB". }but its not working as i want. Any help please? Edited by 684425, 27 December 2014 - 12:58 PM. How can I test if a string has a number at the end? i.e. smith1 instead of smith? I won't know how long the string is or whether there is more than 1 number but I will know that the string's last character is a number. Thank you! Hello Everyone, i have developed one WAP application, i want to get MSISDN number of users who visit my site. My operator has also white listed my WAP application. I am getting MSISDN successfully on couple of Samsung Mobiles, but not getting same result on NOKIA, BLACKBERRY AND I PHONE or any other device. Please suggest me best way to get MSISDN number for all devices. Thanks, Nirav <?php echo "How much money do you want landed on the account?!\n"; $landed = fgets(STDIN); $calc = ($landed * .25); $total = ($landed + $calc); echo "\nYou need to list the dummy for $".$total."...\n\n"; echo "Press enter to close this script..."; $exit = fgets(STDIN); ?> so say I enter 12000000000 which would make the $total .. $15000000000 how so I make the total have commas in it, like $15,000,000,000 Hi all, I'm trying to build a simple shopping cart, there are only 8 products and I want to save the quantity value into a section for each product (product1, product2, etc). I'm having a problem where the I can't get the session value to increase by one if the same item is added to the cart again. Here is the code I have so far, am I missing something or is there a php setting that would cause this not to work. <?php session_start(); // setup if(!isset($_SESSION['product1'])) $_SESSION['product1'] = 0; if(!isset($_SESSION['product2'])) $_SESSION['product2'] = 0; if(!isset($_SESSION['product3'])) $_SESSION['product3'] = 0; if(!isset($_SESSION['product4'])) $_SESSION['product4'] = 0; if(!isset($_SESSION['product5'])) $_SESSION['product5'] = 0; if(!isset($_SESSION['product6'])) $_SESSION['product6'] = 0; if(!isset($_SESSION['product7'])) $_SESSION['product7'] = 0; if(!isset($_SESSION['product8'])) $_SESSION['product8'] = 0; // add product if(mysql_escape_string($_GET['add']) != '') { $addItem = mysql_escape_string($_GET['add']); $_SESSION["product$addItem"] = $_SESSION["product$addItem"] + 1; } echo "product$addItem = ".$_SESSION["product$addItem"]; ?> Thanks! Hi, I want to chenge the following statement so that numbers ending with ".00" are changed to blank. Many opinions but I haven't got any to work. Any help? <td align=right class="currency">$'.number_format($row['value1'],2).'</td> Hi Guys I have a code what inserts very simple queries to database, im trying to add a random reference number for each enrty using $reference = rand(111111111111,999999999999); but each time I add an entry it gives me the same random number previously generated for previous entry can you help pleasE? Suppose I have a series of numbers being stored in an SQL table, which are not uniform and constantly growing. Once the numbers in the table (in sql) hit 99,999,999, they start back at 1, and do it all over again continuously until the end of time.
If I am performing calculations in PHP on these numbers (stop date-start date), is there a function that can take a look at the next cell after 99,999,999 and acknowledge that the 1 is really 100,000,000.
In the below example, instead of using 99,999,999, we used 4 as the last number before numerical reset. Once the numbers hit 4, they reset to 1. continuously.
Example1. If I were to subtract Jan 1(start) from jan 4(stop) I would have Stopdate -Startdate = 4-1 =3.
Example2. If I were to subtract Jan 4(start) from jan 7(stop) I would have Stopdate-Startdate = 3-4 =-1 but should be 7-4 for the sake of the calculation only.
Example3. If I were to subtract Jan 8(start) from jan 11(stop), I would have Stopdate-Startdate = 3-4=-1 but should be 11-8=3 but for ease of not having to be a continuous repeating thing, can be represented at 7-4. There is no need to keep a running memory towards infinity. It just needs to know that any number after some number ending in 4 is 5, instead of reseting to 1.
jan 1 2014.......1
jan 2 2014.......2
jan 3 2014.......3
jan 4 2014.......4
jan 5 2014.......1
jan 6 2014.......2
jan 7 2014.......3
jan 8 2014.......4
jan 9 2014.......1
jan10 2014......2
jan11 2014......3
Hope this is not that confusing.
Long story short, I can't do a stopdate-startdate = somenumber, if that some number keeps resetting to 1 once it reached 99,999,999. As a result, my code will work perfectly until I reach 99,999,999, then I am in trouble because 1-99,999,999 is not equal to 1, where 100,000,000 -99,999,999 = 1
thanks.
Edited by Butterbean, 24 October 2014 - 02:24 PM. i wanted to choose 5 random numbers from 0-20. each number represents an index in an array. is there a way to pick out 5 random items from the array. say if random number generator piked a number 22, the last item in the array is at index 20, it wud then have to go to index 0. thanks! I m printing the prices of the items in my db. I want to print the prices like ; Price --- The format I want 75.000 --- 75 75.500 --- 75.5 100 --- 100 100.5 --- 100.5 1234.654 --- 1,234.654 1234.200 --- 1,234.2 1123456.789 --- 1,123,456.789 Simply I want to cancel the zeros after dot, and want to put comma every 3 digits before the dot. How can I do this ? One more question to ask. I'm trying to do a count of total logins that have happened in the last 5 months including the current one so far. My users_logins table has the following structu users_id, session_id, login_date(datetime), last_activity(datetime). What the end result is going to be is: <tr> <td></td> <th scope="col"><?php echo date("M", strtotime("-4 month")); ?></th> <th scope="col"><?php echo date("M", strtotime("-3 month")); ?></th> <th scope="col"><?php echo date("M", strtotime("-2 month")); ?></th> <th scope="col"><?php echo date("M", strtotime("-1 month")); ?></th> <th scope="col"><?php echo date("M"); ?></th> </tr> <tr> <th scope="row">Logins</th> <td>94</td> <td>53</td> <td>124</td> <td>92</td> <td>105</td> </tr> Where the first td would be May and the last td would be September. Do I have to do this in 4 separate queries. If so here's what I have for the first query. I'm not sure what woudl go for the WHERE. $four_months_ago_query = "SELCT COUNT(date_login) FROM users_logins WHERE ? "; I have to do an assignment for school where I create an html page and a separate page for php. The code is to sum two numbers and return an error if the value entered is not numeric. The sum portion is working; however the numeric validation is not. The code is he
<!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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Enter your information in the form below</title> </head> <body> <!-- Form2.html --> <form action="Form2.php" method="post"> <fieldset><legend> Enter a number in the form below:</legend> <p><b>number 1: <input type="text" name="number1" size="4" maxlength="4" /></b></p> <p><b>number 2: <input type="text" name="number2" size="4" maxlength="4" /></b></p> </fieldset> <div align="center"><input type="submit" name="submit" value="Submit"/></div> </form> </body> </html> <html> <body> <?php $number1 = $_POST['number1']; $number2 = $_POST['number2']; $sum = $number1+$number2; if (!empty($number1)&& !empty($number2)) { if(!is_numeric($number1)) { echo "The value you entered for number 1 is not a number. Please enter a numeric value for number 1"; } else if(!is_numeric($number2)) { echo "The value you entered for number 2 is not a number. Please enter a numeric value for number 2"; } else { echo "The sum of the numbers is: ".$sum; } } ?> </body> </html> |