Name.com Cyber Monday sale: $6.99 .com domains and more. Shop the sale.

MySQL Help

SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
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
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
mind posting the structure of both tables?
 
0
Close
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
Close
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
Close
Appraise.net

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

New: watch any domain
You can now watch domains on NamePros. We check each one and notify you when something changes. Search for a domain and press Watch on...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back