NameSilo

MySQL / PHP Question

SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
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
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
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
Close
$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
Close
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

New: watch any domain
You can now watch domains on NamePros. We check each one and notify you when something changes. Search for a domain and press Watch on...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back