/    Sign up×
Community /Pin to ProfileBookmark

Problem using Count() in a while loop

Im trying to get one of the coloumns in my table to output the number of presentations related to a meeting using the COUNT(). It works the only problem is that i want it to count for every meeting entry in the database. Because i use a while loop the loop continues and doesn’t end where before i put in this feature count() it outputed the data in the database and then finished. Any ideas?

[code=php]<?php

require_once(‘../../../classes/database.class.php’);

$database = new database();
$link_id = $database->database_connection();
$query = “select * from epc_meetings order by meetingid desc”;
$result = mysql_query($query) or die(mysql_error());
$total_rows = mysql_num_rows($result);
$file = mysql_fetch_array($result);
if (!$result)
{
print ‘There was a database error when executing’;
print mysql_error();
exit;
}

?>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
<title>EPC Website Administration: Meetings</title>
<link href=”../../css/epc_admin.css” rel=”stylesheet” type=”text/css” />
<script language=”JavaScript” type=”text/JavaScript”>
<!–
function BRB_PHP_DelWithCon(deletepage_url,field_name,field_value,messagetext) { //v1.0 – Deletes a record with confirmation
if (confirm(messagetext)==1){
location.href = eval(‘”‘+deletepage_url+’?’+field_name+’=’+field_value+'”‘);
}
}
//–>
</script>
<script src=”../../includes/sorttable.js”></script>
</head>

<body>
<div id=”heading”>
<h1><a href=”../index.php”>Website Adminstration</a>: Meetings</h1>
<img src=”../../images/!genric/epc2.jpg” width=”305″ height=”54″ />
<div class=”clear”></div>
</div>

<div id=”main”>
<p>[<a href=”upload.php”>Add a new meeting</a>]</p>
<?php if($total_rows == 0)
{ ?>
<p>There are currently no meeting entries in the database</p>
<?
}
if ($total_rows > 0) { ?>
<table border=”0″ cellpadding=”0″ cellspacing=”0″ class=”indexTable sortable” id=”indexTable”>
<tr>
<th scope=”col”>Event</th>
<th scope=”col”>Location</th>
<th scope=”col”>Year</th>
<th scope=”col”>Presentations</th>
<th colspan=”3″>Action</th>
</tr>
<?php do { ?>
<tr>
<td><?php print $file[‘event’]; ?></td>
<td><?php print $file[‘location’]; ?></td>
<td><?php print $file[‘year’]; ?></td>
<td>
<?php
$id = $file[‘meetingid’];
$database = new database();
$link_id = $database->database_connection();
$query = “select * from epc_meeting_presentations where meetingid = ‘$id'”;
$result = mysql_query($query) or die(mysql_error());
if (!$result)
{
print ‘There was a database error when executing’;
print mysql_error();
exit;
}
echo count($result);

?>
</td>
<td class=”narrow”><?php print ‘<a href=”edit_file.php?id=’.$file[‘meetingid’].'”>Edit</a>’; ?></td>
<td class=”narrow”><a href=”javascript:BRB_PHP_DelWithCon(‘delete.php’, ‘meetingid’,<?php echo $file[‘meetingid’];?>, ‘Are you sure you want to delete this entry?’);”>Delete</a></td>
<td class=”narrow”><?php print ‘<a href=”presentations/index.php?id=’.$file[‘meetingid’].'”>View Presentations</a>’; ?></td>
</tr>
<?php } while ($file = mysql_fetch_array($result)); ?>
</table>
<?php } ?>
<p>&nbsp;</p>
</div>
</body>
</html>
[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@chazzyOct 14.2005 — Are you trying to count the number of meetings in the database? Have you ever seen the count aggregate function in mysql?
Copy linkTweet thisAlerts:
@martinsandhuauthorOct 14.2005 — no im counting the number of presentations related to a specfic meeting. Yes i ahev heard of mysql COunt. Using SQL Count will only return a resource ID. Using PHP Count works and returns the value desired.Only problem is the loop wont end period.
×

Success!

Help @martinsandhu spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...