Solved

Display MY SQL advanced Count in PHP

Posted on 2014-03-09
4
667 Views
Last Modified: 2014-03-09
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);
?>
0
Comment
Question by:ncomper
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 39916201
$result = mysqli_query($con, $query);

this will only run the query, and $result will not be the "number" of the count(*), but a resource identifier. after that line, you need to fetch the row into either an object or an array, so after that line, you will do:
http://php.net/mysqli_fetch_array
$result_data = mysqli_fetch_array($result);
echo $result_data[0]; 

Open in new window

0
 
LVL 58

Expert Comment

by:Gary
ID: 39916210
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

0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39916293
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!
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
0
 
LVL 5

Author Closing Comment

by:ncomper
ID: 39916331
Amazing thank you
0

Featured Post

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question