Jump to content

[SOLVED] MYSQL query into PHP - Have tried for 2 hours


Dave3765

Recommended Posts

Hey,

 

I have spent the last few hours searching the forum and Google for the correct way to do this with no luck.

 

I am trying to use the COUNT function to search a table and simply echo a number.

 

I have what I think is a correct mysql query, but can't put this into php despite many (many, many) failed attempts.

 

SELECT COUNT(*) FROM items WHERE vis='Y'

 

If anyone is able to point me in the right direction it would be most appreciated.  :)

 

Thanks,

 

Dave

I am not sure exactly what I should be writing to get this number to display, and I have tried a ton of different ways with no luck.

 

Below is the closest I have to getting this number to display:

 

<?php

include('inc/dbconnect.inc');

  $pc_query = @mysql_query("SELECT COUNT(*) FROM items WHERE vis='Y'");
  $pc_fetch = mysql_fetch_array($pc_query);
  $productcount = htmlspecialchars($pc_fetch['name']);
  echo('<h1>' . $productcount . '</h1>');
  
?>

 

I don't know why the htmlspecialchars is there or what it does - I copied it from another section of my script.

 

Thanks

<?php

include('inc/dbconnect.inc');

  $pc_query = mysql_query("SELECT COUNT(*) AS rec_count FROM items WHERE vis='Y'") or die(mysql_error());
  $pc_fetch = mysql_fetch_array($pc_query);
  $productcount = $pc_fetch['rec_count'];
  echo('<h1>' . $productcount . '</h1>');
  
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.