Log in

View Full Version : How to not show clicked adoptables


Lonin
06-03-2012, 12:13 PM
Title sense make none

Alrighty so i've spent ages and I don't know how to do this. XD Hopefully someone can help :c
I have a random adoptables page that shows 10 random adoptables for people to click. It's pretty much just the random adopt thing from stats.php but with a limit of 10 instead of 5. :B
What I want is for that page to only show (random 10 of) the adoptables that user hasn't clicked that day instead of any adoptable. :meow:

Hall of Famer
06-03-2012, 12:41 PM
Well this can get a bit tricky, you will need to utilize the other table in the database called prefix_vote_voters. Before displaying the owned adoptables available to click, filter out those who have been fed on the same day by the same user as it shows in table prefix_vote_voters. The rest of adoptables shown on the page will be those who are to be fed.

Lonin
06-04-2012, 03:29 AM
:P Alrighty I don't know how to do that.
Thanks for the help. ^^

Hall of Famer
06-06-2012, 01:01 AM
No worries, I will give you more details on how to accomplish this. Can you show me what you've done with the 10 random adoptables page? It would be easier for me to tell you what to do this way, otherwise Id have to write an arbitrary script and explain some concepts that may not make much sense to you.

Lonin
06-07-2012, 03:37 AM
Yup yup

<?php

include("functions/functions.php");
include("functions/functions_users.php");
include("functions/functions_adopts.php");
include("inc/lang.php");

//***************//
// START SCRIPT //
//***************//
$article_title = "Random adoptables";
$article_content = $article_content."<br><h3>".$lang_randomadopts."</h3>".$lang_randomtext."<br>
<br /><form>
<input type='button' onClick='history.go(0)' value='Refresh'>
</form><br><table>
<tr>
<th>Adoptable Image: </th>
<th>Adoptable Name: </th>
<th>Owned By: </th>
<th>Total Clicks: </th>
<th>Current Level: </th>
</tr>";

// Loop out code...
$query = "SELECT * FROM ".constant("PREFIX")."owned_adoptables, ".constant("PREFIX")."adoptables, ".constant("PREFIX")."levels WHERE "
.constant("PREFIX")."adoptables.type = ".constant("PREFIX")."owned_adoptables.type AND ".constant("PREFIX")."levels.thisislevel = ".constant("PREFIX")."owned_adoptables.currentlevel AND ".constant("PREFIX")."levels.adoptiename = ".constant("PREFIX")."adoptables.type"
." ORDER BY RAND() DESC LIMIT 10";
$stmt = $adopts->query($query);

//Loop out code
while ($row = $stmt->fetchObject()) {
$aid=$row->aid;
$currentlevel=$row->currentlevel;
$owner=$row->owner;
$type=$row->type;
$name=$row->name;
$eggimage=$row->eggimage;
$usealternates=$row->usealternates;
$totalclicks=$row->totalclicks;
$primaryimage=$row->primaryimage;
$alternateimage=$row->alternateimage;

if ($usealternates=='yes') { $image = $alternateimage; }
else { $image = $primaryimage; }
if ($currentlevel==0) { $image = $eggimage; }
if ($image=='') { $image = $primaryimage; }

$article_content = $article_content."<tr>
<td><center><a href='levelup.php?id={$aid}'><img src='{$image}' border=0></a></center></td>
<td><center>{$name}</center></td>
<td><center><a href='profile.php?user={$owner}'>{$owner}</a></center></td>
<td><center>{$totalclicks}</center></td>
<td><center>{$currentlevel}</center></td>
</tr>";

}

$article_content = $article_content."</table><br><form>
<input type='button' onClick='history.go(0)' value='Refresh'>
</form>";


//***************//
// OUTPUT PAGE //
//***************//

echo showpage($article_title, $article_content, $date);

?>

Hall of Famer
06-07-2012, 01:10 PM
Well here is the modified version of your script. Lemme know if it works and I will see what I can do to help you:


<?php

include("functions/functions.php");
include("functions/functions_users.php");
include("functions/functions_adopts.php");
include("inc/lang.php");

//***************//
// START SCRIPT //
//***************//
$article_title = "Random adoptables";
$article_content .= "<br><h3>{$lang_randomadopts}</h3>{$lang_randomtext}<br>
<br /><form>
<input type='button' onClick='history.go(0)' value='Refresh'>
</form><br><table>
<tr>
<th>Adoptable Image: </th>
<th>Adoptable Name: </th>
<th>Owned By: </th>
<th>Total Clicks: </th>
<th>Current Level: </th>
</tr>";

// Loop out code...
$query = "SELECT * FROM ".constant("PREFIX")."owned_adoptables, ".constant("PREFIX")."adoptables, ".constant("PREFIX")."levels
WHERE ".constant("PREFIX")."adoptables.type = ".constant("PREFIX")."owned_adoptables.type
AND ".constant("PREFIX")."levels.thisislevel = ".constant("PREFIX")."owned_adoptables.currentlevel
AND ".constant("PREFIX")."levels.adoptiename = ".constant("PREFIX")."adoptables.type ORDER BY RAND() DESC LIMIT 10";
$stmt = $adopts->query($query);


//Loop out code
$counter = 0;
while($row = $stmt->fetchObject()){
$date = date('Y-m-d');
$ip = $_SERVER['REMOTE_ADDR'];
$where_clause = ($isloggedin == "yes")
?"adoptableid='{$row->aid}' and username = '{$loggedinname}' and date = '{$date}'"
:"adoptableid='{$row->aid}' and ip = '{$ip}' and date = '{$date}'";
$vote = $adopts->select("vote_voters", array("void"), $where_clause)->fetchColumn();
if(is_numeric($vote)){
// The adoptable has been clicked by the user, so we will not load this data
continue;
}

if ($row->currentlevel==0) $image = $row->eggimage;
elseif ($row->$usealternates=='yes') $image = $row->alternateimage;
else $image = $row->primaryimage;

$article_content .= "<tr>
<td><center><a href='levelup.php?id={$row->aid}'><img src='{$image}' border=0></a></center></td>
<td><center>{$row->name}</center></td>
<td><center><a href='profile.php?user={$row->owner}'>{$row->owner}</a></center></td>
<td><center>{$row->totalclicks}</center></td>
<td><center>{$row->currentlevel}</center></td>
</tr>";

$counter++;
if($counter >= 10){
// Already loaded ten adoptables, time to break out of the loop.
break;
}
}

$article_content .= "</table><br><form>
<input type='button' onClick='history.go(0)' value='Refresh'>
</form>";


//***************//
// OUTPUT PAGE //
//***************//

echo showpage($article_title, $article_content, $date);

?>

Lonin
06-08-2012, 12:48 PM
:smile: Yaaaaay it works. Thanks so much for the help. :D

Well sometimes it doesn't always show 10 even if there's over 10 left (one refresh it showed 9 then 10 again after) or it'll show random amounts below 10 (if I don't click anything then one refresh it might show 2 then 5 then 3 or something).

Hall of Famer
06-08-2012, 01:04 PM
Oh I see, remove the 'LIMIT 10' from sql query and it should work for you.

The script uses a counter to check if the number of random adoptables loaded hit 10 or not, so this sql query is redundant and needs to be modified.

Lemme know what happens once you revise the sql query, if it fails to function normally I will take a deeper look into the code.

Lonin
06-08-2012, 01:28 PM
Yaaaaay it's fixed. :D
Thank you <3

Hall of Famer
06-08-2012, 01:29 PM
You are very welcome, glad I can be of any help.

Hall of Famer