TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
Stats
  • Total Posts: 196,004
  • Total Topics: 21,330
  • Online today: 367
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 55
  • Total: 55

Block as php

Started by arez, January 18, 2007, 11:00:53 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

arez

dont know where else to ask so sorry if its wrong here. i just wanted to ask how i can use block scripts as usual php scripts. i have tried it bit iam getting errors like
Fatal error: Call to undefined function: db_query()
(tried to include the top 10 posters could in a pgp script)

iam an absolute beginner and if this has been asked before, please redirect me because i didnt find anything while searching here.

thanks

IchBin

well, it sounds like you're doing something that is already done. No need to code it again, as I think its already built. :) As for the db_query(), its probably something like you have to include SSI.php for the db_query function available.

arez

my problem is that it works as a block but i want to have that block as an extra php script

jacortina

Then you need to be sure to pull in all the supporting code (through includes/requires) which is already in place when working WITHIN blocks. At the very least, I believe you'd want to start by including SSI.php.

arez

its very nice of you to support me with the nneded information.. sadly ian mot a coder and except some small modifications and  customations i have never done something like this before :o(

JPDeni

What is the code that you want to use? It's really hard to give generic "You need to do this" sort of instructions. I always compare trying to solve problems without having the information to trying to put a wristwatch together in the dark. I suppose it can be done, but it's a little difficult. :-)

So...

Post the code that you've used in a block and now want to use in a separate php file and we'll see if we can work out what changes you need to make.

arez

sorry, i thought there is a general thing you can do for this but maybe i can learn if you show me what to do with the top 10 poster cloud - code.
global $db_prefix;
$count= array();

$query = db_query(
    "SELECT posterName
     FROM {$db_prefix}messages
     ORDER BY posterTime DESC
     LIMIT 100", __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($query))
{
  if (!isset($count[$row['posterName']]))
    $count[$row['posterName']] = 0;
  ++$count[$row['posterName']];
}

$random = array_rand($count, count($count));
echo '<div style="text-align: center">';
foreach ($random as $value)
{
  $fsize = $count[$value] + 7;
  $name = str_replace(" ",'ÂÃ,·',$value);
  echo '<span style="font-size:' . $fsize . 'pt;">' . $name . '</span> ';
}
echo '</div>';


thanks

arez

JPDeni

It's best to tell us the specifics. If we can explain by talking about the general, that's cool, but often that's not the case and by telling us the specifics we know what you're talking about.

The db_query function includes a whole lot of stuff that you're going to have to hand-code, including a lot of stuff from your settings.php file.

This should work. I've used this structure before, although it's been quite a while. I've just used TP to connect to the database for months now.


<?php

$host 
'localhost'// this will probably work, but you might need to have something else, depending on your server
$user 'username'// your database username
$pw 'password'// your database password
$dbname 'dbname'// your database name

$link mysql_connect ($host$user$pw);
mysql_select_db('$dbname');

$query =  "SELECT posterName
     FROM smf_messages 
     ORDER BY posterTime DESC
     LIMIT 100"
;

$result mysql_db_query($dbname$query$link);
while (
$row mysql_fetch_assoc($result))
{
  if (!isset(
$count[$row['posterName']]))
    
$count[$row['posterName']] = 0;
  ++
$count[$row['posterName']];
}

$random array_rand($countcount($count));
echo 
'<div style="text-align: center">';
foreach (
$random as $value)
{
  
$fsize $count[$value] + 7
  
$name str_replace(" ",'ÂÃ,·',$value);
  echo 
'<span style="font-size:' $fsize 'pt;">' $name '</span> ';
}
echo 
'</div>';

?>



I haven't tested this, but I'm 97% sure it'll work. :)

To be completely honest, I'm not real thrilled with the idea of using the code I wrote outside of TP. I wrote it to be used within TP and that's where I would like to see it stay. I didn't say that it had to stay there, though, and since I gave you code to use it outside of TP, obviously I'm allowing it. I'm just saying that I would be happier if it stayed in TP.

jacortina

All that has to be done is toss the SSI include at the top of the code (this assumes that the script will reside in the forum's home directory; supply path to SSI, otherwise):


<?php
@include_once(dirname(__FILE__) . '/SSI.php');

global 
$db_prefix;
$count= array();

$query db_query(
   
"SELECT posterName
    FROM 
{$db_prefix}messages
    ORDER BY posterTime DESC
    LIMIT 100"
__FILE____LINE__);

while (
$row mysql_fetch_assoc($query))
{
 if (!isset(
$count[$row['posterName']]))
   
$count[$row['posterName']] = 0;
 ++
$count[$row['posterName']];
}

$random array_rand($countcount($count));
echo 
'<div style="text-align: center">';
foreach (
$random as $value)
{
 
$fsize $count[$value] + 7;
 
$name str_replace(" ",'Ã,·',$value);
 echo 
'<span style="font-size:' $fsize 'pt;">' $name '</span> ';
}
echo 
'</div>';
?>


JPDeni

QuoteAll that has to be done is toss the SSI include at the top of the code
Yes, you can do that, but it causes a whole lot more stuff to be put into memory than is necessary.


This website is proudly hosted on Crocweb Cloud Website Hosting.