View Full Version : My PHP module - do not understand
phifou2
10-24-2005, 03:10 PM
Hello, I am newbie to vBadvanced. I can manage all the tuning tips except creating my own PHP Module. I need to print the result of a query to show last 5 classified ads in an other database.
My SQL query runs fine, I put it in a file called "show_last_ads.php" in Modules directory. If I run http://my_website/modules/show_last_ads.php I have the good result. If I try to include it in a module, it does not run.
So I began with the basics and tried to put this file this in a module Box :
<?
$variable = 'Hello';
print $variable;
?>
This simple thing does not run correctely. It prints "Hello" above the box title bar (see enclosed file). I do not understand, please help
Brian
10-24-2005, 03:48 PM
You just need to wrap <tr><td> and </td></tr> tags around your code.
phifou2
10-24-2005, 04:36 PM
Simple. Evident. Of course it runs well.
So I tried to change the PHP basic code with my query to other database :
<tr><td>
<?
$db = mysql_connect('localhost','login','password') or die ("connexion error");
//selecting database
mysql_select_db('my_datase',$db) or die ("Database error");
$sql = "SELECT ad.siteid, ad.sitetitle, category.catname FROM ad, category WHERE ad.sitecatid = category.catid AND ad.valid = '1' ORDER BY siteid DESC LIMIT 5";
// We send query
$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
//
while($data = mysql_fetch_array($req))
{
// Print info
echo ''.$data['catname'].' : <A HREF="http://my_website.com/detail.php?siteid='.$data['siteid'].'" target="blank">'.$data['sitetitle'].' ...</a></b><br>';
}
echo '<hr><table border="0" cellpadding="2" cellspacing="0" width="100%" bgcolor="#A8BCC5"> <tr> <td width="100%" align="right"><b>»» <a href="http://my_website.com" target="_blank">All classified ads</a></b></td></tr></table>';
?>
</td></tr>
I have a blank screen in return ...
But the PHP script runs well if I run it lonely as http://my_website/modules/show_last_ads.php
Gasp :(
Brian
10-24-2005, 04:43 PM
It may be something with vBulletin not liking that you're connecting to another database. Are those tables in the same database as vB, or can they be moved there if not? If they are or they could then you could just use vB's $db class for the queries and such.
zenithrs@bigpon
10-24-2005, 04:45 PM
Try setting "Clean File Output" to Yes.
Brian
10-24-2005, 04:48 PM
That should already be set to yes since he was getting the output in the proper place...
phifou2
10-24-2005, 05:06 PM
Yes, the "Clean File Output" is set on YES.
Will try to copy the tables in the vB database. Can you suggest me how to call properly vB's $db class for the queries ?
Thanks for all !
Brian
10-25-2005, 12:12 PM
<?
$db->query("SELECT ad.siteid, ad.sitetitle, category.catname FROM ad, category WHERE ad.sitecatid = category.catid AND ad.valid = '1' ORDER BY siteid DESC LIMIT 5");
while($data = $db->fetch_array($req))
{
// Print info
echo ''.$data['catname'].' : <A HREF="http://my_website.com/detail.php?siteid='.$data['siteid'].'" target="blank">'.$data['sitetitle'].' ...</a></b><br>';
}
echo '<hr><table border="0" cellpadding="2" cellspacing="0" width="100%" bgcolor="#A8BCC5"> <tr> <td width="100%" align="right"><b>»» <a href="http://my_website.com" target="_blank">All classified ads</a></b></td></tr></table>';
?>
phifou2
10-26-2005, 03:03 PM
Brian, Thank you very much.
I move the Ads tables to vB database but your last script did not run => it answered an empty block with only the last link to "All classified Ads"
BTW, my first script ran well now I have changed the calling to database $db by $daba... I think it was the conflict
Thank you for your interest
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.