Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

php/mysql phpmydamin server differances

Ok so Im using the following query

SELECT
    `inquiry_source`.`source` AS 'Source',
    `inquiry_source`.`colour` AS 'Colour',
    SUM(
        CASE WHEN `inquiry_source`.`source` = `customer_migration_details`.`Acquisition_Source` THEN 1 ELSE 0
        END
    ) AS 'count'
FROM  `inquiry_source`
    JOIN `customer_migration_details` 
            ON `customer_migration_details`.`Acquisition_Source` = `inquiry_source`.`source`
WHERE `date_opened` = '2023-01-23' AND `Acquisition_Source` != ''
GROUP BY `Acquisition_Source`

Which in phpMyAdmin show the following results

Source Colour count
Auto-Trader #cc0099 1
Ebay/tel #ffbb33 1
eShot #00b3b3 1
FaceBook #0044cc 11
Google #ff6666 3
Web #668cff 11

However when I come to the php as follows.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$sql= "SELECT
    `inquiry_source`.`source` AS 'Source',
    `inquiry_source`.`colour` AS 'Colour',
    SUM(
        CASE WHEN `inquiry_source`.`source` = `customer_migration_details`.`Acquisition_Source` THEN 1 ELSE 0
    END
    ) AS 'count'
FROM `inquiry_source`
    JOIN `customer_migration_details` 
        ON `customer_migration_details`.`Acquisition_Source` = `inquiry_source`.`source`
WHERE `date_opened` = '2023-01-23' AND `Acquisition_Source` != ''
GROUP BY `Acquisition_Source`";

$result = $conn->query($sql);

if ($result->num_rows > 0) {
  while($row = $result->fetch_assoc()) {
    foreach($row as $k => $v){
      if($k == 'Source'){
        $seriesData[] = "'{$v}'";
      }
    }
  }

return implode(',', $seriesData);

Its only returning the following (Missing out Auto-Trader)

Ebay/tel,
eShot,
FaceBook,
Google,
Web

Is there somthing I am missing?

I’ve tried changing the query, add various htmlentites(), htmlspecialchars(), addslashes() etc. but to no avail.

>Solution :

This line

while($row = $result->fetch_assoc()) {

returns one row from the resultset

Then this line returns the next

foreach($row as $k => $v){

So you read and ignored the first row of your resultset

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading