James, if you could mark the thread as resolved, that would be great! (Any future questions could easily fit their own thread)
Thank-you, Kyle
James, if you could mark the thread as resolved, that would be great! (Any future questions could easily fit their own thread)
Thank-you, Kyle
Ah, not quite as familiar with linux specific email details. However - if it is your own server, you'll probably want to setup sendmail (apt-get install sendmail
). The settings are INI settings, they can be set at run time, or directly in the php.ini file. To find what settings are currently in place, add a new .php file to your web server and add this line to it: <?php phpinfo(); ?>
. You'll be able to pull this up in the browser to see your current settings and the .INI location.
Additionally, based on the mail() documentation and possibly more relevant to your code example; what do you get by checking the return of calling 'mail'?
$wasAcceptedForDelivery = mail(...);
if (!$wasAcceptedForDelivery)
{
die("<span class='failure'><h3>Sorry, Server not configured for e-mail.</h3></span>");
}
You are correct in your suspicion, you do need an SMTP server. If you are running in a Windows environment, the 'mail' function might use a built in Windows SMTP (which might need to be configured).
Here is the PHP documentation.
More specifically, the runtime configuration
Also, are you getting any specific error message? If not, what is your output? Do you have any PHP Ini settings for mail?
Hey Douglas,
I was wondering if this request is at a point of resolution. I understand there may be more (specific) questions.
It is always possible to reference this thread in future questions related to this topic as well.
Thank-you,
Kyle
Just an FYI: str_replace is much more efficient then preg_replace. It's like using a bulldozer vs. a shovel.
(Also, please mark as solved, thank-you)
I will assume you've followed some of these steps already - I am mostly listing them to insure everyone is on the same page.
There are many API wrappers, and it would also be possible to write a direct API interface yourself. These are all located here on the MailChimp download page. The difference between the provided API's and writing your own is how the interaction occurs. If you write your own, you are writing direct restful'esque url requests to mailchimp. If you use a pre-built API, you require a file and then call into the required file (the mailchimp API docs might not be extremely useful at this point).
For the officail client, I would expect the documentation you referenced to be more useful, additionally - examples of usage are located here: examples.
Once you have the appropriate API Client downloaded and in place, you can 'require' it into your php code, initialize the class - then start calling onto the standard API methods.
It sounds like you've marginally completed this portion - but …
Hi Douglas,
Do you have any examples of what you've tried to date? I could write something in PHP that talks to the API, but without your input, it won't truly be helpful. Maybe some of the code area where you are looking to add the API call for an example.
$stockData = QueryForStock($connect);
echo BuildStockDataHtml($stockData, $connect);
/**
*
* @param link $connect
* @return array
*/
function QueryForStock($connect)
{
$results = array();
$query = "SELECT sid, oqty, icode, item, iunit, icat FROM stock";
try
{
$result = mysqli_query($connect, $query);
while ($row = mysqli_fetch_array($result))
{
$results[] = $row;
}
mysqli_free_result($result);
}
catch(Exception $e)
{
error_log($e . __FILE__.' '.__LINE__);
$results = array();
}
return $results;
}
function QueryForItemInward($sid, $connect)
{
$results = array();
$statement = mysqli_prepare($connect, "SELECT sum(qty) FROM purchase WHERE sid=?");
mysqli_stmt_bind_param($statement,'i', $sid);
mysqli_stmt_execute($statement);
$statement->bind_result($total);
$statement->fetch();
$statement->close();
return (int)$total;
}
function QueryForItemOutward($sid, $connect)
{
$results = array();
$statement = mysqli_prepare($connect, "SELECT sum(qty) FROM sales WHERE sid=?");
mysqli_stmt_bind_param($statement,'i', $sid);
mysqli_stmt_execute($statement);
$statement->bind_result($total);
$statement->fetch();
$statement->close();
return (int)$total;
}
function QueryDataForCurrentValue($sid, $connect)
{
$query = <<<QUERY
select date, qty, rate, amt from stock st
join purchase p on st.sid = p.sid where st.sid = ?
union all
select date, -qty, rate, amt from stock st
join sales s on st.sid = s.sid where st.sid = ?
union all
select null, oqty, oprice, oamt from stock where sid = ?
order by date desc;
QUERY;
$statement = mysqli_prepare($connect, $query);
mysqli_stmt_bind_param($statement,'iii', $sid, $sid, $sid);
mysqli_stmt_execute($statement);
$statement->bind_result( $date, $qty, $rate, $amt);
while($statement->fetch())
{
$results[] = [ 'date' => $date, 'qty'=> $qty, 'rate' => $rate, 'amt' => $amt];
}
$statement->close();
return $results;
}
function BuildStockDataHtml(array $stockData, $connect)
{
$tableRows = '';
foreach($stockData as $stock)
{
$inQuantity = QueryForItemInward($stock['sid'], $connect);
$outQuantity = QueryForItemOutward($stock['sid'], $connect);
$currentQuantity = $stock['oqty'] + $inQuantity - $outQuantity;
$costOfGoodsForSale = CostOfGoodsForSale($stock['sid'], $connect, $currentQuantity);
$averageCostOfGoodsForSale = $costOfGoodsForSale / …
It looks like this logic might be a little askew in cms.php:
$something = isset($_POST['user_name'])?$_POST['user_name']:'';
if($something) {
$_SESSION['user_name']=$something;
}
As you are attempting to pull it out of the session in cms.php after the login, it should be
$something = isset($_SESSION['user_name']) ? $_SESSION['user_name'] : null;
if ($something === null) {
echo '<p>Not logged in.</p>';
//exit();
}
(Just for reference, this is a continuation )
This can all likely be optimized. I wrote the CostOfGoodsForSale for a single SID.
You'll need to calculate the $countofgoodsforsale - good practice with PHP.
Then for the data table, it is the results from the query built into an array.
$sid = 1;
$query = <<<QUERY
select date, qty, rate, amt from stock st
join purchase p on st.sid = p.sid where st.sid = {$sid}
union all
select date, -qty, rate, amt from stock st
join sales s on st.sid = s.sid where st.sid = {$sid}
union all
select null, oqty, oprice, oamt from stock where sid = {$sid}
order by date desc;
QUERY;
$dataSet = array();
$result = mysql_query($query, $connection);
while(($row = mysql_fetch_array($result, 1) )!== false)
{
$dataSet[] = $row;
}
// Determine the $countOfGoodsForSale
$finalResult = CostOfGoodsForSale($dataSet, $countOfGoodsForSale) / $countOfGoodsForSale;
If this answers your question, could you be so kind as to mark the question as resolved?
(final query I used as well)
select date, qty, rate, amt from stock st
join purchase p on st.sid = p.sid where st.sid = 1
union all
select date, -qty, rate, amt from stock st
join sales s on st.sid = s.sid where st.sid = 1
union all
select null, oqty, oprice, oamt from stock where sid = 1
order by date desc;
sid 1: 37875
sid 2: 63000
sid 3: 32000
sid 4: 27400
Have you made any attempt to calculate the values yourself?
(if my site is up)View the results here
Here's my final function to calculate the cost of the current level of stock:
function CostOfGoodsForSale($dataSet, $countOfGoodsForSale)
{
$totalPurchaseValue = 0;
$totalPurchaseQty = 0;
$done = false;
foreach($dataSet as $row)
{
// skip sales rows
if ($row['qty'] < 0)
{
continue;
}
for ($i=0; $i<$row['qty']; $i++ )
{
$totalPurchaseQty++;
$totalPurchaseValue += $row['rate'];
if ($totalPurchaseQty == $countOfGoodsForSale)
{
return $totalPurchaseValue;
}
}
}
return $totalPurchaseValue;
}
If you do want to continue using login.php to run your sql query, as you are populating a session variable, then you would need to use the session variable in cms.php to get the username back out.
replace your 'post' check in cms.php with a $_SESSION check.
if (isset($_SESSION['user_name']))
{
$username = $_SESSION['user_name'];
}
A word of caution:
Sessions can be insecure. Please read this article
I had taken the total amount for purchase and the original amount added these together and then subtracted the total amount of sales. I divided the resulting number by the final total qty
(totalPurchaseAmount + originalAmount - totalSalesAmount) / (totalPurchaseQty + OriginalQty - totalSalesQty)
How did you get 2@38000 from PVN 1?
Without the original:((1 * 38000 + 20 * 38000 + 1 * 35000 +5 * 38000) - (1*45000 + 1 * 45000+2 * 45000+1 * 45000+1 * 45000)) / 21 = 35857
With the Original row included((3*38000) + (1*38000 + 20*38000 + 1*35000 +5*38000) - (1*45000 + 1*45000+2*45000+1*45000+1*45000)) / (3+21) = 36125
This might be off course, but it was kind of interesting... For the 'test' data, I think this works:
select st.sid, (st.oamt + sum(something.totalv)) / (st.oqty+sum(totalqty)) as newRate, (st.oamt + sum(something.totalv)) as newAmount, (st.oqty+sum(totalqty)) as newQty from (
select st.sid, sum(qty * rate) as totalv, sum(qty) as totalqty from stock st
join purchase p on st.sid = p.sid group by st.sid -- where st.sid = 1
union all
select st.sid, -sum(qty * rate) as totalv, -sum(qty) as totalqty from stock st
join sales s on st.sid = s.sid group by st.sid -- where st.sid = 1;
) as something
join stock as st on st.sid = something.sid group by st.sid;
I get these results:
sid New Rate New Amount New Qty
1 36125.0000 867000 24
2 60293.7500 964700 16
3 24615.3846 320000 13
4 27400.0000 685000 25
This 'works' because it isn't real time data. Meaning, the transactions have already been completed.
In the end, there are a lot of suggested approaches. A db is a heavy handed solution, imo, but it would also work. Regardless, I think the original question has been answered quite thoroughly.
Ah, a chat system. If you are using a single server(the most likely scenario), then you use that server's time.
You then make a client that each user would use to connect to the server. (a browser page for example) Any message must first be sent to the server, and then the server send it to the client (and a confirmation back to the original sender for their timestamp. The clients can then set the local time zone however you want to let them.
Another option is to not use a server and let each client set the time stamp for when it displays the message. The only potential drawback, is that two separate clients might have different timestamps for the same conversation. This is the easier approach.
One thing to note for a client application - unless run through browser requests, PHP is not a wonderful for installing on client boxes.
Added note: I think this was described, but you could also request the current time from a SQL server.
It depends on what you want as a source of truth for time. Using an alternate time source isn't a trivial problem. An easier approach that I would recommend, and use myself, is to keep the server/computer time synced and then just use the server/computer time inside of PHP.
Unfortunately, I don't know of any specific time servers or time applications to recommend
First, assuming your starting input data is the data in your stock table. For a base case, I will stick to one SID (sid 1 is a good start).
# sid, pprice, sprice, oqty, oprice, oamt
1, 46000, 57900, 3, 38000, 114000
Now, let's take a look at the transactions. I am assuming that time is relevant, and that both sales and purchases affect whatever is going on with the stock price - so we really need to see both together.
To get a nice look, I used this:
select st.sid, st.pprice, st.sprice, st.oqty, oprice, oamt, null as svn, pvn, date, null as cid, vid, qty, rate, less, amt from stock st
join purchase p on st.sid = p.sid where st.sid = 1
union all
select st.sid, st.pprice, st.sprice, st.oqty, oprice, oamt, svn, null as pvn, date, cid, null as vid, qty, rate, less, amt from stock st
join sales s on st.sid = s.sid where st.sid = 1
order by date;
Which resulted in:
-- svn 3 and pvn 1 might not be ordered correctly as the timestamp is not unique.
svn, pvn, date, cid, vid, qty, rate, less, amt
5 2014/04/09 2 1 45000 10 40500
1 2014/04/28 1 1 45000 5 45000
1 2014/04/29 1 5 38000 0 190000
3 2014/04/29 1 2 45000 10 81000
11 2014/05/01 1 1 45000 0 45000
10 2014/05/01 2 1 45000 0 45000
4 2014/05/04 1 1 35000 0 35000
2 2014/05/13 1 20 38000 0 760000
3 2014/05/19 1 1 38000 0 38000
Now, going through the sales and purchases is where I'm unclear. I would expect the oqty to be as follows, the others I'm not certain about the calculation.
# sid, pprice, sprice, oqty, oprice, oamt
1, ?, ?, 2, ?, ?
1, ?, ?, 1, ?, ?
1, ?, ?, 6, ?, ?
1, ?, ?, 4, ?, ?
1, ?, ?, 3, ?, ?
1, ?, ?, 2, ?, ?
1, ?, ?, 3, ?, ?
1, ?, ?, 23, ?, ?
1, ?, ?, 24, ?, ?
You would need to connect to an external timeserver or use a third party app that connects to a time server. PHP only knows the time for the box it is on
It is complaining because you have a 'where' clause at the end of an insert statement.
You will want to change it to INSERT INTO event(guest_num) VALUES('$total')
. You would only need a where clause if you were trying to update or select (pretty much where you need to check existing data before performing the operation).
Hello,
I do not see anything particularily tied to PHP in this question. This looks like a general problem that you are looking to have solved. I would suggest approaching the problem and asking for assistance on particular points.