{"id":3637,"date":"2015-10-12T22:30:29","date_gmt":"2015-10-12T21:30:29","guid":{"rendered":"https:\/\/blog.ed.gs\/?p=3637"},"modified":"2015-10-12T22:30:29","modified_gmt":"2015-10-12T21:30:29","slug":"mysqli_result-function-php55-php7","status":"publish","type":"post","link":"https:\/\/ed.gs\/2015\/10\/12\/mysqli_result-function-php55-php7\/","title":{"rendered":"mysqli_result() Function PHP5.5+ & PHP7"},"content":{"rendered":"

REFERENCED FROM: http:\/\/mariolurig.com\/coding\/mysqli_result-function-to-match-mysql_result\/<\/a><\/strong><\/p>\n

In PHP 5.5 and above the MySQL functions are deprecated and have been\u00a0removed PHP7. The recommendation is to switch to MySQLi or use the PDO MySQL extension. The following code will replicate the mysql_result code from previous versions of PHP.<\/p>\n

“Quick review: mysql_result() is used to write less code when your database query is returning only a single row (LIMIT 1) and\/or a single column.”<\/em><\/p>\n

Old code, PHP 5.4 and below:<\/strong><\/p>\n

$output = mysql_result($result,0);<\/pre>\n

To replicate this in MySQLi, the following function can be used:<\/strong><\/p>\n

function mysqli_result($res,$row=0,$col=0){\n    $numrows = mysqli_num_rows($res);\n    if ($numrows && $row <= ($numrows-1) && $row >=0){\n        mysqli_data_seek($res,$row);\n        $resrow = (is_numeric($col)) ? mysqli_fetch_row($res) : mysqli_fetch_assoc($res);\n        if (isset($resrow[$col])){\n            return $resrow[$col];\n        }\n    }\n    return false;\n}<\/pre>\n

“It has one improvement over mysql_result(), which is you can choose to only include the resource and no row and\/or column. It will just assume mysqli_result($resource,0,0).”<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"

REFERENCED FROM: http:\/\/mariolurig.com\/coding\/mysqli_result-function-to-match-mysql_result\/ In PHP 5.5 and above the MySQL functions are deprecated and have been\u00a0removed PHP7. The recommendation is to switch to MySQLi or use the PDO MySQL extension. The following code will replicate the mysql_result code from previous versions of PHP. “Quick review: mysql_result() is used to write less code when your database […]<\/p>\n","protected":false},"author":2,"featured_media":3624,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ep_exclude_from_search":false},"categories":[45,53],"tags":[],"yoast_head":"\nmysqli_result() Function PHP5.5+ & PHP7 - E<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ed.gs\/2015\/10\/12\/mysqli_result-function-php55-php7\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"mysqli_result() Function PHP5.5+ & PHP7 - E\" \/>\n<meta property=\"og:description\" content=\"REFERENCED FROM: http:\/\/mariolurig.com\/coding\/mysqli_result-function-to-match-mysql_result\/ In PHP 5.5 and above the MySQL functions are deprecated and have been\u00a0removed PHP7. The recommendation is to switch to MySQLi or use the PDO MySQL extension. The following code will replicate the mysql_result code from previous versions of PHP. “Quick review: mysql_result() is used to write less code when your database […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ed.gs\/2015\/10\/12\/mysqli_result-function-php55-php7\/\" \/>\n<meta property=\"og:site_name\" content=\"E\" \/>\n<meta property=\"article:published_time\" content=\"2015-10-12T21:30:29+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/static.ed.gs\/wp-content\/uploads\/2015\/10\/236H.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"2048\" \/>\n\t<meta property=\"og:image:height\" content=\"1365\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Ed\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ed\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ed.gs\/2015\/10\/12\/mysqli_result-function-php55-php7\/\",\"url\":\"https:\/\/ed.gs\/2015\/10\/12\/mysqli_result-function-php55-php7\/\",\"name\":\"mysqli_result() Function PHP5.5+ & PHP7 - E\",\"isPartOf\":{\"@id\":\"https:\/\/ed.gs\/#website\"},\"datePublished\":\"2015-10-12T21:30:29+00:00\",\"dateModified\":\"2015-10-12T21:30:29+00:00\",\"author\":{\"@id\":\"https:\/\/ed.gs\/#\/schema\/person\/d775615f2296ad0129fa3ea66346c628\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/ed.gs\/2015\/10\/12\/mysqli_result-function-php55-php7\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/ed.gs\/#website\",\"url\":\"https:\/\/ed.gs\/\",\"name\":\"E\",\"description\":\"automation, consultancy, project management, web\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/ed.gs\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/ed.gs\/#\/schema\/person\/d775615f2296ad0129fa3ea66346c628\",\"name\":\"Ed\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/ed.gs\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4fe1dfaed09e6bdceb557d3008f5cc47?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4fe1dfaed09e6bdceb557d3008f5cc47?s=96&d=mm&r=g\",\"caption\":\"Ed\"},\"url\":\"https:\/\/ed.gs\/author\/ed\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"mysqli_result() Function PHP5.5+ & PHP7 - E","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ed.gs\/2015\/10\/12\/mysqli_result-function-php55-php7\/","og_locale":"en_GB","og_type":"article","og_title":"mysqli_result() Function PHP5.5+ & PHP7 - E","og_description":"REFERENCED FROM: http:\/\/mariolurig.com\/coding\/mysqli_result-function-to-match-mysql_result\/ In PHP 5.5 and above the MySQL functions are deprecated and have been\u00a0removed PHP7. The recommendation is to switch to MySQLi or use the PDO MySQL extension. The following code will replicate the mysql_result code from previous versions of PHP. “Quick review: mysql_result() is used to write less code when your database […]","og_url":"https:\/\/ed.gs\/2015\/10\/12\/mysqli_result-function-php55-php7\/","og_site_name":"E","article_published_time":"2015-10-12T21:30:29+00:00","og_image":[{"width":2048,"height":1365,"url":"https:\/\/static.ed.gs\/wp-content\/uploads\/2015\/10\/236H.jpg","type":"image\/jpeg"}],"author":"Ed","twitter_misc":{"Written by":"Ed","Estimated reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/ed.gs\/2015\/10\/12\/mysqli_result-function-php55-php7\/","url":"https:\/\/ed.gs\/2015\/10\/12\/mysqli_result-function-php55-php7\/","name":"mysqli_result() Function PHP5.5+ & PHP7 - E","isPartOf":{"@id":"https:\/\/ed.gs\/#website"},"datePublished":"2015-10-12T21:30:29+00:00","dateModified":"2015-10-12T21:30:29+00:00","author":{"@id":"https:\/\/ed.gs\/#\/schema\/person\/d775615f2296ad0129fa3ea66346c628"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ed.gs\/2015\/10\/12\/mysqli_result-function-php55-php7\/"]}]},{"@type":"WebSite","@id":"https:\/\/ed.gs\/#website","url":"https:\/\/ed.gs\/","name":"E","description":"automation, consultancy, project management, web","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ed.gs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/ed.gs\/#\/schema\/person\/d775615f2296ad0129fa3ea66346c628","name":"Ed","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/ed.gs\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4fe1dfaed09e6bdceb557d3008f5cc47?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4fe1dfaed09e6bdceb557d3008f5cc47?s=96&d=mm&r=g","caption":"Ed"},"url":"https:\/\/ed.gs\/author\/ed\/"}]}},"_links":{"self":[{"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/posts\/3637"}],"collection":[{"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/comments?post=3637"}],"version-history":[{"count":0,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/posts\/3637\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/media\/3624"}],"wp:attachment":[{"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/media?parent=3637"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/categories?post=3637"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/tags?post=3637"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}