Thread: MySQL Help
View Single Post
  #1  
Old 12-29-2016, 09:31 AM
Abronsyth's Avatar
Abronsyth Abronsyth is offline
A Headache Embodied
 
Join Date: Aug 2011
Location: NY
Posts: 1,011
Gender: Male
Credits: 151,700
Abronsyth is on a distinguished road
Default MySQL Help

I know the title is pretty vague but I am hoping someone can help me out here.

So the way the friends system works is it adds a user's id under the friend part in the database, but because users can have multiple friends it shows like "1, 16, 33" (for example). Clearly the comma is a separator, but I do not understand how new entries are added in that format or how the script knows to read each individual entry and use that information?

What I am trying to do is set up a system to record which users have used each promocode. So a user uses a promocode and it adds their ID to the list of those who've used it. Then I can add a setting option so that the admin can choose to make the promocode only redeemable once per user.

I can also eventually use it to set up a more stream-lined quest system than what I am currently using.

I found this chunk in class_friend.php which I think is relevant:
PHP Code:
   public function append($uid){
      
$mysidia Registry::get("mysidia");
      
$this->getfriendlist();
      
$friendsarray $this->friendlist->getids();      
      if(!
$this->isfriend$friendsarray[] = $uid;   
      
sort($friendsarray);     
      
$friends = (count($friendsarray) == 1)?$uid:implode(","$friendsarray);      
      
$mysidia->db->update("users", array("friends" => $friends), "username='{$this->user->username}'");
   } 
But I am having a hard time figuring this out Here's what I've added to class_promocode.php so far;
PHP Code:
  private function checkredeem() {
      
//This will check to see which users have already redeemed this code.
      
$mysidia Registry::get("mysidia");
      
$redeemed $mysidia->db->select("promocodes", array("redeemed"), "pid='{$this->pid}'")->fetchColumn();
      
$redeem = {$mysidia->user->uid};
      if(empty(
$this->redeemable)) return TRUE;
      else{
        if(
$redeemed){throw new AlreadyRedeemedException($mysidia->lang->redeemed);}
        
//Need to work on this part still...need to make it so that when they redeem it, they're ID is added to the list so they can't redeem it again
        
else {$mysidia->db->update("promocodes", array("redeemed" => $redeem), "pid='{$this->pid}'");}
        return 
TRUE;
      }
  } 
(I have lang_promo, admincp/promo, and admincp/view/promoview all ready to go, as soon as I get this figured out I'll release it as an actual mod)

But this is all I've got and right now it's pretty useless until I figure out how to properly add uids to the database.

If someone could help me I would really, really appreciate it <3
__________________
My Mods Site (1.3.4, 2020 Mods)

Last edited by Abronsyth; 12-29-2016 at 12:39 PM.
Reply With Quote