{"id":3667,"date":"2009-09-03T12:49:42","date_gmt":"2009-09-03T19:49:42","guid":{"rendered":"http:\/\/css-tricks.com\/?page_id=3667"},"modified":"2009-09-03T12:49:42","modified_gmt":"2009-09-03T19:49:42","slug":"return-only-one-variable-from-mysql-query","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/snippets\/php\/return-only-one-variable-from-mysql-query\/","title":{"rendered":"Return Only One Variable from MySQL Query"},"content":{"rendered":"

Function<\/h4>\n
function mysql_get_var($query,$y=0){\r\n       $res = mysql_query($query);\r\n       $row = mysql_fetch_array($res);\r\n       mysql_free_result($res);\r\n       $rec = $row[$y];\r\n       return $rec;\r\n}<\/code><\/pre>\n

Usage<\/h4>\n
$name = mysql_get_var(\"SELECT name from people where email = 'roger@freekrai.net'\");<\/code><\/pre>\n

Will return the name field, so what gets returned will be “Roger” (if that was my name in the database).<\/p>\n","protected":false},"excerpt":{"rendered":"

Function function mysql_get_var($query,$y=0){ $res = mysql_query($query); $row = mysql_fetch_array($res); mysql_free_result($res); $rec = $row[$y]; return $rec; } Usage $name = mysql_get_var(“SELECT name from people where email = ‘roger@freekrai.net'”); Will return the name field, so what gets returned will be “Roger” (if that was my name in the database).<\/p>\n","protected":false},"author":3,"featured_media":0,"parent":3233,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"page-snippet.php","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"c2c_always_allow_admin_comments":false,"footnotes":""},"tags":[],"acf":[],"jetpack-related-posts":[{"id":17757,"url":"https:\/\/css-tricks.com\/snippets\/css\/retina-display-media-query\/","url_meta":{"origin":3667,"position":0},"title":"Retina Display Media Query","date":"August 15, 2012","format":false,"excerpt":"For including high-res graphics, but only for screens that can make use of them. \"Retina\" being \"2x\": @media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) { \/* Retina-specific stuff here *\/ } Or other highish-res: \/* 1.25 dpr *\/ @media (-webkit-min-device-pixel-ratio: 1.25), (min-resolution: 120dpi){ \/* Retina-specific stuff here *\/ } \/* 1.3 dpr\u2026","rel":"","context":"With 72 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3995,"url":"https:\/\/css-tricks.com\/snippets\/php\/get-image-information\/","url_meta":{"origin":3667,"position":1},"title":"Get Image Information","date":"September 10, 2009","format":false,"excerpt":"\/* * @param string $file Filepath * @param string $query Needed information (0 = width, 1 = height, 2 = mime-type) * @return string Fileinfo *\/ function getImageinfo($file, $query) { if (!realpath($file)) { $file = $_SERVER[\"DOCUMENT_ROOT\"].$file; } $image = getimagesize($file); return $image[$query]; }","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":14603,"url":"https:\/\/css-tricks.com\/snippets\/wordpress\/make-archives-php-include-custom-post-types\/","url_meta":{"origin":3667,"position":2},"title":"Make Archives.php Include Custom Post Types","date":"October 15, 2011","format":false,"excerpt":"Archives.php only shows content of type 'post', but you can alter it to include custom post types. Add this filter to your functions.php file: function namespace_add_custom_types( $query ) { if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) { $query->set( 'post_type', array( 'post', 'nav_menu_item', 'your-custom-post-type-here' )); return $query; } }\u2026","rel":"","context":"With 104 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":163745,"url":"https:\/\/css-tricks.com\/snippets\/jquery\/get-query-params-object\/","url_meta":{"origin":3667,"position":3},"title":"Get Query Params as Object","date":"February 22, 2014","format":false,"excerpt":"Nicholas Ortenzio wrote this little plugin: jQuery.extend({ getQueryParameters : function(str) { return (str || document.location.search).replace(\/(^\\?)\/,'').split(\"&\").map(function(n){return n = n.split(\"=\"),this[n[0]] = n[1],this}.bind({}))[0]; } }); So if the URL is: http:\/\/codepen.io\/chriscoyier\/pen\/uszCr?lunch=sandwich&dinner=stirfry You can do: var queryParams = $.getQueryParameters(); And queryParams will be an object like: { \"lunch\": \"sandwich\", \"dinner\": \"stirfry\" }","rel":"","context":"With 21 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":16614,"url":"https:\/\/css-tricks.com\/snippets\/javascript\/lazy-loading-images\/","url_meta":{"origin":3667,"position":4},"title":"Lazy Loading Images","date":"March 27, 2012","format":false,"excerpt":"UPDATE: This is pretty old. If you're looking to lazy load images these days, I'd recommend looking at: The Complete Guide to Lazy Loading Images A Native Lazy Load for the Web Platform Tips for rolling your own lazy loading Use a blank.gif as the src of images, and include\u2026","rel":"","context":"In \"lazy loading\"","img":{"alt_text":"","src":"blank.gif","width":350,"height":200},"classes":[]},{"id":192714,"url":"https:\/\/css-tricks.com\/snippets\/sass\/luminance-color-function\/","url_meta":{"origin":3667,"position":5},"title":"Color Luminance Function","date":"January 9, 2015","format":false,"excerpt":"When digging deep into color theory, there is something called relative color luminance. To put it simply, the luminance of a color defines whether its brightness. A luminance of 1 means the color is white. On the opposite, a luminance score of 0 means the color is black. Knowing the\u2026","rel":"","context":"With 9 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3667"}],"collection":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/comments?post=3667"}],"version-history":[{"count":1,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3667\/revisions"}],"predecessor-version":[{"id":3668,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3667\/revisions\/3668"}],"up":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3233"}],"wp:attachment":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/media?parent=3667"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/tags?post=3667"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}