I have this SQL query which is working as it should when I run it into phpMyAdmin.
SELECT COUNT( * ) , LENGTH( Number ) AS Numbers
FROM `history_2015-07-22`
WHERE Number NOT LIKE '123%'
OR LENGTH( Number ) <50
GROUP BY Numbers
ORDER BY TIME = '2015-07-22 00:00:01' ASC
I want now to make a simple php page where I want to display the query results on the browser but I can't figure out how to echo it exactly. So i've made this:
$result = $pdo->prepare("SELECT COUNT( * ) , LENGTH( Number ) AS Numbers
FROM `history_2015-07-22`
WHERE Number NOT LIKE '123%'
OR LENGTH( Number ) <50
GROUP BY Numbers
ORDER BY TIME = '2015-07-22 00:00:01' ASC ");
$result->execute();
foreach ($result as $Numbers)
{
echo '<div class="container">
'.$Numbers['COUNT(*)'].'
'.$Numbers['LENGTH(Number)'].'
</div>';
}
What I want to echo is Count and Length.
I'm sure is something very simple what I miss but can't figure it out.
First, can you please explain what you're trying to do exactly with the SQL query?
From what I understand, you can try this:
$result = $pdo->prepare("SELECT COUNT( * ) AS ct_all, LENGTH( `Number` ) AS Numbers
FROM `history_2015-07-22`
WHERE `Number` NOT LIKE ('123%')
AND Numbers < 50
GROUP BY Numbers
ORDER BY `TIME` ASC");
$result->execute();
$results = $result->fetchAll();
foreach ($results as $row) {
echo '<div class="container">';
echo $row['ct_all'] . ' // ';
echo $row['Numbers'];
echo '</div>';
}
$result = $pdo->prepare("SELECT COUNT( * ) as cnts, LENGTH( Number ) AS num
FROM `history_2015-07-22`
WHERE Number NOT LIKE '123%'
OR LENGTH( Number ) <50
GROUP BY num
ORDER BY TIME = '2015-07-22 00:00:01' ASC ");
$result->execute();
foreach ($result as $Numbers)
{
echo '<div class="container">
'.$Numbers['cnts'].'
'.$Numbers['num'].'
</div>';
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With