[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Display MY SQL advanced Count in PHP

Posted on 2014-03-09
4
Medium Priority
?
673 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 2000 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 111

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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

649 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