Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 1433 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

PHP Problem

Thread title: PHP Problem
Closed Thread    
    Thread tools Search this thread Display Modes  
01-07-2007, 07:15 PM
#1
Alex Eyre is offline Alex Eyre
Alex Eyre's Avatar
Status: Designer
Join date: Aug 2006
Location: Manchester
Expertise:
Software:
 
Posts: 1,132
iTrader: 5 / 100%
 

Alex Eyre is on a distinguished road

Send a message via MSN to Alex Eyre

  Old  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
Paris Holley is offline Paris Holley
Status: Member
Join date: Dec 2005
Location:
Expertise:
Software:
 
Posts: 347
iTrader: 0 / 0%
 

Paris Holley is on a distinguished road

  Old

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
Paris Holley is offline Paris Holley
Status: Member
Join date: Dec 2005
Location:
Expertise:
Software:
 
Posts: 347
iTrader: 0 / 0%
 

Paris Holley is on a distinguished road

  Old

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
Paris Holley is offline Paris Holley
Status: Member
Join date: Dec 2005
Location:
Expertise:
Software:
 
Posts: 347
iTrader: 0 / 0%
 

Paris Holley is on a distinguished road

  Old

also here are some more pointers

most servers allow you to do
Code:
<?=$bgcolor ?>
instead of
Code:
<?php echo $bgcolor; ?>
that can save u some space in your file

01-07-2007, 07:30 PM
#5
Alex Eyre is offline Alex Eyre
Alex Eyre's Avatar
Status: Designer
Join date: Aug 2006
Location: Manchester
Expertise:
Software:
 
Posts: 1,132
iTrader: 5 / 100%
 

Alex Eyre is on a distinguished road

Send a message via MSN to Alex Eyre

  Old

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
Paris Holley is offline Paris Holley
Status: Member
Join date: Dec 2005
Location:
Expertise:
Software:
 
Posts: 347
iTrader: 0 / 0%
 

Paris Holley is on a distinguished road

  Old

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 == 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
Alex Eyre is offline Alex Eyre
Alex Eyre's Avatar
Status: Designer
Join date: Aug 2006
Location: Manchester
Expertise:
Software:
 
Posts: 1,132
iTrader: 5 / 100%
 

Alex Eyre is on a distinguished road

Send a message via MSN to Alex Eyre

  Old

thanks, made no difference
Alex.

01-07-2007, 07:37 PM
#8
Paris Holley is offline Paris Holley
Status: Member
Join date: Dec 2005
Location:
Expertise:
Software:
 
Posts: 347
iTrader: 0 / 0%
 

Paris Holley is on a distinguished road

  Old

whats wrong?

http://www.wiiroom.net/box.php seems to load for me, what are u trying to do?

01-07-2007, 07:37 PM
#9
Alex Eyre is offline Alex Eyre
Alex Eyre's Avatar
Status: Designer
Join date: Aug 2006
Location: Manchester
Expertise:
Software:
 
Posts: 1,132
iTrader: 5 / 100%
 

Alex Eyre is on a distinguished road

Send a message via MSN to Alex Eyre

  Old

Correction it worked like a dream thanks alot!

01-07-2007, 07:38 PM
#10
Paris Holley is offline Paris Holley
Status: Member
Join date: Dec 2005
Location:
Expertise:
Software:
 
Posts: 347
iTrader: 0 / 0%
 

Paris Holley is on a distinguished road

  Old

hehehe, np

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed