Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

syntax problem

Status
Not open for further replies.

jenodorf

Technical User
Jan 11, 2005
36
0
0
Hi really sorry to be so dense , but I'm trying to get my head around PHP and mysql.

I have a mysql database and need to calculate a total stock value and display it in a web page.

Searched the web, asked here and been through a couple of books but I'm struggling.

The code I'm trying to use is as follows:-

<?php
Select sum (SKU_price * SKU_stock) as totalStockValue from tbl_skus;
echo totalStockVale;
?>

I've inserted this into a PHP admin page which is already logged onto the database.

I thought that LIne one created a value for the total stock called totalStockValue and line two echoed the result to the screen.

Is my logoc totally wrong?

thanks

Ian
 
your first line is a sql statement, not a php function. you would need to do something like this instead

Code:
mysql_connect($host, $user, $pwd);
mysql_select_db($dbname);
$result = mysql_query('Select sum (SKU_price * SKU_stock) as totalStockValue from tbl_skus') or die(mysql_error());
$row = mysql_fetch_assoc($result);
echo "Total is ". $row['totalStockValue'];

obviously you will need to fill the first two lines with your own values for your database.
 
Thanks,

appreciate the help, I'll try it tomorrow.

Wish I could find a good reference guide on using php with mysql and HTML

I'm ok on HTML but the mysql bit is an uphill road

cheers

Ian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top