Can anyone help with this query?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

Can anyone help with this query?

Post by ianhull »

Hi guys,

I am having trouble with this count query.

I have never worked with the count beofre and all I get returned is "Array".

Please help.

Code: Select all

<?php session_start();

$coursetitle = $_GET['coursetitle'];
$username = $_SESSION['username'];

include_once("includes/connect.php");
$sql = "SELECT COUNT(*) FROM course_content WHERE coursetitle='$coursetitle'"; 
$numrecords = mysql_query($sql) or die("Select Failed!");
$counter = mysql_fetch_array($numrecords);
?>
<?php echo $counter?>
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

not positive but try using mysql_num_rows()
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Code: Select all

$sql = "SELECT COUNT(*) FROM course_content WHERE coursetitle='$coursetitle'"; 
$numrecords = mysql_query($sql) or die("Select Failed!");
$count = mysql_result($numrecords,0);
or

Code: Select all

$sql = "SELECT COUNT(*) AS count FROM course_content WHERE coursetitle='$coursetitle'"; 
$numrecords = mysql_query($sql) or die("Select Failed!");
$counter = mysql_fetch_array($numrecords);
echo $counter['count'];
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply