Jump to content

Having trouble with arrays


mcmuney

Recommended Posts

I'd like to perform 2 tasks:

 

First, get a list of users who have not logged in for 30 days. Then, deduct some points as a penalty. This is what I have so far:

 

$sec=30*86400;
$curr_time=time();
$maxtime=$curr_time-$sec;	
$result = mysql_query("SELECT scm_mem_id FROM sc_member WHERE (scm_lastlogin < '$maxtime') ORDER BY scm_lastlogin") ;
while($row = mysql_fetch_row($result)) {
$member = $row[0];
//-------------------------- DEDUCT POINTS --------------------------------
$points = ?; // need to pull existing points (field: scm_points) from the above SELECT statement and deduct 10% (rounded)
$time_=time();		
$sql_c = "INSERT INTO sc_coins_asset (`type_id`,`mem_id`,`from/to_mem_id`,`date_added`,`value`) VALUES(9,$member,8,'".$time_."',-".$points.")";
$db->insert_data($sql_c);
}

 

 

Link to comment
https://forums.phpfreaks.com/topic/220637-having-trouble-with-arrays/
Share on other sites

Maybe this

 

   //-------------------------- DEDUCT POINTS --------------------------------
   $point_total = $row['scm_points'];
   $point_minus = $point_total * .1;
   $points = round($point_minus);
   echo "Begining: $point_total <br />";
   echo "Minus 10% Rounded: $points";
   // need to pull existing points (field: scm_points) from the above SELECT statement and deduct 10% (rounded)

Something isn't quite right with the array. As you can see:

 

$member = $row[0] //shows scm_mem_id, but if I modify this to either $row['scm_mem_id'] or $row[0]['scm_mem_id'] it doesn't show it

 

How can I pull both scm_mem_id and scm_points and show them both separately?

Change the query:

//from
$result = mysql_query("SELECT scm_mem_id FROM sc_member WHERE (scm_lastlogin < '$maxtime') ORDER BY scm_lastlogin") ;
//to
$result = mysql_query("SELECT scm_mem_id, scm_points FROM sc_member WHERE (scm_lastlogin < '$maxtime') ORDER BY scm_lastlogin") ;

//change:
$points = ?; // need to pull existing points (field: scm_points) from the above SELECT statement and deduct 10% (rounded)
//to
$points = $row[1] - round($row[1] * .10);  //Find 10% of scm_points, and subtract it from points.  Rounded of course.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.