...

View Full Version : Help! Split mysql into 2 columns (template tags)



Andrewc
08-19-2007, 08:10 AM
Help please!! Really struggling with this..

I know some of you guys can do this in your sleep ;)

I am a novice in PHP so excuse any noobish thing I might say.

My site uses a PHP template system, so it has a .php file and a .tpl template file.

Problem: I need the data being put into this template tag: {$list_items}
to be in two columns. Preferably {$list_items1} and {$list_items2}


Here is the list.php

<?php
// important files
require "./includes/functions.php";
require './includes/rare_funcs.php';

// get parameters
$cat_id = get_param ('cat_id');
$s = get_param ('s');
$o = get_param ('o');
$p = get_param ('p', 1);

// is there any childs?
$child_cats = 0;
for ($i = 1; $i <= $tmp_tbl['parent'][0]; $i++)
{
if ($tmp_tbl['parent'][$i] == $cat_id) $child_cats = 1;
}

// load tpl
$section = section_tpl ($config['skin']."/list_links.tpl");
$tpl = load_tpl ($config['skin']."/list.tpl");

// variables
$ipp = $config['link_perpage']; // ipp = items per page

// sort vars
$sortby[0] = "sort_point DESC, list_date DESC";
$sortby[1] = "title";
$sortby[2] = "list_date";
$sortby[3] = "avg_rating";
$sortby[4] = "ttl_clicks";
$sortorder[0] = '';
$sortorder[1] = "ASC";
$sortorder[2] = "DESC";

if (empty($o) || !array_key_exists($o, $sortorder)) $o = "0";
if (empty($s) || !array_key_exists($s, $sortby)) { $s = "0"; $o = "0"; }

// get total pages
$where = create_category_sql ($cat_id, 'OR');
$res = sql_query ("SELECT SUM(status='') AS total FROM deal_links WHERE $where");
$row = sql_fetch_array ($res);
$total = $row['total'];
$pages = ceil($total / $ipp); // number of pages of list

// verify vars
// if $p is not defined or $p > number_of_pages
if (empty ($p) or ($p > $pages) or ($p < 1)) $p = "1";
$start = ($p-1) * $ipp;

// create list of links under defined cat_id
$tmp = ''; $i = $start; $tmp_sp = array ();
$where = create_category_sql ($cat_id, 'OR');

$sql = "SELECT * FROM deal_links WHERE ($where) AND status='' ORDER BY sponsored DESC, _vaddbanner DESC, $sortby[$s] $sortorder[$o] LIMIT $start, $ipp";
$res = sql_query ($sql);
while ($row = sql_fetch_array ($res))
{
$i++; $k = 1; $row['status_flag'] = '';
$row['list_category'] = '';
$row['i'] = $i;
$row['list_date_shortdate'] = convert_date ($row['list_date'], 0);
$row['list_date_longdate'] = convert_date ($row['list_date'], 1);
$row['avg_rating_img'] = rating_img ($row['avg_rating']);
$row['note'] = line_wrap ($row['note'], $config['list_wrap']);

// new/updated links
if (diff_date ($row['list_date']) <= $config['link_newperiod']) $row['status_flag'] .= $lang['l_new_flag'];
if (diff_date ($row['last_update']) <= $config['link_updateperiod']) $row['status_flag'] .= $lang['l_update_flag'];
if ($row['editor_pick']) $row['status_flag'] .= $lang['l_editor_flag'];

// categories information
$tmp_cat = '';
for ($j = 1; $j <= $config['cat_multiple']; $j++)
{
$c = "category_$j";
$c = $row[$c];
if (!empty($c)) { $tmp_cat[$k] = where_am_i($c, 0); $k++; }
}

// sort category
reset ($tmp_cat);
asort ($tmp_cat);
while (list ($key, $val) = each ($tmp_cat)) $row['list_category'] .= "$val<BR>\n";

// custom fields
$custom = get_custom ($row);
$row = array_merge ($row, $custom);

if ($row['sponsored'])
$tmp_sp[] = quick_tpl (load_tpl ($section['list_sponsored']), $row);
else
$tmp .= quick_tpl (load_tpl ($section['list_common']), $row);
}

// randomize sponsored link spots
if (!empty ($tmp_sp))
{
shuffle ($tmp_sp);
$tmp = implode (' ', $tmp_sp).$tmp;
}

// sort & method select form
$txt['sort_select'] = create_select_form ('s', $sortby_nm, $s);
$txt['order_select'] = create_select_form ('o', $sortorder_nm, $o);

// previous & next page link
$pr = $p - 1;
$nx = $p + 1;

// generate list pages link
if ($p > 1)
$txt['prev'] = "<a href=\"list.php?cat_id=$cat_id&p=$pr&s=$s&o=$o\">".$lang['l_prev']."</a>";
else
$txt['prev'] = $lang['l_prev'];

if ($p < $pages)
$txt['next'] = "<a href=\"list.php?cat_id=$cat_id&p=$nx&s=$s&o=$o\">".$lang['l_next']."</a>";
else
$txt['next'] = $lang['l_next'];

$txt['list_pages_list'] = generate_pagination ("list.php?cat_id=$cat_id&s=$s&o=$o", $pages, $p);

// get keyword & description for HTML HEADER
$sql = "SELECT cat_note, cat_keywords FROM deal_category WHERE cat_id = '$cat_id' LIMIT 1";
$res = sql_query ($sql);
$row = sql_fetch_array ($res);

// generate list content
$txt['cat_note'] = $cat_note;
$txt['cat_id'] = $cat_id;
$txt['current_page'] = $p;
$txt['number_of_pages'] = $pages;
$txt['list_items'] = $tmp;
$txt['total_links'] = num_format ($total);

where_am_i ($cat_id, 1);
generate_category ('list', $cat_id);
generate_html_header ($row['cat_note'], $row['cat_note'], $row['cat_keywords']);

// flush output
$txt['cat_note'] = $row['cat_note'];
$txt['main_body'] = quick_tpl ($tpl, $txt);
flush_tpl ();

?>

StupidRalph
08-19-2007, 07:14 PM
I'm not sure what you expect. This doesn't tell us what the output of {$list_items} is once this code is ran. You need to be a bit more specific as to whats going on.

Andrewc
08-19-2007, 07:33 PM
Sorry!

The output of {$list_items} is a list of entries from the database. How it displays on the website is controlled by another template file.

So for example {$list_items} displays like this:

Name
Image | Description
link

Name
Image | Description
link

Name
Image | Description
link
___________
And so on..

I would like it to display as:


Name Name
Image | Description Image | Description
link link

Name Name
Image | Description Image | Description
link link
________________________

Does this help?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum