By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,051 Members | 1,198 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,051 IT Pros & Developers. It's quick & easy.

How to display a value of $var in php script

P: n/a
I am trying to display a calculated value through echo/print/write in
php script, but it didn't work. What is the right syntax to display a
$var?

I processed

$sql2 = "select sum(unitprice) from book b, staging s where
b.isbn=s.isbn1 or b.isbn=s.isbn2";
$sql_result2 = mysql_query($sql2,$connection) or die ('We are unable
to process your request right now. Please try again later.');

Then, I tried to display result as follows
echo(' ');
echo(' Thank you for your order. You total is $ ');
print("$sql_result2");
echo('.');
echo(' Your books will be shipped to you within 24 hours.');
echo(' ');
echo(' ');

and

echo(' ');
echo(' Thank you for your order. You total is $ ');
write("$sql_result2");
echo('.');
echo(' Your books will be shipped to you within 24 hours.');
echo(' ');
echo(' ');

Any help will be appreciated!
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
While thinking about how cool Corey Feldman was, xo55ox blurted:

$sql2 = "select sum(unitprice) from book b, staging s where
b.isbn=s.isbn1 or b.isbn=s.isbn2";
$sql_result2 = mysql_query($sql2,$connection)

echo(' Thank you for your order. You total is $ ');
print("$sql_result2");


This is not going to do what you want it to do because $sql_result2
contains an sql result resource rather than the actual sum. You must
first get the record from that sql result, and then get the value
from the appropriate field in that record. Try something like this:

$q = mysql_query("SELECT SUM(unitprice) AS sum
FROM book AS b,staging AS s
WHERE b.isbn=s.isbn1 OR b.isbn=s.isbn2",
$connection);
if(!mysql_num_rows($q))
die "No record";
$rec = mysql_fetch_assoc($q);
echo "The sum is $rec[sum]\n";

Hope this is useful.

/joe
--
In git.talk.phatjoe, the smelly cable line from Sheetal will go to Mo.
Joseph jeong cleverly demonstrates how to make an ass of oneself in front
of Sixth Street for the fiber channel, and then repartitions 102, the emo
house, and the dripping muff and creates a website about... [tape runs out]
Jul 17 '05 #2

P: n/a
Joe,

Thank you very much for the information. But I am still stuck at the
if(!mysql_num_rows($q))
die "No record"; <----- This row for some unknown reasons.

I got this error message.
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in
/home/xo55ox/public_html/insertcustomer.php on line 15

Help please!
Thanks in advance.

xo****@hotmail.com (xo55ox) wrote in message news:<ab**************************@posting.google. com>...
I am trying to display a calculated value through echo/print/write in
php script, but it didn't work. What is the right syntax to display a
$var?

I processed

$sql2 = "select sum(unitprice) from book b, staging s where
b.isbn=s.isbn1 or b.isbn=s.isbn2";
$sql_result2 = mysql_query($sql2,$connection) or die ('We are unable
to process your request right now. Please try again later.');

Then, I tried to display result as follows
echo(' ');
echo(' Thank you for your order. You total is $ ');
print("$sql_result2");
echo('.');
echo(' Your books will be shipped to you within 24 hours.');
echo(' ');
echo(' ');

and

echo(' ');
echo(' Thank you for your order. You total is $ ');
write("$sql_result2");
echo('.');
echo(' Your books will be shipped to you within 24 hours.');
echo(' ');
echo(' ');

Any help will be appreciated!

Jul 17 '05 #3

P: n/a
xo55ox (42.254% quality rating):

Thank you very much for the information. But I am still stuck at the
if(!mysql_num_rows($q))
die "No record"; <----- This row for some unknown reasons.


It's because I'm an idiot, and die is a function.

It needs to be:

die("No record");

/joe
--
Leila Abdi carefully flames the beer fridge, and then demonstrates how to
make an ass of oneself in front of Cherry St.! The self-referential rectum
from the phatmobile will go to Bwooce. Otter verily disses the emo house
for the klutch verdutch optimizer. Ryoko bellows "It is ... [tape runs out]
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.