Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 06-08-2005, 02:38 PM php help
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
i doing this test code and it not working i think i done somthink wrong in the print section near the each buton as in my editor all the txt is in black except the each so im guessing i got a colon or somethink in wrong place

<?php
#script 1.9 -numbers.php
//set the variables

$quantity=30;//buying 30
$price=119.95;//$119.95
$taxrate=.05;//5%

//calculate the total.
$total=$quanty * $price;
$total=$total +($total * $taxrate);//add tax
$total=number_format($total,2);//format the results

//print the results
echo @you are purchasing <b>',$quantity, '</b>widget(s) at a cost of <b>$',$price, '</b>
each. with tx, the total comes to <b>$', $total, '</b>.';




?>
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
 
Register now for full access!
Old 06-08-2005, 03:57 PM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
You need to surround your echo with double quotes so PHP will know to resolve the variables within the double-quoted string:

PHP Code:
echo "You are purchasing <b>$quantity</b> widgets at a cost of <b> $ $price</b> each.  With tax, the total comes to <b>$ $total.</b>"
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 06-08-2005, 03:57 PM
Uche's Avatar
Extreme Talker

Posts: 174
Location: Nigeria/Lagos
Trades: 0
what error did you get ??? try this

//print the results

echo "you are purchasing"; <br/>',$quantity, '<br/>widget(s) at a cost of <br/>$',$price, '<br/>
each "with tx, the total comes"; to <br/>$', $total, '<br/>.';
__________________
Life is just lyke a school where everybody goes to learn one or two thing. the more u school, the more u learn more about school..The more we live our lifes.. the more we learn more about life.

Please login or register to view this content. Registration is FREE
Uche is offline
Reply With Quote
View Public Profile Visit Uche's homepage!
 
Old 06-08-2005, 04:01 PM
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
also i have sorted frsit problem next one

$total=$total +($total * $taxrate);//add tax

the code is not working out the total as in this what i get when i run script

You are purchasing 30 widget(s) at a cost of $119.95 each. With tax, the total comes to $0.00.
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 06-08-2005, 04:03 PM
Uche's Avatar
Extreme Talker

Posts: 174
Location: Nigeria/Lagos
Trades: 0
is ur print working now ??
__________________
Life is just lyke a school where everybody goes to learn one or two thing. the more u school, the more u learn more about school..The more we live our lifes.. the more we learn more about life.

Please login or register to view this content. Registration is FREE
Uche is offline
Reply With Quote
View Public Profile Visit Uche's homepage!
 
Old 06-08-2005, 04:08 PM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
That is because you are reassigning $total with your format_number call. Use a different variable there and print it there. Remember that number_format returns a STRING whereas before it was a double.
PHP Code:
$totalAmt number_format$total);
echo 
"You are purchasing <b>$quantity</b> widgets at a cost of <b> $ $price</b> each.  With tax, the total comes to <b>$ $totalAmt.</b>"
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 06-08-2005, 05:37 PM
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
ok cool wht the difference between variables and constants i mean a variable is $name and a constant is NAME but dont they do the same sort thing
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 06-08-2005, 05:49 PM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
Variables are meant to change. Say you are adding up 10 numbers and keep a running total. The total will change as you add -- thus $total would be appropriate.

Constants are not meant to change. An example might be PI. define( "PI", 3.14); The value of PI cannot be changed and can be referred to in such a manner.
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 06-08-2005, 05:51 PM
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
ah i see so variables can be changed depening on the code


where constants will not change as they be a fixed value
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 06-09-2005, 11:38 AM
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
so what sort of time would i use a constants as i dont really see the point in it i understand it a fixed value but surley this variable is the same as this constant

<?php
$date=8 th june 2005;

echo'today date is $date.';
?>

<?php

define =('DATE' ,'8 th june 2005');
?>
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 06-09-2005, 11:54 AM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
A defined constant is very useful, perhaps if you want to present repetitive text to a user. It can be defined in an include file then used in all your PHP scripts. Another example would be if you have a database application and you only want to present 50 records per page. Your scripts could use such a constant in multiple places. The security of a constant is that it is immutable -- it cannot be changed.

In your question earlier, you would want to surround $date's values in quotes, by the way. But the reason you would use a variable versus a constant is whether or not you would need the value to ever change.

