Jump to content

2 $Rows?


Solar

Recommended Posts

<?php
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_name="login"; // Database name 
$tbl_name="forum_titles"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name WHERE cat='general' ORDER BY fid";
// OREDER BY id DESC is order result by descending 
$result=mysql_query($sql);

$link = mysql_connect("localhost", "root", "");
mysql_select_db("login", $link);
$result2 = mysql_query("SELECT fid FROM forum_question WHERE fid='$fid'", $link);
$num_rows = mysql_num_rows($result2);
?>
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td width="53%" align="center" bgcolor="#E6E6E6"><strong>General</strong></td>
</tr>
<?php
while($rows = mysql_fetch_array($result, $result2) ){ // Start looping table row 
?>
<tr>
<td bgcolor="#FFFFFF">
<a href="forums.php?forum=<? echo $rows['fid']; ?>">
<? echo $rows['forum']; ?></a><BR><span class="style1">
<? echo $rows['desc']; ?> - <?php echo "$num_rows"; ?>
</span>
</td>
</tr>

<?php
// Exit looping and close connection 
}
mysql_close();
?>

 

What I would like to do is have database-forum_question (Forum Topics) Show how many topics are in that specific database-forum_title (Forum Name). So That being said. My databases look like this;

 

Database Forum_Title

fidforumdesccat

1GeneralBlah Blah...1

2SupportBlah Blah...2

 

Database Forum_Question

idfidquestiondetailcat

11General TestBlah Blah...1

22Support TestBlah Blah...2

 

 

What I want; For example;

 

General - 4 Topics

Support - 2 Topics

Anything - 0 Topics

 

I think I am on the right track.. But I know for sure that this following doesn't help.

while($rows = mysql_fetch_array($result, $result2) ){ // Start looping table row 

 

How would I be able to fix this up?

*There is no error, it just results as Zero as the two databases aren't connecting properly*

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.