MyBB Community Forums

Full Version: Putting data from database into pages like memberlist page
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello so I have this
<?php
define("IN_MYBB", 1);
require_once "./global.php";

$altbg = alt_trow();
$userlist = '';
$num = 1;
$query = $db->query("SELECT * FROM mybble_changelog ORDER BY id DESC");

function get_time_ago( $time )
{
    $time_difference = time() - $time;

    if( $time_difference < 1 ) { return 'less than 1 second ago'; }
    $condition = array( 12 * 30 * 24 * 60 * 60 =>  'year',
                30 * 24 * 60 * 60       =>  'month',
                24 * 60 * 60            =>  'day',
                60 * 60                 =>  'hour',
                60                      =>  'minute',
                1                       =>  'second'
    );

    foreach( $condition as $secs => $str )
    {
        $d = $time_difference / $secs;

        if( $d >= 1 )
        {
            $t = round( $d );
            return 'about ' . $t . ' ' . $str . ( $t > 1 ? 's' : '' ) . ' ago';
        }
    }
}

while($result = $db->fetch_array($query))
{
    $id = $result['id'];
    $type = $result['type'];
    $author = $result['author'];
    $note = $result['note'];
    $platform = $result['platform'];
    $date = $result['date'];

    $type_color = "";

    if ($type = "new") {
        $type_color = "#5cd65c";
    } else if ($type = "fix") {
        $type_color = "#4d94ff";
    } else if ($type = "change") {
        $type_color = "#ffd480";
    } else if ($type = "rules") {
        $type_color = "#c266ff";
    } else if ($type = "delete") {
        $type_color = "#c266ff";
    }

    $url = file_get_contents("https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=823D1FBFF54E2BA06BE556C45C1A65FC&steamids=".$author); 
    $content = json_decode($url, true);
    
    $authorimg = $content['response']['players'][0]['avatar'];

    $changelist .= '<tr><td style="text-align:center; border-left: 5px solid' .$type_color. '
    " class="'.$altbg.'"><img src="'.$authorimg.'"/>
    <div style="width: 32px;
    height: 32px;
    background: black;
    border-radius: 6px;
    position: absolute;
    margin-top: -32px;
    margin-left: 30px;
    opacity: 0.4;"></div><div style="    position: absolute;
    padding: 0;
    margin: 0;
    color: white;
    width: 32px;
    margin-top: -25px;
    margin-left: 30px;
    text-align: center;
    font-size: 9pt;">#'.$id.'</div></td><td class="'.$altbg.'">'.$note.'</td><td style="text-align:center;" class="'.$altbg.'">'.$platform.'</td><td style="text-align:center;" class="'.$altbg.'">'.get_time_ago( strtotime("$date") ).'</td></tr>';
	$altbg = alt_trow();
    $num++;

    $db->free_result;
	   
}
 
add_breadcrumb("Changelog", "changelog.php");

$pagetemplate = "<html>
<head>
<title>".$settings['bbname']." - Changelog</title>
{$headerinclude}
<style type=\"text/css\">
.center{
	vertical-align: middle;
	text-align:center;
}

.new{
	background-color:#5cd65c;
}

.fix{
	background-color:#4d94ff;
}

.delete{
	background-color:#ff6666;
}

.change{
	background-color:#ffd480;
}

.rules{
	background-color:#c266ff;
}
</style>
</head>
<body>
{$header}
<div style=\"background:#ffffff; text-align: right;\">
				<span class=\"new\" style=\"color:white;padding:1px 4px;\">New</span>
				<span class=\"delete\" style=\"color:white;padding:1px 4px;\">Delete</span>
				<span class=\"fix\" style=\"color:white;padding:1px 4px;\">Fix</span>
				<span class=\"change\" style=\"color:white;padding:1px 4px;\">Change</span>
				<span class=\"rules\" style=\"color:white;padding:1px 4px;margin-right: 4px;\">Rules</span>
			</div>
<table border=\"0\" cellspacing=\"".$theme['borderwidth']."\" cellpadding=\"".$theme['tablespace']."\" class=\"tborder\">
	<thead>
		<tr>
			<td class=\"thead\" style=\"text-align: center;\" colspan=\"4\"><strong>ATHMOS CHANGELOG</strong></td>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td class=\"tcat\" width=\"5%\" style=\"text-align:center;\" ><strong>Author/Revision.</strong></td>
            <td class=\"tcat\" width=\"75%\"><strong>Note</strong></td>
            <td class=\"tcat\" width=\"10%\" style=\"text-align:center;\"><strong>Platform</strong></td>
            <td class=\"tcat\" width=\"10%\" style=\"text-align:center;\"><strong>Date</strong></td>
		</tr>
		{$changelist}
		<tr>
			<td class=\"tfoot\" colspan=\"2\"></td>
		</tr>
	</tbody>
</table>
{$footer}
</body>
</html>";

$pagetemplate = str_replace("\\'", "'", addslashes($pagetemplate));

eval("\$page = \"".$pagetemplate."\";");

output_page($page); 
?>
However I wanted to make it so it displays like 15 results or something like that per page I was wondering if anyone knew how todo this?

Thanks Smile
please see pagination guidance available here --> advanced plugin development
[section 2 - starting @ line 44]