NameSilo

MySQL / PHP Question

Spaceship Spaceship
Watch

freeflow

Established Member
Impact
13
How can I "echo" the result of the following mysql query?

PHP:
<?php

  $sql = "SELECT Link,\n"

    . "COUNT(Link) AS NumOccurrences\n"

    . "FROM Web2\n"

    . "GROUP BY Link\n"

    . "HAVING ( COUNT(Link) > 1 )";  

?>
Thanks for any help.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
PHP:
$result = mysql_query($sql);
if ($result)
{
    while ($item = mysql_fetch_object($result))
    {
        echo "Link: $item->Link, NumOccurrences: $item->NumOccurrences<br />\n";
    }
}
else
{
    echo 'MySQL error : ' . mysql_error(). "\n";
}
 
1
•••
$sql = "SELECT Link,\n"

. "COUNT(Link) AS NumOccurrences\n"

. "FROM Web2\n"

. "GROUP BY Link\n"

. "HAVING ( COUNT(Link) > 1 )";

Just a tip, since you are learning. Keep your code clean, this is very sloppy, and if you were writing wordpress plugins for example, they'd laugh at that, no offense. Just write it in one line. It took you twice the time to code that than it should have. Time is important in this business. Also, learn to wrap strings and such in single quotes, so yu do not have to backslash as often.

Code:
$sql = 'SELECT `Link`,COUNT(Link) AS NumOccurrences FROM `Web2` GROUP BY `Link` HAVING ( COUNT(Link) > 1 )';

Much easier to read and less time to code. Always put this at the end of your queries, or a custom error logging function...

Code:
 or die(mysql_error());
 
Last edited:
1
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back