|
|
|
|
Thread title: PHP Problem |
|
|
|
|
|
Thread tools
Search this thread
Display Modes
|
|
01-07-2007, 07:15 PM
|
#1
|
Status: Designer
Join date: Aug 2006
Location: Manchester
Expertise:
Software:
Posts: 1,132
|
PHP Problem
Hi everyone,
I am trying to get the latest threads to show on this page, but it is failing as you can see:
http://www.wiiroom.net/box.php
For some reason nothing is displaying
Please see if you can spot anything.
and heres the code:
Code:
<?php
$rel = "forum/"; // The directory to your forum--relative to this file's location; include ending slash
chdir($rel);
$host = "localhost"; // Your database host
$user = "****"; // Your database username
$pass = "***"; // Your database password
$data = "wiiroom_board"; // The name of your database
$prfx = "mybb_"; // The table prefix of your database
$col1 = "#FFFFFF"; // The color of the first row--alternating row colours
$col2 = "#FCFCFC"; // The color of the second row
// NOTE: I didn't include ./global.php because I wasn't sure what the variables look like.
$num = 5; // The number of recent posts to show
$author = TRUE; // Should we display the post author? (TRUE or FALSE)
$conn = mysql_connect($host,$user,$pass) or die("<b>Error:</b> Database connection failed.");
$sel = mysql_select_db($data,$conn) or die("<b>Error:</b> Database connection failed.");
if($author == TRUE)
{
?>
<table>
<?php
}
$i = 0;
$q = mysql_query("SELECT * FROM ".$prfx."posts ORDER BY dateline DESC LIMIT ".$num);
while($row = mysql_fetch_array($q))
{
if($i % 2 == 0)
{
$bgcolor = $col1;
}
else
{
$bgcolor = $col2;
}
$i++;
$q2 = mysql_query("SELECT * FROM ".$prfx."forums WHERE fid = '".$row["fid"]."';");
$row = mysql_fetch_array($q2);
?>
<tr>
<td width="50%" bgcolor="<?php echo $bgcolor; ?>">
<a title="In forum: <?php echo $row["name"]; ?>" href="<?php echo $rel; ?>showthread.php?tid=<?php echo $row["tid"]; ?>&action=lastpost">
<b><?php echo $row["subject"]; ?></b></a></p></td>
<?php
if($author == TRUE)
{
?>
<td width="50%" bgcolor="<?php echo $bgcolor; ?>">by
<b><a title="<?php echo $row["username"]; ?>'s Profile" href="<?php echo $rel; ?>member.php?action=profile&uid=<?php echo $row["uid"]; ?>">
<?php echo $row["username"]; ?></b></a></td>
<?php
}
?>
</tr>
<?php
}
?>
</table>
Alex.
|
|
01-07-2007, 07:21 PM
|
#2
|
Status: Member
Join date: Dec 2005
Location:
Expertise:
Software:
Posts: 347
|
try renaming your variables, it seems you have the post information in $row originally
Code:
while($row = mysql_fetch_array($q))
then you are replacing it with what looks to be the forum information
Code:
$row = mysql_fetch_array($q2);
rename the second variable and you should be good
|
|
01-07-2007, 07:23 PM
|
#3
|
Status: Member
Join date: Dec 2005
Location:
Expertise:
Software:
Posts: 347
|
also it would probably help if you combined those queries
Code:
SELECT p.*,f.* FROM ".$prfx."posts p LEFT JOIN ".$prfx."forums f ON f.fid=p.fid ORDER BY p.dateline DESC LIMIT ".$num
that will grab both of the information at once, instead of running multiple queries, however u may only want to select certain fields from the forums table so it doesn't overwrite anything in the posts table
Code:
SELECT p.*,f.forumdid,f.name FROM ".$prfx."posts p LEFT JOIN ".$prfx."forums f ON f.fid=p.fid ORDER BY p.dateline DESC LIMIT ".$num
etc..
|
|
01-07-2007, 07:27 PM
|
#4
|
Status: Member
Join date: Dec 2005
Location:
Expertise:
Software:
Posts: 347
|
also here are some more pointers
most servers allow you to do
instead of
Code:
<?php echo $bgcolor; ?>
that can save u some space in your file
|
|
01-07-2007, 07:30 PM
|
#5
|
Status: Designer
Join date: Aug 2006
Location: Manchester
Expertise:
Software:
Posts: 1,132
|
could you add those corrections into the document please, cause I think Ive done it wrong :P
Alex.
|
|
01-07-2007, 07:32 PM
|
#6
|
Status: Member
Join date: Dec 2005
Location:
Expertise:
Software:
Posts: 347
|
try this
PHP Code:
<?php
$rel = "forum/"; // The directory to your forum--relative to this file's location; include ending slash
chdir($rel);
$host = "localhost"; // Your database host
$user = "****"; // Your database username
$pass = "***"; // Your database password
$data = "wiiroom_board"; // The name of your database
$prfx = "mybb_"; // The table prefix of your database
$col1 = "#FFFFFF"; // The color of the first row--alternating row colours
$col2 = "#FCFCFC"; // The color of the second row
// NOTE: I didn't include ./global.php because I wasn't sure what the variables look like.
$num = 5; // The number of recent posts to show
$author = TRUE; // Should we display the post author? (TRUE or FALSE)
$conn = mysql_connect($host,$user,$pass) or die("<b>Error:</b> Database connection failed.");
$sel = mysql_select_db($data,$conn) or die("<b>Error:</b> Database connection failed.");
if($author == TRUE)
{
?>
<table>
<?php
}
$i = 0;
$q = mysql_query("SELECT p.*,f.* FROM ".$prfx."posts p LEFT JOIN ".$prfx."forums f on f.fid=p.fid ORDER BY p.dateline DESC LIMIT ".$num);
while($row = mysql_fetch_array($q))
{
if($i % 2 == 0)
{
$bgcolor = $col1;
}
else
{
$bgcolor = $col2;
}
$i++;
?>
<tr>
<td width="50%" bgcolor="<?php echo $bgcolor; ?>">
<a title="In forum: <?php echo $row["name"]; ?>" href="<?php echo $rel; ?>showthread.php?tid=<?php echo $row["tid"]; ?>&action=lastpost">
<b><?php echo $row["subject"]; ?></b></a></p></td>
<?php
if($author == TRUE)
{
?>
<td width="50%" bgcolor="<?php echo $bgcolor; ?>">by
<b><a title="<?php echo $row["username"]; ?>'s Profile" href="<?php echo $rel; ?>member.php?action=profile&uid=<?php echo $row["uid"]; ?>">
<?php echo $row["username"]; ?></b></a></td>
<?php
}
?>
</tr>
<?php
}
?>
</table>
^updated
|
|
01-07-2007, 07:36 PM
|
#7
|
Status: Designer
Join date: Aug 2006
Location: Manchester
Expertise:
Software:
Posts: 1,132
|
thanks, made no difference
Alex.
|
|
01-07-2007, 07:37 PM
|
#8
|
Status: Member
Join date: Dec 2005
Location:
Expertise:
Software:
Posts: 347
|
|
|
01-07-2007, 07:37 PM
|
#9
|
Status: Designer
Join date: Aug 2006
Location: Manchester
Expertise:
Software:
Posts: 1,132
|
Correction it worked like a dream thanks alot!
|
|
01-07-2007, 07:38 PM
|
#10
|
Status: Member
Join date: Dec 2005
Location:
Expertise:
Software:
Posts: 347
|
|
|
|
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
|