Facemash algorithm [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Does anyone know the facemash algorithm that Mark Zuckerberg implemented in his facemash site?
http://www.thecrimson.com/article/2003/11/19/facemash-creator-survives-ad-board-the/
Preferably in PHP & MySQL.

UPDATE:
As I said in the comments, I've added this algerithm to my new website. At first it seemed to work perfectly. But after some weird inputs some strange result began to form.
While debugging I figured out what I was doing wrong. When getting the score for a "direct relationship" (used in the indirect relationship too) between 2 nodes I added the scores together. This was wrong, the score of a direct relationship should be expressed in -1 to +1, where:
-1 = lost everything
+1 = won everything
So if A won 8 times to B, and B won 2 times to A the score should be:
(A wins) 8 + (B wins) 2 = (total matches)10
(delta of -1 and +1 =) 2 / (total matches)10 = (points per win) 0.2
Score of A vs B = (points per win) 0.2 * (wins) 8 - 1 = 0.6
Score of B vs A = (points per win) 0.2 * (wins) 2 - 1 = -0.4
Also I didn't mention this in the original explanation but it is all about triangles. So when we look at the indirect score, you don't need to go any further than 1 hop.

I don't know what algorithm was actually used for the real-world site, but what they write on the window in the movie is based on the Elo rating system, which originated in the chess world and is now also used in many other games.

I recreated it aswell check it out.
Not sure about php but the C# class is
http://lukedurrant.com/2010/11/c-elo-rating-class-used-on-facemash-as-seen-in-the-social-network-movie/
I used it on my
Facemash
Key press code is
$(document).keydown(function(event) {
if (event.keyCode == 37) {
//Voted Face 1
Rate("face1", false);
}
if(event.keyCode == 39) {
//Voted Face 2
Rate("face2", false);
}
});

<?php
//This page is responsible to return a JSON object
//code starts after the functions for those who might get confused xD
header('content-type: application/json; charset=utf-8');
global $responseData;
function AdjustRate($Ra, $Ea, $Sa)
{
//i used my own rules here 32 points for less than 500
if($Ra < 500)
$k = 32;
elseif ($Ra < 1000)//24 points for anything between 500 and 1000
$k = 24;
else
$k = 16;//16 for anything more than 1000
return $Ra + ($k*($Sa - $Ea));
}
function GetExpectedChance($rA, $rB) // the ELO formula taken from http://en.wikipedia.org/wiki/Elo_rating_system
{
return (1/(1+pow(10,(($rB-$rA)/400))));
}
function setNewRates($lastCall) // function I used to update my database tables
{
global $responseData;
$A = $lastCall->p1;
$B = $lastCall->p2;
$C = $lastCall->c;
$A->E = GetExpectedChance($A->rate, $B->rate);
$B->E = GetExpectedChance($B->rate, $A->rate);
// decide who won and who lost
if($A->id == $C){
$winner = $A;
$looser = $B;
}
elseif ($B->id == $C) {
$winner = $B;
$looser = $A;
}
// 3 cases, in all of them winner will get his rate/hits increased by 1
//Case #1: normal case we just update rate/hits for the winner, this applies all the time
$winner->rate += 1;
$winner->hits += 1;
//Case #2 / #3 : here we should adjust the rate after applying case #1
// if he won while he is expected to lose OR if he lost while expected to win
// there should be minimum rate different of 40 between the two
$diff = abs($winner->rate - $looser->rate);
if($diff >= 40 && ($winner->E < 0.5 || $looser->E >= 0.5)) {
$winner->rate = AdjustRate($winner->rate, $winner->E, 1);
$looser->rate = AdjustRate($looser->rate, $looser->E, 0);
}
// update the db to update rates, hits for both winner and looser
$updateQuery = 'UPDATE user SET rate='.$winner->rate.',hits='.$winner->hits.' WHERE id=' . $winner->id;
mysql_query($updateQuery);
$updateQuery = 'UPDATE user SET rate='.$looser->rate.' WHERE id=' . $looser->id;
mysql_query($updateQuery);
// Save to responsedate
$responseData->winner = $winner;
$responseData->looser = $looser;
}
//CODE STARTS HERE :)
// Setup the mysql connection
include 'db.php';
// Part 1: calculate the rate and save to db, if we have a lastcall
// GET the last call data object, it has p1, p2, c, these are the items i recieved from my javascript ajax call
$lastCall = json_decode((string)$_GET['lastCall']); // it was a JSON object so i need to decode it first
// Save last call data, will be sent with the respond as well
$responseData->lastCall = $lastCall;
// if there is a json object, means that there was a rating process and I have to set the new rates
if($lastCall->c != NULL)
{
setNewRates($responseData->lastCall);
}
// Part 3: Select new persons and addthem to our responseData
$q = Array();
$q[0] = 'SELECT id, name, sex, rate, hits FROM user WHERE fm_status=1 AND sex="female" ORDER BY RAND() LIMIT 2';
$q[1] = 'SELECT id, name, sex, rate, hits FROM user WHERE fm_status=1 AND sex="male" ORDER BY RAND() LIMIT 2';
// girls or boys ?
srand(mktime());
$query = $q[array_rand($q)];
$result1 = QueryIntoArray($query);
$responseData->user = $result1;
// Part 4: encode to JSON/JSONP string then respond to the call
$json = json_encode($responseData);
$json = isset($_GET['callback'])? "{$_GET['callback']}($json)" : $json;
echo $json;
mysql_close();
// by Noor Syron :)
//I used this in my www.mimm.me
?>

`I have designed the code in Perl all from google searching and it works.
Here's It
use strict;
use warnings;
use WWW::Mechanize;
use LWP::Simple;
sub images()
{
my $mech = WWW::Mechanize->new();
my ($site,$count,$file,$dir);
print "\t\t\tDesigned By NUMWARZ GAMING\n\n";
print "Enter the name of the site you want to search for images\t:\n";
$site = <STDIN>;
print "Enter the folder where you want to save this\t:\n";
$dir = <STDIN>;
open my $doc, ">" , $dir."sitelist.txt";
$mech->get( $site);
my #links = $mech->images();
$count = 0;
for my $link ( #links )
{
$file = $dir.$count.".jpg";
mirror($link->url,$file);
print $file," : "$link->url,"\n";
print $doc $link->url." ".$file."\n";
$count+=1;
}
close $doc;
exit;
}
images();

No not here not anywhere on the web. The Facemash source code has never been released to the public. The only one, who might still have a copy is Mark Zuckerberg himself.

here is a clone of facemash available http://www.facemash.99k.org

I've recreated it as well, but in a WordPress plugin
http://pofornot.com/
http://codecanyon.net/item/pics-mash-image-rating-tool/3256459?ref=mikemayhem3030

Related

Stopping a PHP loop when updating MySQL database

I'm creating a basic main menu for a stock market simulator where the price of a company will be updated periodically. For testing purposes, I need to make a loop to display the price of a share on the website five times (with the website automatically updating without refreshing) and to update the database at the same time.
I have successfully wrote some code which will both update the database with the current share price and will also update the website as well. However, when I have tried to include a loop I have come to a problem. I have included a loop to iterate five times but the problem that I am having is that the code continues to iterate even after five tries.
PHP:
<?php
$conn = mysqli_connect("localhost", "root", "", "prices");
if ($conn->connect_error)
{
die("Connection error: ". $conn->connect_error);
}
$result = $conn->query("SELECT `price` FROM `priceTable` WHERE `company` = 'Bawden'");
$x = 0;
if ($result->num_rows > 0)
{
while ($row = $result->fetch_assoc())
{
echo $row['price'];
echo '<br><br>';
echo $x;
if ($x < 5)
{
$random = (rand(3300, 3700) / 100);
$sql = $conn->query("UPDATE `priceTABLE` SET `price` = '$random' WHERE `company` = 'Bawden'");
$x++;
}
}
}
?>
The above code will be displayed in a separate document with Javascript code and I can post this if required in the original post however I originally chose not to as I believe this is a PHP only problem. I have chosen to display $x to see if the value will increment. However, when running, the value of $x will stay at 0.
My expected result is that, on the website, there will only be five different updates and in the database, the database will only be updated five times.
However, my actual result is that the website and database are both continuously being updated, not stopping after five times.
I'm trying to limit the update command to only 5 updates yes. At the
moment, for testing purposes, there is only one company in my database
with one price only. So I'm updating this one company's price five
times
If you need to do the update 5 times for each row returned from the database, change your if statement to a for loop. Change this :-
if ($x < 5)
{
$random = (rand(3300, 3700) / 100);
$sql = $conn->query("UPDATE `priceTABLE` SET `price` = '$random' WHERE `company` = 'Bawden'");
$x++;
}
to this
for ($x = 0, $x < 5, $x++)
{
$random = (rand(3300, 3700) / 100);
$sql = $conn->query("UPDATE `priceTABLE` SET `price` = '$random' WHERE `company` = 'Bawden'");
}
This will repeat the process exactly 5 times and not rely on a separate counter (remove the other references to $x). Not sure why you would want to update the same record 5 times with different random values though.
The else will break the first loop, the second one will stop on the first while loop.
while ($row = $result->fetch_assoc())
{
echo $row['price'];
echo '<br><br>';
echo $x;
if ($x < 5)
{
$random = (rand(3300, 3700) / 100);
$sql = $conn->query("UPDATE `priceTABLE` SET `price` = '$random' WHERE `company` = 'Bawden'");
$x++;
}else{
break;
}
break;
}
What makes you think the loop should stop after 5 iterations?
You need to add the condition $x<5 in the while ($row = $result->fetch_assoc())
Edit following your comment
What you initially wrote is something like loop hundreds of times if need be and do something in the first 5 occurrences (starting loop 6, keep looping but do nothing).
Now for the 2nd half of your comment, I'm not sure what you mean.
What I see in your code is:
Select all prices for company = 'Bawden'
Update all the prices for company = 'Bawden' 5 times (loop) with a random value, the same one, on all the records.
Not enough information to tell for sure but I don't think it makes sense: on one hand, you except to have several records under company = 'Bawden (= reason why you created a loop), on the other hand, your update feels like it is written under the assumption there would be 1 record only...
Are you missing something like a price date from your table? What is the primary key of priceTable?
Try to post more technical details about your table (definition, sample of data) or it will be complicated to help further.

putting variable into specific rows after math

i am trying to create a golf tourney scoreboard where i input the scores from each round and if i put in what course was played, it will go into the row of my sql database. how do i make a total score that is figured out in my php code go into a row that i specify on the form?
the form is built out like this:
<input name='name/handi/par/course/hole1/etc' type='text'>
to save space/time just short-handing the coding as much as possible. the php looks like this:
$name = $_POST['name/handi/par/course/hole1/etc'];
then i have the math broken out to figure the front 9, back 9, total score (with handicap [handi] worked in)
$totOut = ($hole1 + $hole2...etc)
$totIn = ($hole10 + $hole11 ... etc)
$total = ($totOut + $totIn) - $handi;
$o_u_total = $total - $par; (over/under for the week)
$o_u_today = $total - $par; (over/under for the day)
the total for today (b/c there are 4 rounds) and the total for the whole week. the totals for the whole week are worked out in a query on the display page:
$sql = "SELECT name,
SUM(total) AS Score,
SUM(o_u_total) AS Over_Under,
total AS Total_Today,
o_u_today AS Over_Under_Today
FROM matchplay
GROUP BY name
ORDER BY Score ASC";
$result = mysqli_query($conn, $sql);
and how i am trying to make the inputted value (course name) go into the specific row (designated in my sql dbase) is like this:
$ridge;
if ($_POST['course'] = 'The Ridge') {
($ridge = $total);
}
$cove;
if ($_POST['course'] = 'The Cove') {
($cove = $total);
} etc
i have a feeling that i am doing something terribly wrong with the if/else, but i don't know how else to choose what i want the $total to go into.
can anybody help me?
i figured it out ... thanks if anybody saw it and was in the middle of thumping me on the head with how easy it was
$ridge;
if ($_POST['course'] == 'The Ridge') {
($ridge = $total);
}
and not
$ridge;
if ($_POST['course'] = 'The Ridge') {
($ridge = $total);
}
Glad you did figure it out. To enhance your code and avoid multiple ifs, you can use a switch case statement.
$course_name = $_POST['course'];
switch($course_name){
case ('The Ridge'):
// your code here
break;
case ('The code'):
// an other code here
break;
}
Hope this help.

Pulling specific random values from php array

On the page I'm creating there is graphic representation of pigeon-holes with five compartments for new comments. If there is new unread comment it should show up as graphic in one random compartment. But it won't happen if all of the 5 are
already occupied. So if someone writes new comment I like the code to check for if there is already five of them taken, and if not, than to randomly occupied one of the remaining ones. So "new_c" stands for number of
unread (new) comments, and c1-c5 stands for compartments. Value 0 means empty compartment for each "c". I was trying to make code that would first separate new_c from rest of the array after knowing the number is smaller than 5,
so I'm only working with 5 compartments. And than to determine which one is/are empty. And then randomly choose one empty to occupy. It's not really working as it is I probably am not using that array_keys properly as c2 is changed to some other value than 0 but still is being echoed, there is probably also a better/more efficient way to achieve that. I will really appreciate some input.
<?php
$tucQuery = "SELECT new_c,c1,c2,c3,c4,c5 FROM users WHERE id = '{$author_id}' LIMIT 1";
$result_tuc = mysqli_query($connection, $tucQuery);
$tucArray = mysqli_fetch_assoc($result_tuc);
mysqli_free_result($result_tuc);
$new_c = $tucArray[0];
if($new_c < 5){
$new_array = array_keys((array_slice($tucArray,1)), 0);
$rand_zero = array_rand($new_array, 1);
echo $rand_zero + 1;
}
?>
Bellow code works but it doesn't seem to be efficient and there is probably a better way.
if($new_c < 5){
$empties = array();
if($tucArray['c1'] == 0){
$empties[] = 1;
}
if($tucArray['c2'] == 0){
$empties[] = 2;
}
if($tucArray['c3'] == 0){
$empties[] = 3;
}
if($tucArray['c4'] == 0){
$empties[] = 4;
}
if($tucArray['c5'] == 0){
$empties[] = 5;
}
print_r($empties);
$rand_zero = array_rand((array_flip($empties)), 1);
echo $rand_zero;
}

Select random array generated from while loop

im learning PHP because i made only designs and templates, and i came to an big problem, at least for me. I am making simple "army battle script" where each player has some troops with attack, defense, hp stats, and they battle against each other. Ive made attack player vs player but i am struggling about many entity fight and how to code it.
First im calling all my units sended to attack, run it trought the loop and get in array every row/unit
Then i made that with enemy units, and in the end, i have a simple simulation script that makes the fight. But the fight isnt working. It doesnt select random unit from the array, it doesnt switch between attacker x defender turns and whats the worse, it only runs with one unit, when that units dies, the script ends and thats it... Can you guys please give me some answer, or way to handle this? I will be so thankfull because i am solving this for few days and i have no clue. Thanks. (i know that the code is ugly, but its just concept...)
//EDIT
Ok, i turned on the error reports and change a bit the simulation code, but the results are bad. I get error Fatal error: Maximum execution time of 30 seconds exceeded in or Warning: Division by zero in php in line
$hit = ($attacker['attack']/$defender['defense']) + rand(1, 2);
Heres the full code, ive tried rand(0,count($unit_attacker_def)-1); but i think its without changes. Also i added selecting new random array with unit, if there is 0 health and unset. And its still running trought one unit, not all in attacker array, and all, or left units in defender array. I somehow came to phase where the script calls the next unit, but it havent any variables in it loaded.
case 'battle_wizard_execute';
?>
<table>
<tr><td><h3>Utok</h3></td></tr>
<?
$query_street = mysql_query("SELECT * FROM game_army_attacks WHERE attack_id = '".$_GET['id']."' ");
$row_street = mysql_fetch_assoc($query_street);
$query_loc_info = mysql_query("SELECT * FROM game_location_street WHERE street_id = '".$row_street['attack_attacker']."' ");
$row_loc_info = mysql_fetch_assoc($query_loc_info);
$tilee_info = mysql_num_rows($query_street);
if ($tilee_info > 0){
$query_units_info = mysql_query("SELECT * FROM game_army_units_attacking WHERE army_attack = '".$_GET['id']."' ");
while (($unitsinfo = mysql_fetch_assoc($query_units_info)) != NULL) {
$query_unit_info = mysql_query("SELECT * FROM game_army_class WHERE army_class_id = '".$unitsinfo['army_class_id']."' ");
$unit = mysql_fetch_assoc($query_unit_info);
$unit_attacker = array();
$unit_attacker[] = array(
'name' => $unit['army_class_name'],
'power' => $unitsinfo['army_power'],
'attack' => $unitsinfo['army_att'],
'defense' => $unitsinfo['army_def']
);
///// Kolko jednotiek máš tolko krat sa vypise
$x = 1;
while($x <= $unitsinfo['army_population']) {
foreach($unit_attacker as $index => $record){
///// Tato cast pusti kod pre kazdu jednu jednotku ktora je v poli
echo "<tr><td>Jednotka: {$record['name']} ID: {$record['power']} ParentID: {$record['attack']} Title: {$record['defense']}</td></tr>";
$x++;
}
}
}
}
?>
</table>
<table>
<tr><td><h3>Utok protivnik</h3></td></tr>
<?
$query_street_def = mysql_query("SELECT * FROM game_army_units WHERE army_street = '".$row_street['attack_defender']."' ");
$tilee_info_def = mysql_num_rows($query_street_def);
if ($tilee_info_def > 0){
$query_units_info_def = mysql_query("SELECT * FROM game_army_units WHERE army_street = '".$row_street['attack_defender']."' ");
while (($unitsinfo_def = mysql_fetch_assoc($query_units_info_def)) != NULL) {
$query_unit_info_def = mysql_query("SELECT * FROM game_army_class WHERE army_class_id = '".$unitsinfo_def['army_class_id']."' ");
$unit_def = mysql_fetch_assoc($query_unit_info_def);
$unit_attacker_def = array();
$unit_attacker_def[] = array(
'name' => $unit_def['army_class_name'],
'power' => $unitsinfo_def['army_power'],
'attack' => $unitsinfo_def['army_att'],
'defense' => $unitsinfo_def['army_def']
);
///// Kolko jednotiek máš tolko krat sa vypise
$y = 1;
while($y <= $unitsinfo_def['army_population']) {
foreach($unit_attacker_def as $index => $record_def){
///// Tato cast pusti kod pre kazdu jednu jednotku ktora je v poli
echo "<tr><td>Jednotka: {$record_def['name']} ID: {$record_def['power']} ParentID: {$record_def['attack']} Title: {$record_def['defense']}</td></tr>";
$y++;
}
}
}
}
Simulation:
$count = 0;
while ((count($unit_attacker_def) > 0) && (count($unit_attacker) > 0)){
$count++;
$attacker_key = rand(0,count($unit_attacker_def)-1);
$attacker =& $unit_attacker[$attacker_key];
$defender_key = rand(0,count($unit_defender)-1);
$defender =& $unit_attacker_def[$defender_key];
while (($defender['power'] >= 0) && ($defender['power'] >= 0)){
$hit = ($attacker['attack']/$defender['defense']) + rand(1, 2);
echo "<tr><td>{$count}.xx {$attacker_key} xJednotka {$defender['name']} ({$defender['power']} hp) bola zranená a dostala {$hit} zranenia jednotkou {$attacker['name']} ({$attacker['power']} hp)</td></tr>";
$defender['power'] = $defender['power'] - $hit;
$attacker['power'] = $attacker['power'] - $hit;
if ($defender['power'] <= 0) {
echo "<tr>Jednotka {$defender['name']} umrela, jednotka {$attacker['name']} vyhrala!</tr>";
unset($defender[$defender_key]);
$defender_key = rand(0,count($unit_defender)-1);
$defender =& $unit_attacker_def[$defender_key];
}
if ($attacker['power'] <= 0) {
echo "<tr>Jednotka {$attacker['name']} umrela, jednotka {$defender['name']} vyhrala!</tr>";
unset($attacker[$attacker_key]);
$attacker_key = rand(0,count($unit_attacker_def)-1);
$attacker =& $unit_attacker[$attacker_key];
}
}
}
?>
</table>
<?
break;
Well you use array_rand() it selects one element from the array and when u use $array[$key] where $key = 1 because of array to var conversion it returns second element of your array atackers and second element of defenders. Use rand(0,count($unit_attacker)-1) to generate random key. But it still will be bugy because you can generate the same key )).
First of all, make sure you have turned on error reporting:
<?php
// Turn off error reporting
error_reporting(0);
// Report runtime errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Report all errors
error_reporting(E_ALL);
// Same as error_reporting(E_ALL);
ini_set("error_reporting", E_ALL);
// Report all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);
?>
With simple debugging you will find out where is an error. Just var_dump() every important variable and check its state. Nobody can debug for you because we don't know what is the data in your mysql table.
Try to use mysqli_* functions, because mysql are deprecated.
Try to use classes to describe everything in your game and make it more readable and maintainable. For example:
<?php
abstract class Unit{
protected $hp;
protected $damage;
protected $defense;
// Force Extending class to define this method
abstract protected function applyDamage($damage);
}
class GroundUnit extends Unit{
//GroundUnit inherits everything from Unit
//define methods specific for GroundUnits
}
class FlyingUnit extends Unit{
//FlyingUnit inherits everything from Unit
//define methods specific for GroundUnits
}
When you find where is an error, and if you are still stuck, update your question with relevant data.
Note that your code is vulnerable to SQL injection
$query_street = mysql_query("SELECT * FROM game_army_attacks WHERE attack_id = '".$_GET['id']."' ");//don't put $_GET['id'] directly into query because that is security hole
Simple steps(related to your example) to improve your protection from sql injection would be :
//assume that $_GET['id'] should hold an integer value
$id = isset($_GET['id']? trim($_GET['id']) ? 0);
$id = (int)$id;
Now let's pretend that there is a $_GET['some_key'] also and it should hold string value. Now checks would be little different:
$some_string_value = isset($_GET['some_key']? trim($_GET['some_key']) ? '');
$some_string_value = trim($some_string_value);//triming whitespace
$some_string_value = mysql_real_escape_string($some_string_value);//escaping troublesome quotes(')
Also you can use prepared statements which is in my opinion a preferred way.

Couldn't get the total amount of each row

I was having difficulty trying to get the total amount of each row with this code:
Total Sales for this day:
<b>Php <?php
function formatMoney ($number, $fractional=false) {
if ($fractional) {
$number = sprintf('%.2f', $number);
}
while (true) {
$replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1,$2', $number);
if ($replaced != $number) {
$number = $replaced;
}
else {
break;
}
}
return $number;
} // formatMoney
$result1 = mysql_query("SELECT sum(sales) FROM sales where date='$startDate'");
while($row = mysql_fetch_array($result1)) {
$rrr=$row['sum(sales)'];
echo formatMoney($rrr, true);
}
?>
But once I manually inserted the data straight to the database it appears to be working. It’s just that whenever I tried to add a data through the system, the values isn't showing at all.
Apart from it, I’m also having issue with how to refresh a column if the one next to it has placed a value that is connected to it.
Any idea? I’m getting stuck with this one.
Additional Information:
Here's the actual table.
No. of Remaining Property No. of Rented Property Rent Cost Amt. Tendered
1 1 1000 1000
1 1200
If there's a value placed in No. of Rented Property [example 1], the other column beside it No. of Remaining Property, must be refreshed and should display 0. Then the value for the Amount tendered must be=No. of Rented Property x Rent Cost.
You see the first row has values in it. And its working since I do a manual insert on the database. But The second row shows only the value for No. of Remaining Property and the rest is empty. When I tried to add value in NoRentedProperty the NoOfRemaningProperty still displays 1 and the amount was not being multiplied to the Amount Tendered.
I’ve checked my code and am quite sure that it’s all fine. But I don't understand why this is happening.
First & foremost, you should always format your code to make it easier to read. It helps you debug issues like this better & it helps others—like us—aid you in debugging issues:
function formatMoney ($number, $fractional=false) {
if ($fractional) {
$number = sprintf('%.2f', $number);
}
while (true) {
$replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1,$2', $number);
if ($replaced != $number) {
$number = $replaced;
}
else {
break;
}
}
return $number;
} // formatMoney
$query_sql = "SELECT SUM(sales) sales_total FROM sales WHERE date='$startDate'";
// echo $query_sql . '<br />';
$result1 = mysql_query($query_sql);
while ($row = mysql_fetch_array($result1)) {
$rrr = $row['sales_total'];
echo formatMoney($rrr, true);
}
The main thing I did beyond basic formatting is to return SUM(sales) as sales_total.
As far as formatting goes, I also set the actual query SQL in a variable named $query_sql and have a commented out line with echo $query_sql . '<br />'; in it. I recommend you uncomment that on your system and look at the query that is being set & test that directly in the database itself.
Given the fact you are not providing examples of what $startDate looks like—or explaining where that comes from—not much else can be done to debug this.

Categories