Blog

WordPress & MySQL – Query Database

Posted On:

Here $wpdb->get_results will fetch associative array of values ... multiple values

either you need to loop through each of them using

$sql = "SELECT * FROM wp_posts WHERE post_type='video'";
$results = $wpdb->get_results($sql) or die(mysql_error());    
if (count($results) > 0) {
    $display_row = null;
    foreach ($results as $res) {
         echo "id - " . $res->id;
    }
} 
or if you're expecting only one row, then try this

$result = $wpdb->get_row($sql);
echo "id - "$result->id;

CSS – Add icons to links

Posted On:

/* All Links */
 a[href $='.pdf'] { 
   padding-right: 18px;
   background: transparent url(icon_pdf.gif) no-repeat center right;
}

/* Specific Links */

.customPage li a[href $='.pdf'] { 
   margin: 3px 0px 3px -10px;
   background: transparent url(../templateimages/rebrand/pdf_icon.gif) no-repeat center left;
   
}

Javascript – Rotate content in a div

Posted On:

var secondsToDisplay = 2; //number often in seconds to rotate
			var theCounter = 0; //start the counter at 0

			// place your images, text, etc in the array elements here
			var CatalogueHTML = new Array();
			
		    CatalogueHTML[0]="Free Catalogue and Gift Pack<br \/><a href=\"\/-Pindar_OrderCatalogue.asp\" title=\"Order your catalogue today\"><img src=\"templateimages/content/CataloguePack.jpg\" width=\"120\" height=\"164\" border=\"0\" alt=\"Order your catalogue today\" vspace=\"5\" /><\/a><br /><div class=\"WhiteLinks\"><a href=\"/-Pindar_OrderCatalogue.asp\" title=\"Order your catalogue today\">Order Now&gt;&gt;<\/a><\/div>";
		    CatalogueHTML[1]="Download your Catalogue Now<br /><img src=\"\templateimages/content/mini_catalogue_cover.jpg\" vspace=\"5\" border=\"0\" height=\"166\" width=\"120\" alt=\"Click here to download your catalogue\">";
		
		
		
		
		function LoadCatalogue()
		{
			document.getElementById('CatalogueMiniBox').innerHTML = CatalogueHTML[theCounter];
		    theCounter = (theCounter==CatalogueHTML.length-1) ? 0 : theCounter + 1;
		    setTimeout("LoadCatalogue()",secondsToDisplay*1000);
		}
		
		
		</script>

SQL – Create a table if it doesn’t exist

Posted On:

strSQL="IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[TBLTempPrices]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1) CREATE TABLE [TBLTempPrices]( " &_
				"[VersionCode] [varchar](25) NULL," &_
				"[Quantity1] [int] NULL," &_
			"[Price1] [float] NULL," &_
			"[Quantity2] [int] NULL," &_
			"[Price2] [float] NULL," &_
			"[Quantity3] [int] NULL," &_
			"[Price3] [float] NULL," &_
			"[Quantity4] [int] NULL," &_
			"[Price4] [float] NULL," &_
			"[Quantity5] [int] NULL," &_
			"[Price5] [float] NULL," &_
			"[Quantity6] [int] NULL," &_
			"[Price6] [float] NULL)"

ASP – RegEx – Strip Special Characters from string

Posted On:

Function CleanURL(URLString)

	IF INSTR(URLString,"-")=>1 THEN
		URLString = Replace(URLString, "-","")
	END IF
	IF INSTR(URLString, " ")=>1 THEN
		URLString = Replace(URLString, " ", "-")
	END IF

		Set RegularExpressionObject = New RegExp
	With RegularExpressionObject
		.Pattern="[^a-zA-Z0-9\-\][:punct:]"
		.IgnoreCase = True
		.Global = True
	End With
	TempURL = RegularExpressionObject.Replace(URLString, "")
	
	IF INSTR(TempURL, "--")=>1 THEN
		TempURL = Replace(TempURL, "--", "")
	END IF
	IF Right(TempURL, 1)="-" THEN
		TempURL = Left(TempURL, Len(TempURL)-1)
	END IF
		CleanURL = TempURL

	Set RegularExpressionObject = nothing
End Function
		

strText = "This Is My $1000 Dollar URL-Baby, ""Yeah:""! 'Whoo' @ £ &"
Response.Write "Safe :"&CleanURL(strText)