hi again. i am wanting to display the number of entries in database where the entry in blogID = $blogid
Hope that makes sence
Eric
Count the number of entries
Moderator: General Moderators
- ericburnard
- Forum Contributor
- Posts: 104
- Joined: Wed Jun 15, 2005 5:11 pm
- Location: Chesterfield, UK
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
- ericburnard
- Forum Contributor
- Posts: 104
- Joined: Wed Jun 15, 2005 5:11 pm
- Location: Chesterfield, UK
- ericburnard
- Forum Contributor
- Posts: 104
- Joined: Wed Jun 15, 2005 5:11 pm
- Location: Chesterfield, UK
aaahhhhhhh ive worked it out now.
Heres what i came up with it if anyone wants to know
Eric
Heres what i came up with it if anyone wants to know
Code: Select all
<?php
// Connecting, selecting database
mysql_connect('localhost', '*********', '*************')
or die('Could not connect: ' . mysql_error());
mysql_select_db('madashat_blog') or die('Could not select database');
$blogid = $_GET['blogid'];
$query = "SELECT * FROM comments where blogID = '$blogid'";
$result = mysql_query($query) or die(mysql_error().'<br />'.$query);
$number_of_rows = mysql_num_rows($result);
echo "$number_of_rows";
?>- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
If you're looking for a speed increase use MySQL as much as possible. No need to use PHP when it can be done in the query...ericburnard wrote:aaahhhhhhh ive worked it out now.
Heres what i came up with it if anyone wants to know
EricCode: Select all
<?php // Connecting, selecting database mysql_connect('localhost', '*********', '*************') or die('Could not connect: ' . mysql_error()); mysql_select_db('madashat_blog') or die('Could not select database'); $blogid = $_GET['blogid']; $query = "SELECT * FROM comments where blogID = '$blogid'"; $result = mysql_query($query) or die(mysql_error().'<br />'.$query); $number_of_rows = mysql_num_rows($result); echo "$number_of_rows"; ?>
Code: Select all
<?php
// Connecting, selecting database
mysql_connect('localhost', '*********', '*************')
or die('Could not connect: ' . mysql_error());
mysql_select_db('madashat_blog') or die('Could not select database');
$blogid = $_GET['blogid'];
$query = "SELECT count(*) FROM comments where blogID = '$blogid'";
$result = mysql_query($query) or die(mysql_error().'<br />'.$query);
$number_of_rows = mysql_result($result, 0, 0);
echo "$number_of_rows";
?>- ericburnard
- Forum Contributor
- Posts: 104
- Joined: Wed Jun 15, 2005 5:11 pm
- Location: Chesterfield, UK
It's done this way.
Code: Select all
<?php
// Connecting, selecting database
mysql_connect('localhost', '*********', '*************')
or die('Could not connect: ' . mysql_error());
mysql_select_db('madashat_blog') or die('Could not select database');
$blogid = $_GET['blogid'];
$query = "SELECT count(*) AS total FROM comments where blogID = '$blogid'";
$result = mysql_query($query) or die(mysql_error().'<br />'.$query);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$number_of_rows = $row['total'];
echo "$number_of_rows";
?>