PDA

View Full Version : Information on pet with most clicks works only sometimes


Dinocanid
02-27-2017, 06:23 PM
The script will sometimes show the wrong pet when choosing the one with the most clicks
I discovered this problem yesterday, and it's that showing the information of the pet with the most clicks will not always work, but there doesn't seem to be any pattern to when it works and when it doesn't.

$topclicks = $mysidia->db->select("owned_adoptables", array("totalclicks"), "Type='{$species}'", "1 ORDER BY totalclicks DESC LIMIT 1")->fetchColumn();
$topadopt = $mysidia->db->select("owned_adoptables", array("name"), "Type='{$species}'", "1 ORDER BY totalclicks DESC LIMIT 1")->fetchColumn();
$topadoptowner = $mysidia->db->select("owned_adoptables", array("owner"), "Type='{$species}'", "1 ORDER BY totalclicks DESC LIMIT 1")->fetchColumn();
I use this code to get the name, name of the owner, and amount of clicks of the most clicked adoptable of that species. It will sometimes pick my pet, which doesn't have the most clicks. The problem is that I have the exact same line of code repeated throughout my php file, and sometimes it works and sometimes it does not.
$topclicks = $mysidia->db->select("owned_adoptables", array("totalclicks"), "Type='{$species}'", "1 ORDER BY totalclicks DESC LIMIT 1")->fetchColumn();
$topadopt = $mysidia->db->select("owned_adoptables", array("name"), "Type='{$species}'", "1 ORDER BY totalclicks DESC LIMIT 1")->fetchColumn();
$topadoptowner = $mysidia->db->select("owned_adoptables", array("owner"), "Type='{$species}'", "1 ORDER BY totalclicks DESC LIMIT 1")->fetchColumn();

ewe
03-24-2017, 11:52 AM
Some odd behavior might come from having multiple cells fetched. You could try selecting the adoptable code and making it an OwnedAdoptable.

$topclicks = $mysidia->db->select("owned_adoptables", array("aid"), "Type='{$species}'", "1 ORDER BY totalclicks DESC LIMIT 1")->fetchColumn();

$adopt = new OwnedAdoptable($topclicks);
Then use the OwnedAdoptable class attributes to fill in everything you need

When you fetch a column you're getting just the data in that cell. If you pick the AID you'll be able to make an OwnedAdoptable. You could also reduce your statement to:
$pet = $mysidia->db->select("owned_adoptables", array(), "Type='{$species}' ORDER BY RAND() LIMIT 1")->fetchObject();

kristhasirah
03-31-2017, 03:17 PM
Im not a coder and don't know if this will be useful or if it will work for you, but for me it works:

$topclicks = $mysidia->db->select("owned_adoptables", array("totalclicks"), "Type='{$species}' ORDER BY totalclicks DESC LIMIT 1")->fetchColumn();
$topadopt = $mysidia->db->select("owned_adoptables", array("name"), "Type='{$species}' ORDER BY totalclicks DESC LIMIT 1")->fetchColumn();
$topadoptowner = $mysidia->db->select("owned_adoptables", array("owner"), "Type='{$species}' ORDER BY totalclicks DESC LIMIT 1")->fetchColumn();

is the same code you provided for the encyclopedia i just removed the: ", "1 from each one and united Type with ORDER, don't know if is the correct way but that's how you can find it in the myadopts.php
and now is displaying the correct info