PHP - A Question About Float
Can someone clear up my confusion about FLOAT.
I have data in a TINYINT field that displays whole numbers WITHOUT any decimal places. This does not format very nicely when there are ALSO decimalled values to be echoed: 1 1.5 2 2.5, etc. It can be a little confusing. The only way I've thought of to resolve the issue (if you know another, please share) is to add a decimal place to get: 1.0 1.5 2.0 2.5 etc. But I am unclear on WHERE to put the commands to get this result. Does it go into the actual DB? Or into my PHP script? Please help with a detailed example. Thanks Similar TutorialsThis topic has been moved to CSS Help. http://www.phpfreaks.com/forums/index.php?topic=312178.0 The following returns strings instead of floats. Am I able to retrieve floats directly from PDO and/or PostgreSQL or must I manually type cast them afterwards using PHP? Thanks $sql='WITH RECURSIVE t AS (bla bla bla) SELECT id, CAST(SUM(slope*value+intercept) AS FLOAT) "value", SUM(slope*prev_value+intercept)::FLOAT "prevValue" FROM t WHERE type=\'physical\' GROUP BY id'; $stmt = $this->pdo->prepare($sql); $stmt->execute($ids); $arr = $stmt->fetchAll(\PDO::FETCH_UNIQUE); //returns [123=>['value'=>'123.456', 'prevValue'=>'122.234'], ...]
Hello, The data that actually gets stored in my database differs from what I'm trying to put there. Here's a short code snippet: $lat = 42.272939; $lng = -83.622941; // insert cordinates into dB $query = "INSERT INTO markers (lat, lng, user_id) VALUES ('$lat','$lng','$user_id')"; $results = mysql_query($query) or die(mysql_error()); When I look in the database, the data is stored as: 42.272938 and -83.622940. Any ideas as to why this happens? These values are being stored as float(10,6). Not sure if this is useful, but here's some other info: datbase: MySQL engine: InnoDB Format: Compact Collation: utf8_general_ci Thanks im trying to update a GPS table for example: UPDATE markers SET lat = '38.40907441955112' AND lng = '14.943452775478363' WHERE ApID = '35911' i tried with float 20,18 it isnt updatng correctly first person to solve this gets an automatic, irrevocable entry into my VIP Holiday Card Master List. ive been tussling with it for hours over two days and cannot figure out what the problem is.
site: http://104.152.168.18/~redtagsp/
you'll see five image buttons in the center of the homepage. red bg is for diagnostic only. the third of the smaller images in the top row is sitting slightly lower than the others. the containing element (transparent black) is floated as are all 5 images within it. and the text-div above the images. seems really simple but ive had these frigging elements bobbing all around and this is the best i can get them. my guess is there is some CSS outside of my own (this is a Wordpress site) that is screwing things up for me but i cant find it.
here is the HTML for the containing element:
<div id='home_buttons'> <div id='free_shipping'><strong>FREE</strong> Shipping on all orders over $40</div> <a href=''><img src='/~redtagsp/wp-content/themes/bmw_storefront_child/pics/buttons/button_blank_pucks.png' class='home_button_small'></a> <a href=''><img src='/~redtagsp/wp-content/themes/bmw_storefront_child/pics/buttons/button_custom_pucks.png' class='home_button_small'></a> <a href=''><img src='/~redtagsp/wp-content/themes/bmw_storefront_child/pics/buttons/button_custom_pucks.png' class='home_button_small'></a> <div style='float:left; clear:both; width:100%; height:5px;'></div> <a href='' class='link_button_large'><img src='/~redtagsp/wp-content/themes/bmw_storefront_child/pics/buttons/tape.png' class='home_button_large'></a> <a href='' class='link_button_large'><img src='/~redtagsp/wp-content/themes/bmw_storefront_child/pics/buttons/balls.png' class='home_button_large'></a> </div>here is the CSS directly associated with the above: #home_buttons { float:left; width:95.4%; padding:1%; margin:100px 1% 20px 1%; background:rgba(0, 1, 17, 0.75); border-radius:10px; } #free_shipping { float:left; width:100%; text-align:center; border-radius:5px; background:#555; color:#fff; margin-bottom:10px; } #home_buttons a { float:left !important; max-width:32.8%; margin:0 0.5% 0 0; padding:0px !important; background:red; clear:none !important; } .link_button_large { float:left !important; max-width:49% !important; margin:0px 2% 0px 0px; clear:none; } .link_button_large:last-of-type { margin:0px; } .home_button_small { float:left; max-width:100%; } .home_button_small:last-of-type { margin-right:0%; } I know I may sound like a nab, but here I go: Code: [Select] $ric=10; $price=$price+($price/$ric); Basically I want to add a 10% to the price value this is inside a "for", and price values is taken from a csv file. Said value is for example: $price=4,36 after the script takes place, the value goes to: $price=4796 While i aimed to obtain 4,80 (a 2 precision float). Can anyone help me? It's the first time I mess with float numbers. EDIT: Or at least direct me to a more efficient way to apply % on doubles, while preserving the original precision Hi, in Mysql have a row with FLOAT 10,2 In form put the number 20.20 and after reload in form show: 20.200000762939 when in a form, I wish to build a conditional that if the response to a radio button is a value of 2 (female), it will display an input requesting for users maiden name. If not 2 goes to the next input statement. Here is code I was experimenting with: <html> <body> <form action="" name="test" method='POST'> <input type="radio" id="sex" value=1 checked><label>Male</label> <input type="radio" id="sex" value=2><label>Femaleale</label> <?php $result = "value"; if ($result == 2) echo "<input type='int' id='gradYear' size='3' required>"; else echo "Not a female!" ?> <input type="submit" value="GO"> </form> </body> </html> The code passes debug, however, Not a Female is displayed. My question is - Can I do this and if so, what value do I test against id='sex' or value. I tried each one but gave the same results. I realize that $_POST[sex] would be used after the submit button is clicked. But this has me stumped. Thanks for the assis in advance. Hey, I have a while that shows the rows(duh). What i want to do is: show 3 rows then echo float left or clear both. So basically 3 at a time, but it shows all the rows in a nice order. Can someone do this? Cheers. Hello, i am currently working on a project and i have been on google and nothing has helped i am trying to detect characters in the URL so for example XSS if someone typed in the URL:
home.php?=<script>document.cookie();</script> OR home.php?=<?php echo file_get_contents("document.txt", "a");How would i be able to make a kind of firewall to detect this? and if it does then redirect to another page. Thanks. So I've been trying to work with OOP more lately and basically I have just some basic code. Code: [Select] class announce_manager { //I guess we'll start with setting the title. public function setTitle($title) { $this->title = $title; } public function getTitle() { return setTitle(); } } Anyway, say I set the title on a page called announce.php would it still be set on index.php? Probably not right? Is there a way to make the value I set carry over to another page without using sessions? example: announce.php Code: [Select] if(isset($_GET['annsubmit'])) { $title = $_GET['title']; $ann = new announce_manager(); $ann->setTitle($title); } index.php Code: [Select] echo getTitle(); <- make this equal to the value I set in announce, without using sessions. I'm just asking if this is possible. Hi there! So, I remember doing this correctly some time ago, but now I've forgotten how. I am try in to get it to echo out something if the results from mysql are empty. I can get it to return the results if there is something in the database, but it's not echoing out the message from the case statement. I can't remember how to get it to look for "nothing". Here's my php code: Code: [Select] <?php $sql = "select * from tbl_tribue where letter = '$_GET[letter]' order by letter asc"; $result = mysql_query($sql,$conn); while ($row = mysql_fetch_array($result)){ $petname = $row['petname']; $desc = $row['description']; $family = $row['familyname']; if ($row=="0") { echo "No pet tributes for the letter."; } else { echo <<<END <p><strong>$petname</strong><br /> $desc<br /> <em>- $family</em></p> END; } } ?> I am not sure if I have the if, else in the right place either. Any help is greatly appreciated. Thanks! U guys know in forums how at the top or bottom there links to the "1 2 3 4 5 next" and stuff? and how it loads a database? how would i do that exactly? or explain to me what it could be called. cause me i have no idea :/ Major breakthrough. utf8_encode() allows me to view utf-8 characters in the browser. Therefore, my source data file must be ISO-8859-1 encoded text, right? Am I understanding this correctly?
<?php //mb_internal_encoding("UTF-8"); header('Content-type: text/html; charset=utf-8'); $file = fopen('some_csv_file_created_by_excel.csv', "r"); ob_start(); while (($spec = fgetcsv($file, 100000, ",")) !== FALSE){ echo($spec[0].' '.utf8_encode($spec[0]).'<br>'); } $string=ob_get_clean(); ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>utf</title> </head> <body> <p><?php echo($string);?></p> </body> </html> Edited by NotionCommotion, 11 January 2015 - 08:22 PM. I'm creating a re classified ad site and I've hit a brick wall. I'm trying to create a 'listing' which will contain info and pictures of the property that's for sale, but I'm unsure on how to do it. Would I have to create different db tables to have the albums, images and listing together? Or would can I just do it all in one table? I appreciate your help. i am looking for a way to write a php script to pull information from a html table and put that information in to the databases does any one have any idea who to do this hello all, i am having a for each problem. im trying to get two post fields using the foreach function. here is what i have in my form.php: Code: [Select] <?php foreach($_POST['staff'] as $value) { echo "$value - <br />"; } ?> the name of the the fields coming in are Code: [Select] name='staff[]' and the second one is name='descr[]' fields += 1; Is it posible to put a submit button somewhere out of a form and still use that submit button with the form? hi php people, I am wondering will if the code below will work when I call $C->getafoo() will I get foo; I keep getting an error at this point return $this->A->a(); saying the method is not there Code: [Select] class A{ public function a(){ return "foo"; } } class B { public $A; function __construct($A) { $this->A = $A; } public function geta(){ return $this->A->a(); } } class C extends B{ public function getafoo(){ return geta(); } } $C = new C(new A()); echo $C->getafoo(); Howdy, I have a question about Dates in PHP 5.3.6. I queried my database (SQL Server 2008) and I got back two columns, a date(StartDate) and a time(StartTime). The software we used only allows the user to enter a StartDate, so that field always has a value, but there are instances where the StartTime is null (no time set). What I want to do is if there is a StartTime, concat it to the StartDate. If there is not StartTime, I want to add a default time. But when I do that, I get an error saying that I cannot combine a string and a date. I really do not understand why this is happening. I set up PHP 5.3.6 on a server, so I am not sure if there something in the php.ini file that is not allowing me or if this is something new. Some help please! Thanks Code: [Select] if( $row['StartTime'] != null ) $sTime = $row['StartDate'] . " " . $row['StartTime']; //What I want '2011-05-03 17:58:12.000' else $sTime = $row['STartDate'] . " 00:00:00.000"; //What I want '2011-05-03 00:00:000' |