-
Notifications
You must be signed in to change notification settings - Fork 3
/
new.php
78 lines (58 loc) · 1.71 KB
/
new.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
require_once("adodb/adodb-exceptions.inc.php");
require_once("adodb/adodb.inc.php");
$db_name = 'CHANGEME';
$db_ip='CHANGEME';
$db_user = $db_name;
$db_name = $db_user;
$db_pass = 'CHANGEME';
$connect= "mysql://$db_user:$db_pass@$db_ip/$db_name?persist";
$DB = NewADOConnection($connect);
$memcache = new Memcache();
$memcache->addServer('10.12.198.194', 11211);
function get_total_joke_count() {
global $memcache, $DB;
$r = $memcache->get("total_joke_count_profile");
if($r == FALSE) {
$sql = "SELECT max(id) from jokes_approved";
$r = $DB->GetOne($sql);
$memcache->set("total_joke_count_profile", $r, false, 60);
}
//echo "total user count: $r";
return $r;
}
$total_joke_count = get_total_joke_count();
//echo $total_joke_count;
$ra = rand(1,$total_joke_count);
/*
if($memcache) {
$r = $memcache->get('joke_random');
if($r == FALSE) {
*/
$r = $DB->GetRow('select * from jokes_approved where id = ?', array($ra));
/* $memcache->set('joke_random', 10);
}
}
else {
$r = $DB->GetRow('select * from jokes where id = ?', array($ra));
}
*/
//print_r($r);
//$size = count($r);
//echo "size is $size";
//$r = $DB->GetRow('select * from jokes limit 1');
$question =$r['question'];
$answer =$r['answer'];
$user =$r['user'];
if($question == '' || $question == FALSE) {
$question = 'Why are Pirates so Cool?';
$answer = 'They just arrrr!!!';
}
?>
<div id='lolinner'>
<div style='margin:5px; border: 1px dotted black'><p style='text-align:center; font-size:125%'><strong>Q: </strong><?php echo $question; ?></p>
</div>
<div style='margin:5px; border: 1px dotted black'>
<p style='text-align:center; font-size:125%'><strong>A: </strong><?php echo $answer; ?></p>
</div>
</div>