Page 1 of 1

A Block I am working on

Posted: 23. October 2008 13:13
by hooplah
A little guidance please.

i have created this in the portal/blocks folder called reviews.php

Code: Select all

// how many rows to show per page
$rowsPerPage = 2;

// by default we show first page
$pageNum = 1;

// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
	$pageNum = $_GET['page'];
}

// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;

$query  = "SELECT * FROM phpbb_reviews LIMIT $offset, $rowsPerPage";

$result = mysql_query($query) or die('Error, query failed');

// print the results in a table

while($list = mysql_fetch_array($result))
  {
  
	$template->assign_block_vars('reviews_row', array(
		'R_TITLE'				=> $list['title'],
		'R_REVIEW'			=> $list['review'],
		'R_INFO'				=> $list['info'],
		'R_IMAGE'				=> $list['image'],
		'R_LINK'				=> $list['link'],
		'R_ED2K'				=> $list['ED2K']
		)
	);
	
	}
this to output the results in styles/portal/blocks

Code: Select all

<!--version $Id: reviews.html 321 2008-08-17 10:17:11Z kevin74 $ //-->
<table width='100%' border='1'> 
    <tr> 
    <td colspan='3'> 
    <div align='center'>{reviews_row.R_TITLE}</div> 
    </tr> 
    
   <tr>
     <td width='25%'>&nbsp;</td>
     <td width='3%'>&nbsp;</td>
     <td width='72%'>Review</td>
   </tr>
   <tr> 
    <td>{reviews_row.R_TITTLE}</td>
   <td>&nbsp;</td>
    
    <td>{reviews_row.R_REVIEW}</td> 
    </tr> 
    
   <tr>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
   </tr>
   <tr> 
    <td> 
    </td>
   <td>&nbsp;</td>
    
    <td>{reviews_row.R_INFO}</td> 
    </tr> 
   
    
   <tr>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
   </tr>
   <tr> 
    <td><a href="{reviews_row.R_LINK}">Board Link</a></td>
   <td>&nbsp;</td>
    
   <td><a href="{link.URL}" title="{link.TEXT}">{link.TEXT}</a></td>
    <td>{R_ED2K}</td>
   </tr> 
  
   
 </table>
 
added the following to portal.php

Code: Select all

		include($phpbb_root_path . 'portal/block/reviews.'.$phpEx);
included the file in the portal_body.html

The table shows on the portal but not the variables. What have i missed please? ;)

Re: A Block I am working on

Posted: 23. October 2008 13:27
by Kevin
Set a

Code: Select all

<!-- BEGIN reviews_row -->
and the end statement in your template. ;)

Re: A Block I am working on

Posted: 23. October 2008 13:37
by hooplah
Thanks for the quick reply buddy. Works a treat. ;)

Re: A Block I am working on

Posted: 23. October 2008 21:37
by hooplah
what is the best and safest way to run the sql for this block, i know there are built in db connections and certain ways to query the database.

I have two queries;

1. the alternative to the way i tested this I believe I don't require.

Code: Select all


$con = mysql_connect("localhost","root","");

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  
  
  }
  
  mysql_select_db("sharessoul", $con);
2. how would i format this qurey?

Code: Select all


$offset = ($pageNum - 1) * $rowsPerPage;

$query  = "SELECT * FROM phpbb_reviews LIMIT $offset, $rowsPerPage";

$result = mysql_query($query) or die('Error, query failed');



while($list = mysql_fetch_array($result))
  {
  
	$template->assign_block_vars('reviews_row', array(
		'R_TITLE'				=> $list['title'],
		'R_REVIEW'			=> $list['review'],
		'R_INFO'				=> $list['info'],
		'R_IMAGE'				=> $list['image'],
		'R_LINK'				=> $list['link'],
		'R_ED2K'				=> $list['ED2K']
		)
	);
these two variables are used elsewhere to provide paging elsewhere, many thanks for your help. :D

Re: A Block I am working on

Posted: 24. October 2008 10:48
by hooplah
tried the following to connect

Code: Select all

$offset = ($pageNum - 1) * $rowsPerPage;

$sql  = "SELECT * FROM phpbb_reviews LIMIT $offset, $rowsPerPage";

$result = $db->sql_query($sql);
got this error

Code: Select all

[phpBB Debug] PHP Notice: in file /portal/block/reviews.php on line 14: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Could not connect: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

Re: A Block I am working on

Posted: 24. October 2008 20:34
by Kevin
I would try this:

Code: Select all

$offset = ($pageNum - 1) * $rowsPerPage;

$sql = 'SELECT *
    FROM ' . REVIEWS_TABLE . '
$result = $db->sql_query_limit($sql, $offset);
and add to the includes/constants.php

Code: Select all

define('REVIEWS_TABLE',                $table_prefix . 'reviews'); 

Re: A Block I am working on

Posted: 25. October 2008 19:27
by Superman
This sounds like something I could use (see my topic in block requests). Is this something that will be released?

Re: A Block I am working on

Posted: 27. October 2008 15:39
by hooplah
Sorted it thanks Kevin.

I hadn't thought about releasing this block but if there is interest then I could release it once completed.

Will give you more info about it when I get a working version finished. ;)

Re: A Block I am working on

Posted: 28. October 2008 01:01
by Superman
That would be great. here is what I am looking for (as posted in another topic)

I'm relaunching my site and it will be geared to A/V and HD related topics. Some of that is going to be Blu-Ray movie reviews. What I would like is a simple block of recent topics, but only pointing to one particular forum (in this case, the forum for the Blu-Ray reviews). I have that forum set to display in the News blocks, but often they don't stay up very long due to the other news being posted throughout the day. A dedicated block would be helpful.

You can view my site here.

It sounds like the same thing you are trying to do. If you can get it to work and would be willing to share, that would be great. Thanx. :)

Re: A Block I am working on

Posted: 28. October 2008 18:56
by digitales
This might suit my needs too. Can you tell me how it looks when installed? I need to have a Recent Topic block that displays topics from the whole forum, but also an additional Recent Topic block that pulls topics from one forum. Is that the general idea of this block?