Decimal numbers PHP/MySQL
HelloI'm working on a real estate site. Most monthly apartment rental rates are round numbers like $950, however a few have odd prices like $1070,76 (where the need for decimal data type in MySQL).
On the page where are all the apartment ads, what I want to do is to remove the decimal point and zeroes if the number is round because all zeros are distracting (and useless). For example:
I have this code snippet:
If ($r-> maxRent == 0) {}
$price = ' requested rent $';
$price. = $r-> minRent;
$price. = "monthly";
} else {}
$price = ' requested rent $';
$price. = $r-> minRent;
$price. = '-';
$price. = $r-> maxRent;
$price. = "monthly";
}
Which shows this:
Ask the rent 810, 00-950, 00 per month
1070.76 rental request - $1200.00 per month
Asking rent $1335,00 per month
But I want things to be displayed like this:
Rental $810-950 per month
1070.76 rental request-$1200 per month
Rental $1335 per month
What I have to do it work with regular expressions (Voodoo!) or is there another way? I am currently in a situation where I have to use outdated versions instead of all (PHP 4.1.2 / MySQL 3.23) if that makes a difference in this case.
I looked through my books and I tried Googling & forums for an answer to the search, but I'm not sure of exactly what I should look for, so I won't have a bit of luck. Any help would be greatly appreicated.
Kind regards
Bev
bsoliman wrote:
> But I want things to be displayed like this:
> Asking rent $810-950 per month
> Asking for rent 1070.76-$1200 per month
> Asking for rent $1335 per month
In fact, le.76 seems to me more confused than la.00. I'd do it
Just use round() to give a round for all rents figure. However, if
you want to do it your way, add this function to your script:
function checkEven ($val) {}
return preg_match ("/ \d+\.00 /', $val")? number_format ($val, 0):
number_format ($val, 2);
}
Then change your code to do this:
If ($r-> maxRent == 0) {}
$price = ' requested rent $';
$price. = checkEven ($r-> minRent);
$price. = "monthly";
} else {}
$price = ' requested rent $';
$price. = checkEven ($r-> minRent);
$price. = '-';
$price. = checkEven ($r-> maxRent);
$price. = "monthly";
}
--
Adobe Community Expert David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Tags: Dreamweaver
Similar Questions
-
I want to use numbers from a database, prices. In the database (PHP/MySQL), the structure is ' decimal (9.2). If I put it out with PHP a number as is €9.02 9,02 but 9.20 looks like this €9,2. How can I set prices with PHP/MySQL?
I hope that my question is simple... Thankx for any other help.
Use number_format() functionof PHP.
-
help with php mysql connect script
OK guys im new to php mysql and I try inserting form information in my database. IM using a sitepoint script in which I went through the tutorial made some experiences of myself and it worked...
but now I get this error that I can't understand...
Command error: you have an error in your syntax SQL; consult the manual corresponding to your version of the server MySQL for the right syntax to use near 'order product SET = ' 1', 'average' = size, color is ", amount = '1' at line 1
Here is the page
http://vaughntucker.com/imagecon/hats.php
and this is the script
<? PHP
default page view
connect to the database
$dbcnx = @mysql_connect ('p3nl41mysql7.secureserver .net', 'imagecon', ' Dub * boss_1');
If (! $dbcnx) {}
echo "< p > unable to connect to the '. 'database server at this time." < /p > ";
Exit();
}
Select database
If (! @mysql_select_db ('imagecon')) {}
exit (' < p > cannot locate the ".")
"database at this time. < /p >");
}
MySQL Query add joke
If (isset($_POST['submit'])) {}
$product = 1;
$size = $_POST ["size"];
$color = $_POST ['color'];
$quan = $_POST ['quantity'];
$sql = "INSERT INTO command TOGETHER
product = "$product."
size = "$size."
Color = "$color"
quantity = "$quan"
Date = CURDATE () ';
} else {}
ECHO 'no data sent ";
}
If (@mysql_query ($sql)) {}
echo "< p > your order has been sent. < /p > ";
} else {}
echo ' error < p > order process: '.
mysql_error(). / '< p > ';
}
? >
Thanks in advanceMurray * ACE * has written:
> $sql = "INSERT INTO command TOGETHER."
"> product ='". $product. "',
"> size ='". $size. "',
"> color ='". $color. "',
' > quantity = ' ". $quan. "',No, this is not what is causing the problem. It is the use of 'order' as
the name of the table. The order is an SQL reserved word. Either the name of the table
should be changed, or the query INSERT rewritten as follows:$size = mysql_real_escape_string($_POST['size']);
$color = mysql_real_escape_string($_POST['color']);
$quan = mysql_real_escape_string($_POST['quantity']);
$sql = 'INSERT INTO 'order' SET
product = 1,.
size = "$size."
Color = "$color"
quantity = $quan,
'date' = CURDATE () ';Note that I surrounded order and date with backticks. I also have
$product, was deleted because it has a fixed value. I removed the quotes from
around $quan, because the numbers should not be quoted in SQL queries.The changes I did assume that magic quotes are disabled the
Server. If they are on, you must also pass the variables $_POST
stripslashes() like this:$size = mysql_real_escape_string (stripslashes($_POST['size']));
$color = mysql_real_escape_string (stripslashes($_POST['color']));
$quan = mysql_real_escape_string (stripslashes($_POST['quantity']);--
Adobe Community Expert David Powers
Author, "The Essential Guide to Dreamweaver CS4",
"PHP Solutions" & "PHP Object-Oriented Solutions.
http://foundationphp.com/ -
Regex to allow only integer and decimal numbers.
Hi all
I need a regex to allow only integers and decimal numbers.
Examples:
100 licences
100.00 - Unauthorized
100 - unauthorized
100.11.22 - unauthorized
all characters other than numbers - unauthorized
I used the regular expression - ^ [0-9] +. ? [0-9] * $- but its allowing the "100" also.
Can someone help me solve this problem.
Your timely assistance is greatly appreciated.
Thanks in advance.
Hello
inDiscover wrote:
Hi all
I need a regex to allow only integers and decimal numbers.
Examples:
100 licences
100.00 - Unauthorized
100 - unauthorized
100.11.22 - unauthorized
all characters other than numbers - unauthorized
I used the regular expression - ^ [0-9] +. ? [0-9] * $- but its allowing the "100" also.
Can someone help me solve this problem.
Your timely assistance is greatly appreciated.
Thanks in advance.
Use
^[0-9]+(\.[ 0-9] +) ? $
to make the decimal point and the following figures (of which there must be at least 1), as a unit, as an option.
-
I need some tutorials Ajax, PHP, Mysqli?
Hello world
I need tutorials on the following
(1) I have a div that is connected to a database, it displays information x I want to do a picture-button that refreshes this div in a click.
(2) I have 3 different pictures (thumbnails) on a page that each represents its own category of pictures, I want each image to do ' when one of the 3 images is presset, there should be a fade by displaying images (10, etc.) associated with this category (perhaps of an include statement?). under the 3 photos, if you press one of the 3 images current images in the 3 images has to falter and new photos (22 photos etc.) melted, does make sense? .
If anyone has some good tutorials that is not impossible to understand due to the mic/accent, I'd be more than happy!
OMFG... I just think that I found the magic for the first jewel, if someone need to solve one that I found this
http://StackOverflow.com/questions/17438243/AJAX-update-div-tag-on-button-click
N ° 1)
"I just removed the"
setTimeout('Ajax()',2000);" both places.
Step 2)
Made the small script php/mysqli one inclusionStep 3)
Changed to this-->> >
xmlHttp.open("GET","refresh.php",true);
xmlHttp.send(null);<<<-- to this -->>xmlHttp.open("GET","Includes/frontpage/featured.php",true);
xmlHttp.send (null);<>
Step 4)
Added this onclick = "Ajax (); "to my tag
-
Align decimal numbers for the track list
Hello, you showed me how do it long ago and have forgotten since. I have a Tracklisting of a paragraph as follows:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
I followed the tabs tut in the CC tut who says line right to the top of the box of the tab with the text block, click align decimal numbers and click where you want to go, I get the orange arrow, but nothing aligns. The UTU uses a table for example, is the only way it will work?
Kind regards.
If you do just a numbered list, you only need to use tabs to align on the decimal point. Simply insert a fixed space called a figure space.
Make sure your numbers are of equal width. Since the character or control panel menu > OpenType, make sure Tabular Lining is set for numbers:
Then in front of 1, 2, etc. Insert a space figure (Type > insert a space > Figure space). White space is the width of any character. You can use several spaces figure if you were with a very large number.
-
Bug of STROKE Weird Illustrator containing decimal numbers
Hello
I m having this really weird in Illustrator bug when I try to change the size of the stroke to something with decimal numbers. When I have a call 1 pt or pt 2 it works as expected, but when I change it to something like 1.6 pt, the trait is uneven on the way. Some lines are thicker than others, and it's very weird.
Can someone point me in the right direction? See my 30 sec video-screen for an overview of the bug.
Thanks for your help in advance!
sure it is an alignment at pixel grid.
Select the object and check the transform palette. 'show options' in the menu if the option is not visible.
-
Calculation of tabular form, problem with decimal numbers
Hello
I wrote a simple java script function that is responsible for calculating the price * quantity and store that value to total_price.
function CalcTotalPrice (pThis)
{
var vRow = pThis.id.substr (pThis.id.indexOf ('_') + 1);
html_GetElement ('f07_' + vRow). Value = parseInt (html_GetElement('f06_'+vRow).value, 10) * parseInt (html_GetElement('f05_'+vRow).value, 10);
}
The function calculation is correct, but I have problem when the price or quantity decimal numbers.
For example.
Currently:
price * quantity = total_price
7.5 * 1 = 7 instead of * cf. 7.5 *.
I've already put a mask of correct format for all of these areas (999G999G999G999G990D00).
I appreciate your help.
Request Express 4.2.1.00.08
Oracle Database 11g Express Edition Release 11.2.0.2.0
Kind regardsHi John,.
before the multiplication, you analyze your values as an integer, so 'cut' the decimals.
Replace "parseInt" by "parseFloat" should do the trick.function CalcTotalPrice(pThis) { var vRow = pThis.id.substr(pThis.id.indexOf('_')+1); html_GetElement('f07_'+vRow).value = parseFloat(html_GetElement('f06_'+vRow).value, 10) * parseFloat(html_GetElement('f05_'+vRow).value, 10); }
Please let me know if this worked for you.
Thank you
Sandro -
Unable to connect error 404 PHP/MySQL
Wow, the learning curve is killing me. Yet another challenge. I use Dreamweaver CC and this tutorial http://www.adobe.com/devnet/dreamweaver/articles/setup_php.html
I'm at this stage:
- Open comments.php . You must have a PHP page open in the Document window to create a MySQL connection.
- In the databases Panel (choose window > databases), click on the sign located on the Panel and select MySQL Connection.The MySQL connection dialog box appears.
- Type connTest as login name.
- For the MySQL server, type localhost. If you use MAMP ports by default on a Mac, use localhost:8889.
- For the user name, type phptestuser.
- Type the password that you chose for the phptestuser account in the password field.
- To the database, type php_test. Note: You need not precede the underscore with a backslash character here. It was inserted by phpMyAdmin in the previous section (see Figure 20) only because phpMyAdmin uses a query which allows wildcards.
- Click on Test.Dreamweaver tries to connect to the database. If the connection fails, follow these steps:
- Check the server name, user name, and password.
- Check the settings in the file that Dreamweaver uses to process dynamic pages (see specification of a Dreamweaver testing server).
- Ensure that the web and MySQL server are both running.
- Temporarily disable any firewall or security program. If the connection works, you must configure the security program to allow communication between Dreamweaver and MySQL.
- Click OK. The new connection appears in the data Panel.
- Expand connTest connection, and then expand the Tables branch. You will see the comments table in the database, you can expand to reveal the details of the columns in the table (see Figure 23).
I can say that I followed this tutorial to the letter.
As far as I know, XAMPP/php mySQL all running very well, the files are in the right place and everything should work. However when I type test, I get a 404 error. (Same error when I hit the select button).
The problems on the 404 message are:
1. There is no server running on the server test.
Sure the testing server is running. Is there a way to test this, another that note that xampp is certainly running right now and I can connect to phpMYadmin without problem?
2 test specified for this site server is not mapped with the http://localhost/php_test/_MMServerScripts/MMHTTPDB.php URL check that the URL prefix maps to the root of the site.
UH... I'm sure that I put things where I was told to put them in the tutorial, but I'm lost right now where I should check that. A clue here? The files are where they are supposed to be, but maybe I entered something wrong? Except... I don't know what it might be or where to find it. Whatever IT is.
Everything in the local files is fine.
Thanks for your help!
PS: Extra points to anyone who figures how to make copy/pasteable error messages! These guys are the bane of my life!
Stop and restart the services he. Stop Xampp if still the same behavior. It should look like as below
-
PHP/MySQL relational database
Hello
I'm pretty new to php/MySQL. I'm stuck on how to make a cross-connection database.
I have two tables 'users' and 'comments' and wants to set up a page that a user can see and edit the comments they made.
So far, I tried to do an advanced Recordset, but all I managed to do is to display all records that share a user_id.
I use dreamweaver CS5.5 and PHP and MySQL.
Thanks in advance for your help
Eddie
This should be just a base query SELECT * FROM {comment-tbl} WHERE userid = $_SESSION ['user'].
Do you use Cookies or Sessions at this point or you're simply trying to write this in a query without them?
-
Code PHP/mySQL help please
Hi all
Thanks to David Powers fab tutorial I am now well on my way to my first dynamic website with PHP/mySQL competeing, (thanks to David ), but I'm stuck on one particular area... can someone please help?
I know that the mySQL database using the YYYY/MM/DD format for dates, and that's fine. I set how to display in a format more regular (for example, September 1, 2011) for my application, but I'm stuck on how to convert a more regular formatting date is entered by the user of the site to mySQL format.
Ideally I would like to enter users or tell the 09/01/11 or 09/01/11 (or something in that sense, to be recognized and displayed on the registration form, but to have a back-end service that converts the data to the format mySQL. I think I'm reading a lot of posts forum who say that this is possible, but unfortunately I can't quite understand how or where the code should sit. Someone would have is not afraid to take a look at my page of codes to identify actually what I need to insert and also as important... where!
Is it possible to have a miniature calendar date picker that can be built next to the entry field in the right format and date to make sure that a valid date is entered along these lines? Where this could be extracted?
Thanks for help if necessary
Mark
GetSQLValueString (date('Y-m-d'), strtotime($_POST['date']), 'day'),
Make this line looks like this-
GetSQLValueString (date ('Y-m-in, strtotime($_POST['date'])), 'day'),
This was my mistake - sorry. The MySQL data type DATE should be in YYYY-MM-DD format. If this is the data type of this field "date", and then copy the following code should work.
-
Insert a special character such as apostrophes with PHP/Mysql
Hi friends,
I have a problem with php/mysql. I created a form vach'inton a page php with dreamweaver and when I try to fill in the form with a string that contains an apostrophe ('), I got an error. It seems that integration is not possible. Would you have any idea for that. I give you the code of dreamweaver php and thank you for your help.
<? php require_once('Connections/Mainconnect.php');? >
<? php require_once('Zend/Date.php');? >
<? PHP
If (! function_exists ("GetSQLValueString")) {}
function GetSQLValueString ($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
If (via PHP_VERSION < 6) {}
$theValue = get_magic_quotes_gpc()? stripslashes ($TheValue): $theValue;
}
$theValue = function_exists ("mysql_real_escape_string")? mysql_real_escape_string ($TheValue): mysql_escape_string ($theValue);
Switch ($theType) {}
case 'text ':
$theValue = ($theValue! = "")? « " ». $theValue. "" "": "NULL";
break;
case "long":
case "int":
$theValue = ($theValue! = "")? intval ($TheValue): 'NULL ';
break;
case "double":
$theValue = ($theValue! = "")? doubleVal ($TheValue): 'NULL ';
break;
case "date":
If ($theValue =="")
{
$theValue = "NULL";
}
on the other
{
$zendDate = new Zend_Date($theValue,"dd/MM/yyyy");
$theValue = "" "." $zendDate-> toString("yyyy-MM-dd"). »" « ;"
}
break;
case "set":
$theValue = ($theValue! = "")? $theDefinedValue: $theNotDefinedValue;
break;
}
Return $theValue;
}
}
$editFormAction = $_SERVER ['PHP_SELF'];
If (isset {}
$editFormAction. = « ? ». htmlentities($_SERVER['QUERY_STRING']);
}
If ((isset($_POST["MM_update"])) & & ($_POST ["MM_update"] == "form1")) {}
$updateSQL = sprintf ("UPDATE pers_soc_reg SET Field1 = %s, Field2 = %s,
GetSQLValueString ($_POST ["field1"], "text").
GetSQLValueString ($_POST ["Field2"], "double"));
Hello friends,
I solved the problem.
The problem is a free extension for dreamweaver called 'check new items' of Felixone. After his retirement, all forms of work without problem.
Thanks to you all.
-
Horizontal/vertical repeat region PhP/MySQL
Hi guys,.
I'm sure that this issue would have been requested many times before. If so, my apologies for the re - this announcement first.
In any case, what I'm trying to do is create a repeat region that spans 4 columns and then repeat the rest in rows. For example, if I have 100 records in my table (MySQL), so I want to display in a table of 4 columns and 25 rows and (in reality, the number of records would be indeterminate, of course, but still records must be displayed on a 4 X line table column). For example:
name
Comment
name
Comment
name
Comment
name
Comment
name
Comment
name
Comment
name
Comment
name
Comment
name
Comment
name
Comment
name
Comment
name
Comment
name
Comment
name
Comment
name
Comment
name
Comment
name
Comment
name
Comment
name
Comment
name
Comment
For the moment, I have no problem with displaying the records vertically or horizontally (explicitly) by using the behavior 'repeat region. However, when I have the problem is with displaying records in a table like the one I described above.
I use PS CS5 with PhP/MySQL.
Can I still do this in server behavior "repeat region", using the If yes how?
Otherwise, if not, how could I achieve this (ideally without using extensions)?
Thanks in advance for any help and support,
See you soon
The Horizontal Looper to Tom Muck is perhaps something for you:
-
AS3 / PHP / MySQL - login form
Hello
I am creating the simplest example I can an AS3/PHP/MySQL interaction. I want a Flash animation to check login/pass a user against a database. I tested the PHP code and know that it is correct. The problem must lie in his. I traced everything to make sure that it shuts down correctly, but it is up under the names of variable $user, $passer... and some of the other garbage... not the values of the variables I wait... see below.
The PHP code returns correctly what follows when tested in the browser: user = dan & pass = danpass & err = success!
The variable traces $user, $pass, $err return the following Flash:
undefined
$pass
$err ';
echo $returnString;
}
? >
The following ActionScript code:
import flash.events. *;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLVariables;
import flash.net.URLRequestMethod;
logbtn.addEventListener (MouseEvent.CLICK, login)
function login ($e:MouseEvent) {}
var myVariables:URLVariables = new URLVariables();
var myRequest:URLRequest = new URLRequest ("login.php");
myRequest.method = URLRequestMethod.POST;
myRequest.data = myVariables;
var myLoader:URLLoader = new URLLoader;
myLoader.dataFormat = pouvez;
myLoader.addEventListener (Event.COMPLETE, completeHandler);
myVariables.user = loguser.text;
myVariables.pass = logpass.text;
myLoader.load (myRequest);
function completeHandler(event:Event):void {}
trace (Event.Target.Data.User);
trace (Event.Target.Data.Pass);
trace (Event.Target.Data.Err);
}
}
And here is the PHP:
<? PHP
include_once "dbconnect.php";
$user = $_POST ['user'];
$pass = $_POST ['pass'];
$sql = mysql_query ("SELECT * FROM users WHERE user = ' $user ' AND pass = '$pass'");
$check = mysql_num_rows ($sql);
If ($check > 0) {}
$row = mysql_fetch_array ($sql);
$user is $row ['user'];.
$pass is $row ['pass'];.
$err = ' Success! ';
$returnString = "user = $user & pass = $pass & err = $err;
echo $returnString;
}
? >
Nothing stands out as incorrect? I went on that for probably 10 or 15 hours trying different variations, tweaks and reduce complexity. Really, I'd appreciate any help you can offer! Thank you.
-Eric
Hello
you load the php file in the same folder, or localhost (running the SWF in a browser)?
If being run from localhost, your system could deliver rather than run php scripts
-
Best way to update the images using PHP / MySQL?
Hello
I want to update the images using PHP/MySQL, so users can update their images and maybe a few others, but especially images.
Thank youHi, you can try this "How update an image in mysql"
Maybe you are looking for
-
I have nothing to add to the question.
-
My Sony Dash will connect is more to the internet, although he did for a year or two
Is no longer, my dashboard will connect to the internet. I tried all the recommendations for the resetting, etc. and even disabled my firewall, but nothing will work. Any ideas?
-
Code 80072EFE ALSO IT ME LEAVES DO NOT updated EVEN IN TROUBLESHOOTING
Remember - this is a public forum so never post private information such as numbers of mail or telephone! Ideas: Code 80072EFE ALSO IT ME LEAVES DO NOT updated EVEN IN TROUBLESHOOTING
-
What region DVD can read my laptop?
I have a laptop HP Pavilion G62-456TU (with Windows 7 Home Premium OS), that I bought new in early 2011. There is a DVD that interest me, for sale from abroad (UK). -Since the program has not yet been published on DVD in Australia. But first I want t
-
Starting message questions...
I have a Pavilion ZE4901US laptop, using XP home. On startup, I get the message "missing or corrupt \system32\ntoskrnl.exe please reinstall a copy of the above file. I went to "F10" on a start, did a "disk hard self test", and the result was "#1-07