Exclude result from MySQL query using multiple ID’s

//set parameter in mysql query
$query = “SELECT * FROM category WHERE published=1 and id not in (’11’,’22’,’33’)”;
//execute the query
$result = mysql_query($query);

Advertisements

Insert a php array into mysql table

Following code shows that how can insert php array into mysql table directly. Sometime we have big array data and need to insert in mysql table, in that case following code will helpful for you.

$array = array(
"a" => array("100","test1"),
"b" => array("200","test2"),
"c" => array("300","test3"),
);

foreach ($array as $key => $value) {
$a = $array[$key][0];
$b = $array[$key][1];
$query ="INSERT INTO tablename (key, field1, field2) VALUES ( '".$key."','". $a."','".$b."' )";
mysql_query($query);
}

Remove empty paragraph tags in php.

You can remove empty <p> tags from content using preg_replace function in php. For searching empty paragraph tags in content , we need to use regulars expression code.

See following example.

<?php

$string = '<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p><p></p>'; //content with empty paragraph
$string .= '<p>this paragraph has some content</p>';
$string .= '<p></p>'; //empty paragraph

echo 'string with empty paragraph tags';
echo $string;
echo '<hr/>';

$pattern = "/<p[^>]*><\\/p[^>]*>/"; // regular expression

echo 'string after remove paragraph tags';
echo preg_replace($pattern, '', $string);
?>

See More details about preg_replace() function.
http://php.net/manual/en/function.preg-replace.php