A Block I am working on

Post Reply

Topic author
hooplah
Active Member
Posts: 22
Joined: 16. September 2008 14:26

A Block I am working on

Post 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? ;)
User avatar

Kevin
Site Admin
Posts: 2989
Joined: 7. January 2006 20:11
phpBB.de User: Saint
phpBB.com User: Saint_hh
Location: Hamburg
Contact:

Re: A Block I am working on

Post by Kevin »

Set a

Code: Select all

<!-- BEGIN reviews_row -->
and the end statement in your template. ;)
~~~ They say the definition of madness is doing the same thing and expecting a different result ~~~

Kein Support per PN / No support via PM!

Topic author
hooplah
Active Member
Posts: 22
Joined: 16. September 2008 14:26

Re: A Block I am working on

Post by hooplah »

Thanks for the quick reply buddy. Works a treat. ;)

Topic author
hooplah
Active Member
Posts: 22
Joined: 16. September 2008 14:26

Re: A Block I am working on

Post 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

Topic author
hooplah
Active Member
Posts: 22
Joined: 16. September 2008 14:26

Re: A Block I am working on

Post 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)
User avatar

Kevin
Site Admin
Posts: 2989
Joined: 7. January 2006 20:11
phpBB.de User: Saint
phpBB.com User: Saint_hh
Location: Hamburg
Contact:

Re: A Block I am working on

Post 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'); 
~~~ They say the definition of madness is doing the same thing and expecting a different result ~~~

Kein Support per PN / No support via PM!

Superman
Active Member
Posts: 4
Joined: 24. October 2008 17:36

Re: A Block I am working on

Post by Superman »

This sounds like something I could use (see my topic in block requests). Is this something that will be released?

Topic author
hooplah
Active Member
Posts: 22
Joined: 16. September 2008 14:26

Re: A Block I am working on

Post 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. ;)

Superman
Active Member
Posts: 4
Joined: 24. October 2008 17:36

Re: A Block I am working on

Post 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. :)

digitales
Active Member
Posts: 4
Joined: 28. October 2008 14:43

Re: A Block I am working on

Post 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?
Post Reply

Return to “Modifications Support”