Checking whole table with strpos code

Hello,

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

$q6=mysql_query(‘SELECT * FROM banlinktable’);
$o6=mysql_fetch_object($q6);
$banurl=$o6->url;

if (strpos($newsubmitrul, $banurl) != FALSE)
{
exit;
}

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:

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

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:
[php]<?
$q = “SELECT * FROM banlinktable WHERE link = ‘$url’”;
$r = mysql_query($q);

$row_count = mysql_num_rows($r);

if($row_count == 0)
{
exit;
}
[/php]

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:

Sponsor our Newsletter | Privacy Policy | Terms of Service