{"id":1856,"date":"2018-10-25T13:31:58","date_gmt":"2018-10-25T13:31:58","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=1856"},"modified":"2022-02-17T07:14:02","modified_gmt":"2022-02-17T07:14:02","slug":"php4-select-general","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/mysql\/php-versions\/php4-old-code\/queries-php4-old-code\/php4-select-general","title":{"rendered":"PHP4 .SELECT General"},"content":{"rendered":"<p>\n<span style=\"color:#FF0000;\"><em><strong>This is PHP4 Code!<\/strong><\/em><\/span>\n<\/p>\n<p>\n<a href=\"http:\/\/www.w3schools.com\/sql\/\" target=\"_blank\" rel=\"noopener noreferrer\">w3schools.com SQL Guide<\/a>\n<\/p>\n<h4>\nSimple Get A Result<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n  $query = @mysql_query(&quot;SELECT user_name, password FROM member_profile WHERE email_address = &#39;$user_name_login&#39; AND password = &#39;$password_login&#39;&quot;);\r\n  $result = @mysql_fetch_array($query);\r\n  $result_display_username = $result['user_name'];\r\n  $result_username = strtolower($result['user_name']);\r\n<\/code><\/pre>\n<h4>\nDoes Record Exist<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n  $query = @mysql_query(&quot;SELECT * FROM my_table WHERE some_field = $some_field AND some_field2 = $some_field2 AND some_field3 = &#39;yes&#39;&quot;);\r\n  if (@mysql_num_rows($query))\r\n  {\r\n<\/code><\/pre>\n<h4>\nGet Each Row Returned<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n  $query1 = @mysql_query(&quot;SELECT * FROM some_table WHERE some_field = $some_value AND approved = &#39;pending&#39;&quot;);\r\n  while ($result1 = @mysql_fetch_array($query1))    \/\/Get each row returned\r\n  {\r\n    $m_title = $result1['member_username'];\r\n    \/\/Do something with it...\r\n  }\r\n<\/code><\/pre>\n<h4>\nGet Number Of Rows Returned<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n  $count = @mysql_num_rows($query);\r\n<\/code><\/pre>\n<h4>\nGet Specific Columns<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n  $query_user_details = mysql_query(&quot;SELECT first_name, last_name, image_file_name FROM member_profile WHERE member_id = $user_id&quot;);\r\n<\/code><\/pre>\n<h4>\nGet each field as a variable named as the field<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n  foreach ( $result as $key =&gt; $value )\r\n  {\r\n    $$key = $value;\r\n  }\r\n<\/code><\/pre>\n<h4>\nUsing OR Arguments<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n$sql = &quot;SELECT * FROM videos WHERE response_id = $vid AND (video_approved =&#39;yes&#39; || approved =&#39;group&#39; || approved =&#39;school&#39;) AND public_private = &#39;public&#39;&quot;;\r\n<\/code><\/pre>\n<h4>\nPutting All Results Into An Array<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n$all_results = array(); \t\t\/\/Empty array to hold returned rows\r\nwhile ($row = @mysql_fetch_array($search_query))\r\n{\r\n\t$all_results[] = $row;\r\n}\r\n<\/code><\/pre>\n<p>\n&nbsp;\n<\/p>\n<p>\n&nbsp;\n<\/p>\n<p>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is PHP4 Code! w3schools.com SQL Guide Simple Get A Result $query = @mysql_query(&quot;SELECT user_name, password FROM member_profile WHERE email_address = &#39;$user_name_login&#39; AND password = &#39;$password_login&#39;&quot;); $result = @mysql_fetch_array($query); $result_display_username = $result[&#8216;user_name&#8217;]; $result_username = strtolower($result[&#8216;user_name&#8217;]); Does Record Exist $query = @mysql_query(&quot;SELECT * FROM my_table WHERE some_field = $some_field AND some_field2 = $some_field2 AND some_field3 = [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[156],"tags":[],"class_list":["post-1856","post","type-post","status-publish","format-standard","hentry","category-queries-php4-old-code"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1856","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=1856"}],"version-history":[{"count":2,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1856\/revisions"}],"predecessor-version":[{"id":3211,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1856\/revisions\/3211"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=1856"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=1856"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=1856"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}