Checking whole table with strpos code



I have a problem now to check the whole table with this code… can someone please help me?

$q6=mysql_query(‘SELECT * FROM banlinktable’);

if (strpos($newsubmitrul, $banurl) != FALSE)

With this code it will only check the last inserted row, how can I check the whole banlinktable for the url?

$newsubmiturl is a new url posted by user and when it matched the $banurl from my database table banlinktable it will exit.


Try this:

$q6 = mysql_query(‘SELECT * FROM banlinktable’);
while ($o6 = mysql_fetch_object($q6)) {
if (strpos($newsubmiturl, $o6->url) !== false) {

Also, keep in mind that unless you’re using persistent connections, it’s NEVER a good idea to exit a PHP script without closing the MySQL connection.


Any reason you don’t write it like the following?

If so you could simply create something simple like:
$q = “SELECT * FROM banlinktable WHERE link = ‘$url’”;
$r = mysql_query($q);

$row_count = mysql_num_rows($r);

if($row_count == 0)

Not that it matters, same either way was just wondering.
As for the closing Mysql connections, its good practice to close them, but not needed as mysql will close the connection automatically.


I guess it depends on how you wish to implement the code, there’ll always be a better way :wink: