Unstoppable Domains

MySQL Help

Spacemail by SpaceshipSpacemail by Spaceship
Watch

jonambed

New Member
Impact
0
I have a table named forum that has a column called 'bid' and one called 'fid'. Both columns are all numbers. bid stands for board ID. My PHP code holds a bid var. I need to get all of the different 'fid' numbers depending on what my $bid var holds and then count all of the rows in another table called "poster" where the different "fid"s in the first table are equal to the "topicID"s in the second table. The end result would be a number.
_____________________________
What is the Best Acne Medicine
build muscle
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
.US domains.US domains
mind posting the structure of both tables?
 
0
•••
Here is a very very quick thing I just coded. It could be completely wrong and not what your looking for because I don't have time to put a lot of thought into it. Here:

PHP:
$bid = addslashes("YOUR BID VAR");

$sql_fid = mysql_query("SELECT fid FROM first_table_name WHERE bid='$bid'");
$total_rows = 0;

while($row = mysql_fetch_array($sql_fid)){
	$fid = $row["fid"];
	$sql_rows = mysql_query("SELECT * FROM poster WHERE topicID='$fid'");
	$num_rows = mysql_num_rows($sql_rows);
	$total_rows = $total_rows + $num_rows;
}
echo $total_rows;

Tell me how you get on with it or if you get any errors. You might need to modify some of it, maybe.
 
0
•••
You should be able to do this using single MySQL query, which will probably be more efficient than using multiple MySQL queries. Something like:

PHP:
$res = mysql_query("SELECT COUNT(*) AS total FROM forum, poster WHERE forum.bid='".intval($bid)."' AND forum.fid=poster.topicId");
if (! $res)
{
    echo "MySQL error: ".mysql_error();
}
else
{
    $row = mysql_fetch_object($res);
    $total = $row->total;
}
 
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Live Options
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back