PDA

View Full Version : help with while


sabret00the
05-11-2004, 12:23 PM
while ($project_info = $DB_site->fetch_array($projects))
{
$project_info['text'] = nl2br(stripslashes($project_info['text']));
extract($project_info);
$time_posted = vbdate('n-j-y, g:i:s a', $timestamp);
//where it started going wrong
$number_of_votes = $DB_site->query_first("SELECT COUNT(*)
FROM project_rate
WHERE projectid = $project_info[projectid]
");
$num_votes = number_format($DB_site->num_rows($number_of_votes));

can someone tell me what i'm doing wrong please? :nervous:

i'm now getting this error

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in K:\Network\xampp\htdocs\forums\includes\db_mysql.p hp on line 311

i never touched that file btw it went ok untill i started trying to extract data from the second table.

'project_rate' as the project_info extracts data from 'projects'

Xenon
05-11-2004, 12:32 PM
erm, you are running num_rows on a normal array (query_first's result is always an array, not a mysql result resource.

so the correcter version is:
while ($project_info = $DB_site->fetch_array($projects))
{
$project_info['text'] = nl2br(stripslashes($project_info['text']));
extract($project_info);
$time_posted = vbdate('n-j-y, g:i:s a', $timestamp);
//where it started going wrong
$number_of_votes = $DB_site->query_first("SELECT COUNT(*) AS votes
FROM project_rate
WHERE projectid = $project_info[projectid]
");
$num_votes = number_format($number_of_votes['votes']);

but stillt a query within a while loop, is not good ;)

sabret00the
05-11-2004, 12:51 PM
thanks xenon :D

i just tested this in phpmyadmin and it works fine, however in the project_bit template


<table class="tborder" cellpadding="5" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
<tr>
<td class="tcat">
project <a href="index.php?projectid=$projectid" class="projectid">$projectid</a> by confess[username]
</td>
</tr>
<tr>
<td valign="top" class="alt1">
$text
</td>
</tr>
<tr>
<td class="thead" align="right">
<smallfont><strong>$report $adminoptions $num_rates votes</strong></smallfont>
</td>
</tr>
</table>
it refuses to echo out.

NTLDR
05-11-2004, 12:59 PM
Because you have $num_rates and not $num_votes in the template?

sabret00the
05-11-2004, 01:07 PM
ahhhhhh, how stupid am i, i'm so so so so so sorry to waste your time :o

* sabret00the is might ashamed and embarrassed

sorry :o

NTLDR
05-11-2004, 01:11 PM
We've all done it, many a time ;)