Link to home
Start Free TrialLog in
Avatar of ncomper
ncomper

asked on

Display MY SQL advanced Count in PHP

Hi I have this PHP script below which works for a selcect count(*) from x

However when I put a more advanced MYSQL syntax in there it gives the following error"Notice: Undefined index: total in /var/www/dupe.php on line 12 Total ="

Any ideas






<?php
$con=mysqli_connect("localhost","ccc","N3wcccc21","actccccaign");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$query = "select count(*) from activecampaign.em_exclusion
Inner join activecampaign.em_subscriber
ON em_exclusion.email = em_subscriber.email";

$result = mysqli_query($con, $query);

echo $result;

mysqli_close($con);
?>
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Since there is no total in your sample code I'm going to assume you are not showing us the real code and expecting us to be psychic.

$query = "select count(*) as total from activecampaign.em_exclusion
Inner join activecampaign.em_subscriber
ON em_exclusion.email = em_subscriber.email"; 

$result = mysqli_query($con,$query);

$rows = mysqli_fetch_row($result );

echo $rows[0];

Open in new window

When in doubt, you can check the online man page for the return values from PHP functions.  Example: Ask yourself, "What is the expected return value from this function?"
http://php.net/manual/en/mysqli.query.php

Some learning resources to help you get started with things like this are available in this article.  Buy any of the books and give yourself a few weeks to read, study and practice.  In no time you'll be able to do this yourself!
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
Avatar of ncomper
ncomper

ASKER

Amazing thank you