Another example I can think of is that I always define my email address as a constant so that the contact form scripts can use that constant when sending the email to me after a visitor has fileld out a feedback form.
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 06-10-2005, 04:48 AM
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
hi im just learing where to place the quotes and just had a question really the book say to type this

echo "you are purchasing <b>$quantity</b>widget(s) at a cost of <b>\$$price</b>
each. with tax, the total comes to <b>\$$total </b>.";


1 question i typed this code and it works fine

echo "you are purchasing <b>$quantity</b>widget(s) at a cost of <b>$$price</b>
each. with tax, the total comes to <b>$$total </b>.";

so what are the backslashes for what the point of them if the code works fine without them
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 06-10-2005, 06:23 AM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
The dollar sign in PHP indicates that the string immediately following it is a variable. $total is a variable, for example. The backslash communicates to the PHP processing engine that the next character should be taken literally, that is to say that it has absolutely no programmatic significance -- that it should be treated just as a character, just a dollar sign.

The reason that it may work well without it is because the processing engine does have some intelligence about figuring such things out. My guess is that it knows when two dollar signs appear together that the first one is a literal and the second one may be the beginning of a variable. However, don't rely on such things. You are safer and it is considered better programmatic style to use the escape characters where it is necessary and appropriate.
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 06-10-2005, 06:25 AM
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
cool thanks im sur3e i have some more question soon thank for all your help kyrnt
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 06-11-2005, 01:26 PM
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
hi learing about the $var=stripsslashes($var); commaned in php is this a good code to add all my scripts i build

also where would i use the $var = trim ($var); command what is this good i undersntad it to trim the white spaces but where

Last edited by millwalll; 06-11-2005 at 02:09 PM..
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 06-12-2005, 09:17 AM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
You may want to use trim() if you want to be sure that you have a String with no spaces at either end. This would be useful if you want to compare a user-input field to some value. For example, if you want to know whenever a user types "Chicken" into a particular form field, you want to trim the user's input before you perform the check, because any stray spaces at the end would throw off the comparison.
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 06-12-2005, 09:30 AM
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
oh i see so if i want to look for chicken and they entered it as spacechickenspace then i woudl use the trim to get ride of the two spaces
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 06-16-2005, 05:34 AM
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
need help with this code this bit of code the [] why is this after interests does this tell php this is the key or somethink why would i need to put this in there


<p><b>Interests:</b><input type="checkbox" name="interests[]" value="Music" />Music</p>


also what does this do ($_POST['name']); does this code say if the name variable is less than 0 i.e null the print the name variable and you forgot to enter your name where this is ($_POST['name']); is this wrong and is meant to be $name

if (srelen($_POST['name'])>0){
$name =stripsslashes
($_POST['name']);
} else {
$name="null";
echo '<p><b>You forgot to enter your name!</b></p>';




hi i need help with this im just total confussed with this code from the point a to b


<?php
# script 2.11 -handle_about.php

if (srelen($_POST['name'])>0){
$name =stripsslashes
($_POST['name']);
} else {
$name="null";
echo '<p><b>You forgot to enter your name!</b></p>';
}
if (isset($_POST['interests'])){ dont understand from this point A
$ints = NULL;
foreach($_POST['interests']as $key =>$value){
$ints .= "$value, ";
}
$ints = substr($ints, 0, -2);
$interests = true;
}else{
$interests =NULL;
echp '<p><b> you forgot to enter your interests!</b></p>'; to this point here B
}
if ($name && $interests){
echo "thank you, <b>$name</b>.
you entered your interests as:<br /><tt>$ints</tt></p>";
}

?>
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 06-16-2005, 07:55 AM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
$_POST['name'] refers to a post variable, ie something that has been submitted from a form. The form control (probably a text field) will have name="name" in the html source. You can use $name instead, but only if register globals is on, and it's generally a good idea not to.

The checkboxes with the name "interests[]" are named that way because it wants them treated as an array. This way instead of calling them interests1 interest2 interests3 etc and then having to hunt for variable names in your php, you name all the checkboxes interests[], and when you submit the form, all the checkboxes get submitted in one array called $interests, with only the elements set that were checked.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 06-16-2005, 08:19 AM
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
ok so if i hade a list of hobbies i would do the code below and it would tell to treat them all as a $hobbies

<p><b>Interests:</b><input type="checkbox" name="hobbies[]" value="games" />games</p>
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Reply     « Reply to php help

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.75358 seconds with 12 queries