Log in

View Full Version : troubles including a file


werwer
06-12-2002, 06:35 AM
hi all,

I installed vb 2.5 and wanted to include the file last.php in the header of my vb page.
The last.php file connects to a different database on my site and retrievs the last 7 records on it. The last.php file looks like:


<?

$dbservertypee="mysql";

$servernamee="localhost";
$dbusernamee="name";
$dbpasswordd="pass";

$dbnamee="db";

$urll="http://www.mysite.com";

$topicss = "7";


$db=mysql_connect($servername,$dbusername,$dbpassw ord);
mysql_select_db($dbname);

$query = "select * from table1 where catname='general'";
$queryresult = mysql_query($query);
$count = mysql_numrows($queryresult);




$query2 = "select * from table1 where catname='general' order by idnum desc limit 0,$topics";
$queryresult2 = mysql_query($query2);
$count2=mysql_numrows($queryresult2);

if ($count2 == "0") {
echo "No records";
}

else {

while($row = mysql_fetch_object($queryresult2)) {


echo "<tr>
<td width=\"20\" bgcolor=\"#F0F0F0\" align=\"center\">
<img border=\"0\" src=\"http://www.mysite.com/photos/new.gif\" width=\"12\" height=\"10\"></td>

<td bgcolor=\"#F0F0F0\" align=\"right\" onMouseOver=\"this.style.backgroundColor='#fffeff';this.style.cu rsor='hand';\"
onMouseOut=\"this.style.backgroundColor='#F0F0F0';\"
onClick=\"window.location.href='http://www.mysite.com/index.php?ct=general&md=details&id=$row->idnum'\">
<a href=\"$url/index.php?ct=general&md=details&id=$row->idnum\">$row->title</a></font></td>
<td bgcolor=\"#F0F0F0\" width=\"80\">
<p align=\"center\"><b><font size=\"2\">$row->field01</font></span></b></td>
</tr>
";


}

}

mysql_close();
?>


then I modyfy the phpinlude template as follows:

ob_start();
require("/path/last.php");
$last = ob_get_contents();
ob_end_clean();


this causes a seriuos problem in my forum and error msgs show up even before I put the &last variable in the header!!!

I have been trying to figure out what is going on, but failed to fix it.

Can anyone plz help me with this?! Any help is apreciated


thanx a lot

Admin
06-12-2002, 06:44 AM
Try changing:
mysql_close();
To:
mysql_close($db);

werwer
06-12-2002, 08:08 AM
I changed the code but still have the error msgs:

There seems to have been a slight problem with the forum database.
Please try again by pressing the refresh button in your browser.

An E-Mail has been dispatched to our Technical Staff, who you can also contact if the problem persists.

We apologise for any inconvenience.

Database error in vBulletin 2.2.5:

Invalid SQL: SELECT * FROM usergroup WHERE usergroupid=6
mysql error:

mysql error number:

Date: Wednesday 12th of June 2002 04:27:44 AM
Script: http://www.mysite.com/vb

Referer:

Invalid SQL: UPDATE session SET lastactivity=1023870464,location='/vb/' WHERE sessionhash='050c4ae41a96bb961812d4f6fa57a7bd'
mysql error:

mysql error number:

Date: Wednesday 12th of June 2002 04:27:44 AM
Script: http://www.mysite.com/vb
Referer:

important to mention that I have included some other files and everything wen just fine, I think the problem with the above code.

any sugestions?

Logician
06-15-2002, 09:51 PM
Why dont you run your query in global.php and instead of echoing the result right after the query, compile them with HTML code and assign all to a variable? Then you can insert the variable into header template.

I dont know why your code does not work but this method will work..

Admin
06-16-2002, 05:34 AM
Logician: Because he's using a different database, not vBulletin's.

Logician
06-16-2002, 06:51 AM
Originally posted by FireFly
Logician: Because he's using a different database, not vBulletin's.
Does it matter? He has "mysql_connect" command in his code so he is supposed to connect any db he likes.

His problem may be forgetting to switch back to vb db inside his own code. If his code runs before all other vb code (in the very begining of global.php), I guess it will work..

Admin
06-16-2002, 07:19 AM
He doesn't need to switch databases because vBulletin uses the $DB_site class, which specifies a connection ID for each query it issues. He can have 10 other connections open, it doesn't affect vB.

werwer
06-16-2002, 11:47 AM
Hi all,

thanx Logician and Firefly,

So guys what is wrong? I'm sure it's a correct php code! do you have any idea why it's not working?

and how can I try the global.php solution proposed here?

thanx

Logician
06-16-2002, 05:07 PM
I am not sure what your problem is but I know my solution will work (PROVIDED THAT your code is correct).

So what you have to is copy your code in the begining of file yourboard/global.php right AFTER line:

<?php


Then you have to edit your code so that it will NOT echo anything or send any information to the user. So delete all your echo commands. Instead of echoing while the code is parsed, put the information inside a variable like:

$my_variable.=" <td width=\"20\" bgcolor=\"#F0F0F0\" align=\"center\">";


$my_variable.="<a href=\"$url/index.php?ct=general&md=details&id=$row->idnum\">$row->title</a></font></td>";

etc.

then put $my_variable inside any template you like (header for you)

If you get "headers already sent error" after modification it means that while editing your code you miss a part which echos a text or sends a piece of information to user, so make sure to remove that part and this will do the trick.

Kenji Wing
02-23-2003, 01:16 AM
im trying to add my advertisement onto my forums

the code is only 2 lines

<?php

require "ad.php";

echo show_ad();

?>

at first i couldnt figure it out, and i just included the file in the main pages and it would give the header already recieved error

i tried adding it to the parsed php, but it has an echo in it, so that doesnt work

and when i tried what logician suggested above it gave me an db error.

is there any way to do this?
thanks

Kenji Wing
02-26-2003, 02:48 PM
is there anyone that would know how to include an echo file ontop of the header?

i would really like to know if anyone does.

Thanks!