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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

<?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>');
  
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.