{"id":2661,"date":"2022-08-30T15:26:43","date_gmt":"2022-08-30T15:26:43","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/02\/04\/php-query-for-mysql-text-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:26:43","modified_gmt":"2022-08-30T15:26:43","slug":"php-query-for-mysql-text-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/php-query-for-mysql-text-collection-of-common-programming-errors\/","title":{"rendered":"php query for mysql text-Collection of common programming errors"},"content":{"rendered":"<p>i&#8217;m having problems while querying for mysql &#8220;text&#8221; data.<\/p>\n<p>here&#8217;s my code:<\/p>\n<pre><code>$result_odg = mysqli_query($con,\"SELECT * FROM agenda WHERE data = '\" . $today . \"' AND odg IS NOT NULL\");\necho \"<\/code><\/pre>\n<h4><code>ODG:<\/code><\/h4>\n<pre>\";\n\nif (mysqli_fetch_array($result_odg)) {\n    $i = 1;\n    echo \"<\/pre>\n<p>&#8220;; while($row = mysqli_fetch_array($result_odg)) { if($i % 2 == 0) $cellID = &#8220;even&#8221;; else $cellID = &#8220;odd&#8221;; echo &#8220;&#8221;; $i == $i++; } echo &#8221;<\/p>\n<table id=\"\\&quot;agenda_odg\\&quot;\">\n<tr id=\". $cellID .\">\n<td>&#8221; . $row[&#8216;testo&#8217;] . &#8220;<\/td>\n<\/tr>\n<\/table>\n<p><code>\"; } else { echo \"No ODG\"; }<\/code><\/p>\n<p>the table have the following fields: id, data_ins, data, testo, odg, agenda, ok.<\/p>\n<p>using any other name than &#8220;testo&#8221; in <code>$row['testo']<\/code> (example <code>$row['id']<\/code>) will print out the text. is there any special query to do for &#8220;TEXT&#8221; type fields? maybe because it&#8217;s too heavy and needs a particular array? can&#8217;t find anything about this on the manual&#8230;<\/p>\n<ol>\n<li>\n<p>please use<\/p>\n<pre><code>\/\/ no need to fetch the result for check (shorten runtime time)\nif ($result_odg) {\n\n    while($row = mysqli_fetch_assoc($result_odg)) {\n        \/\/ use $row['testo'] is possible\n\n        \/\/ replace this too\n        $i++;\n    }\n}\n<\/code><\/pre>\n<\/li>\n<li>\n<p>To make query fast select only those fields which needed.In this case your query should be like:<\/p>\n<pre><code>$result_odg = mysqli_query($con,\"SELECT testo FROM agenda WHERE data = '\" . $today . \"' AND odg IS NOT NULL\");\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2014-02-04 13:27:02. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>i&#8217;m having problems while querying for mysql &#8220;text&#8221; data. here&#8217;s my code: $result_odg = mysqli_query($con,&#8221;SELECT * FROM agenda WHERE data = &#8216;&#8221; . $today . &#8220;&#8216; AND odg IS NOT NULL&#8221;); echo &#8221; ODG: &#8220;; if (mysqli_fetch_array($result_odg)) { $i = 1; echo &#8221; &#8220;; while($row = mysqli_fetch_array($result_odg)) { if($i % 2 == 0) $cellID = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2661","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2661","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2661"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2661\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2661"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2661"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}