public function fetchArrayStrict($sql = null) { if (empty($sql)) { throw new DbException('<b>SQL ERROR</b> : null query ! <br>'); } $query = $this->query($sql); if ($query === false) { return null; } $confunc = $this->connect->getDbStyle() . '_fetch_array'; while ($arr = $confunc($query)) { $array[] = $arr; } if (!is_array($array)) { return null; } foreach ($array as $k => $v) { foreach ($v as $kk => $vv) { if (!is_numeric($kk)) { continue; } $type = mysql_field_type($query, $kk); $name = mysql_field_name($query, $kk); if ($type == 'int') { $arr[$k][$name] = (int) $vv; } else { $arr[$k][$name] = $vv; } } } return $arr; }
/** * INPUT: $apikey * OUTPUT: XML file **/ function WriteHistoryFromSQL($sql) { $req = mysql_query($sql) or die('SQL Error !<br>' . $sql . '<br>' . mysql_error()); $f = mysql_num_fields($req); for ($i = 0; $i < $f; $i++) { $previous[$i] = ""; $xmltab[$i] = ""; } while ($data = mysql_fetch_array($req)) { for ($i = 0; $i < $f; $i++) { if (mysql_field_name($req, $i) != 'cid' && mysql_field_name($req, $i) != 'date' && $data[$i] != $previous[$i]) { $previous[$i] = $data[$i]; $xmltab[$i] .= "<" . mysql_field_name($req, $i) . " date=\"" . $data['date'] . "\">" . $data[$i] . "</" . mysql_field_name($req, $i) . ">"; } } } for ($i = 0; $i < $f; $i++) { $tag_name = mysql_field_name($req, $i); if ($tag_name != 'cid' && $tag_name != 'date') { if ($xmltab[$i] != "") { print "<" . $tag_name . "_history>" . $xmltab[$i] . "</" . $tag_name . "_history>"; } } } }
function get_field_names($table){ $result = mysql_query("SELECT * FROM ".$table); for($x = 0; $x < mysql_num_fields($result); $x++){ $arr[$x] = mysql_field_name($result,$x); } return $arr; }
function update_emp_values($emp_type, $emp_id, $fname, $lname, $contact, $address, $salary, $sex, $bdate, $join_date) { $dbc = mysql_connect('localhost', 'root', 'rishi'); if (!$dbc) { die('NOT CONNECTED:' . mysql_error()); } $db_selected = mysql_select_db("restaurant", $dbc); if (!$db_selected) { die('NOT CONNECTED TO DATABASE:' . mysql_error()); } $emp_type_id = $emp_type . "_id"; $query = "Select * from {$emp_type}"; $emp = mysql_query($query); $num_fields = mysql_num_fields($emp); if ($emp_type == "COOK") { $val_arrays = array("{$emp_id}", $fname, $lname, $contact, $address, $salary, $sex, $bdate, $join_date, $_POST["Specialization"]); } else { $val_arrays = array("{$emp_id}", $fname, $lname, $contact, $address, $salary, $sex, $bdate, $join_date); } $values = ""; for ($i = 1; $i < $num_fields; $i++) { $values = $values . mysql_field_name($emp, $i) . " = " . "\"{$val_arrays[$i]}\""; if ($i != $num_fields - 1) { $values = $values . " , "; } } $query = "UPDATE {$emp_type} SET " . $values . " WHERE {$emp_type_id} = {$emp_id};"; mysql_query($query); }
/** * Constructor method for the adapter. This constructor implements the setting of the * 3 required properties for the object. * * @param resource $d The datasource resource */ function mysqlfAdapter($d) { $f = $d['filter']; $d = $d['data']; parent::RecordSetAdapter($d); $fieldcount = count($f); $truefieldcount = mysql_num_fields($d); $be = $this->isBigEndian; $isintcache = array(); for ($i = 0; $i < $truefieldcount; $i++) { //mysql_fetch_* usually returns only strings, //hack it into submission $type = mysql_field_type($d, $i); $name = mysql_field_name($d, $i); $isintcache[$name] = in_array($type, array('int', 'real', 'year')); } $isint = array(); for ($i = 0; $i < $fieldcount; $i++) { $this->columnNames[$i] = $this->_charsetHandler->transliterate($f[$i]); $isint[$i] = isset($isintcache[$f[$i]]) && $isintcache[$f[$i]]; } //Start fast serializing $ob = ""; $fc = pack('N', $fieldcount); if (mysql_num_rows($d) > 0) { mysql_data_seek($d, 0); while ($line = mysql_fetch_assoc($d)) { //Write array flag + length $ob .= "\n" . $fc; $i = 0; foreach ($f as $key) { $value = $line[$key]; if (!$isint[$i]) { $os = $this->_directCharsetHandler->transliterate($value); //string flag, string length, and string $len = strlen($os); if ($len < 65536) { $ob .= "" . pack('n', $len) . $os; } else { $ob .= "\f" . pack('N', $len) . $os; } } else { $b = pack('d', $value); // pack the bytes if ($be) { // if we are a big-endian processor $r = strrev($b); } else { // add the bytes to the output $r = $b; } $ob .= "" . $r; } $i++; } } } $this->numRows = mysql_num_rows($d); $this->serializedData = $ob; }
function RunFreeQuery() { global $cnInfoCentral; global $aRowClass; global $rsQueryResults; global $sSQL; global $iQueryID; //Run the SQL $rsQueryResults = RunQuery($sSQL); if (mysql_error() != "") { echo gettext("An error occured: ") . mysql_errno() . "--" . mysql_error(); } else { $sRowClass = "RowColorA"; echo "<table align=\"center\" cellpadding=\"5\" cellspacing=\"0\">"; echo "<tr class=\"" . $sRowClass . "\">"; //Loop through the fields and write the header row for ($iCount = 0; $iCount < mysql_num_fields($rsQueryResults); $iCount++) { echo "<td align=\"center\"><b>" . mysql_field_name($rsQueryResults, $iCount) . "</b></td>"; } echo "</tr>"; //Loop through the recordsert while ($aRow = mysql_fetch_array($rsQueryResults)) { $sRowClass = AlternateRowStyle($sRowClass); echo "<tr class=\"" . $sRowClass . "\">"; //Loop through the fields and write each one for ($iCount = 0; $iCount < mysql_num_fields($rsQueryResults); $iCount++) { echo "<td align=\"center\">" . $aRow[$iCount] . "</td>"; } echo "</tr>"; } echo "</table>"; echo "<br><p class=\"ShadedBox\" style=\"border-style: solid; margin-left: 50px; margin-right: 50 px; border-width: 1px;\"><span class=\"SmallText\">" . str_replace(Chr(13), "<br>", htmlspecialchars($sSQL)) . "</span></p>"; } }
function ListIt() { $tmpstr = ""; $query = ""; global $strCantQuery; global $strNoContent; if (isset($this->headerfmt)) { $tmpstr = $this->headerfmt; } $query = "select " . $this->fields . " from " . $this->tables . " limit " . $this->startrow . ", " . $this->maxrow; $this->sqlres = mysql_query($query) or die("{$strCantQuery}: {$query} <br>Error: " . mysql_error()); // ambil nama2 field $numfields = mysql_num_fields($this->sqlres); for ($cl = 0; $cl < $numfields; $cl++) { $arrfields[$cl] = mysql_field_name($this->sqlres, $cl); //echo $arrfields [$cl] . "<br>"; } $nomer = 0; while ($row = mysql_fetch_array($this->sqlres)) { $tmp = $this->detailfmt; $nomer++; for ($cl = 0; $cl < $numfields; $cl++) { settype($nomer, "string"); $tmp = str_replace("=NOMER=", $nomer, $tmp); $nmf = $arrfields[$cl]; $tmp = str_replace("=" . $nmf . "=", $row[$nmf], $tmp); $tmp = str_replace("=!" . $nmf . "=", StripEmpty(urlencode($row[$nmf])), $tmp); $tmp = str_replace("=:" . $nmf . "=", StripEmpty(stripslashes($row[$nmf])), $tmp); } $tmpstr = $tmpstr . $tmp; } $tmpstr = $tmpstr . $this->footerfmt; return $tmpstr; }
function getAccessInfo($sql_fields, $sql_table, $sql_conditions = "1", $cond = NULL) { $access['Data'] = array(); $access['Headers'] = 0; $access['Sql_Fields'] = $sql_fields; $access['Sql_Table'] = $sql_table; $access['Sql_Conditions'] = $sql_conditions; $sql = "Select {$sql_fields} from {$sql_table} where {$sql_conditions}"; $result = sql_query_read($sql) or dieLog(mysql_error() . " ~ " . "<pre>{$sql}</pre>"); if (mysql_num_rows($result) < 1) { return -1; } $row = mysql_fetch_row($result); $fields = mysql_num_fields($result); for ($i = 0; $i < $fields; $i++) { $type = mysql_field_type($result, $i); $name = mysql_field_name($result, $i); $len = mysql_field_len($result, $i); $flags = mysql_field_flags($result, $i); $table = mysql_field_table($result, $i); $useName = $name; if (array_key_exists($useName, $access['Data'])) { $useName = $name . $i; } if ($name == 'access_header') { $access['Headers']++; } $access['Data'][$useName] = getAttrib($name, $type, $len, $flags, $table, $row[$i], &$cond); } return $access; }
function query($query, $report = false) { $result = mysql_query($query, $this->link); $this->affected_rows = mysql_affected_rows($this->link); $this->insert_id = mysql_insert_id($this->link); if (!is_resource($result)) { if ($result == false && $report == true) { echo mysql_error(); } return $result; } else { $numRows = mysql_num_rows($result); if ($numRows == 0) { return false; } $numFields = mysql_num_fields($result); for ($i = 0; $i < $numFields; $i++) { $resultFields[] = mysql_field_name($result, $i); } for ($i = 0; $i < $numRows; $i++) { $resultValues = mysql_fetch_row($result); $results[] = array_combine($resultFields, $resultValues); } return $results; } }
/** * Field data * * Generates an array of objects containing field meta-data * * @access public * @return array */ function field_data() { $retval = array(); for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) { $retval[$i] = new stdClass(); $retval[$i]->name = mysql_field_name($this->result_id, $i); $retval[$i]->type = mysql_field_type($this->result_id, $i); $retval[$i]->max_length = mysql_field_len($this->result_id, $i); $retval[$i]->primary_key = strpos(mysql_field_flags($this->result_id, $i), 'primary_key') === FALSE ? 0 : 1; $retval[$i]->default = ''; } /** Updated from github, see https://github.com/EllisLab/CodeIgniter/commit/effd0133b3fa805e21ec934196e8e7d75608ba00 while ($field = mysql_fetch_object($this->result_id)) { preg_match('/([a-zA-Z]+)(\(\d+\))?/', $field->Type, $matches); $type = (array_key_exists(1, $matches)) ? $matches[1] : NULL; $length = (array_key_exists(2, $matches)) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL; $F = new stdClass(); $F->name = $field->Field; $F->type = $type; $F->default = $field->Default; $F->max_length = $length; $F->primary_key = ( $field->Key == 'PRI' ? 1 : 0 ); $retval[] = $F; } **/ return $retval; }
function export_excel_csv() { $conn = mysql_connect("oblogin.com", "neel099_root", "rootdb"); $db = mysql_select_db("neel099_twofactorauth", $conn); $sql = "SELECT * FROM Llog"; $rec = mysql_query($sql) or die(mysql_error()); $num_fields = mysql_num_fields($rec); for ($i = 0; $i < $num_fields; $i++) { $header .= mysql_field_name($rec, $i) . "\\t"; } while ($row = mysql_fetch_row($rec)) { $line = ''; foreach ($row as $value) { if (!isset($value) || $value == "") { $value = "\\t"; } else { $value = str_replace('"', '""', $value); $value = '"' . $value . '"' . "\\t"; } $line .= $value; } $data .= trim($line) . "\\n"; } $data = str_replace("\\r", "", $data); if ($data == "") { $data = "\\n No Record Found!\n"; } header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=reports.xls"); header("Pragma: no-cache"); header("Expires: 0"); print "{$header}\\n{$data}"; }
function select($query, $class = 'recordset', $cache = true) { if (!$this->con_id) { return false; } if ($class == '' || !class_exists($class)) { $class = 'recordset'; } if ($cache && ($rs = $this->_getFromCache($query)) !== false) { return new $class($rs); } else { $cur = mysql_unbuffered_query($query, $this->con_id); if ($cur) { # Insertion dans le reccordset $i = 0; $arryRes = array(); while ($res = mysql_fetch_row($cur)) { for ($j = 0; $j < count($res); $j++) { $arryRes[$i][strtolower(mysql_field_name($cur, $j))] = $res[$j]; } $i++; } $this->_putInCache($query, $arryRes); return new $class($arryRes); } else { $this->setError(); return false; } } }
function export2csv($params) { $export = $params['rows']; $filename = $params['filename']; include_once "../config/db_conn.php"; $fields = mysql_num_fields($export); for ($i = 0; $i < $fields; $i++) { $header .= mysql_field_name($export, $i) . ","; } while ($row = mysql_fetch_object($export)) { $line = ''; foreach ($row as $value) { if (!isset($value) or $value == "") { $value = ","; } else { $value = str_replace('"', '""', $value); $value = '"' . $value . '"' . ","; } $line .= $value; } $data .= trim($line) . "\n"; } //$data = str_replace("r","",$data); if ($data == "") { $data = "n(0) Records Found!n"; } header("Content-type: application/x-msdownload"); header("Content-Disposition: attachment; filename=" . $filename . ".csv"); header("Pragma: no-cache"); header("Expires: 0"); print " {$header}\n{$data}"; }
function printIt() { //[s.6] $num_cols = mysql_num_fields($this->result); $num_rows = mysql_num_rows($this->result); print "<h3>"; //print field names print "<pre>"; for ($i = 0; $i < $num_cols; $i++) { print mysql_field_name($this->result, $i); print "\t"; } print "</pre>"; print "</h3>"; print "<p>"; print "<pre>"; mysql_data_seek($this->result, 0); for ($i = 0; $i < $num_rows; $i++) { $row = mysql_fetch_row($this->result); for ($j = 0; $j < $num_cols; $j++) { print $row[$j]; print "\t"; } print "<br>"; } print "</pre>"; print "</p>"; }
function getSqlResultAsXml($dbCon, $SQL_query) { // Replace by a query that matches your database $result = $dbCon->executeQuery($SQL_query); // we produce XML header("Content-type: text/xml"); $XML = "<?xml version=\"1.0\"?>\n"; if (isset($xslt_file) && $xslt_file) { $XML .= "<?xml-stylesheet href=\"{$xslt_file}\" type=\"text/xsl\" ?>"; } // root node $XML .= "<result>\n"; // rows while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $XML .= "\t<row>\n"; $i = 0; // cells foreach ($row as $cell) { // Escaping illegal characters - not tested actually ;) $cell = str_replace("<", "<", $cell); $cell = str_replace(">", ">", $cell); $cell = str_replace("\"", """, $cell); //$cell = str_replace("&", "<![CDATA["."&"."]]>", $cell); $col_name = mysql_field_name($result, $i); // creates the "<tag>contents</tag>" representing the column $XML .= "\t\t<" . $col_name . ">" . $cell . "</" . $col_name . ">\n"; $i++; } $XML .= "\t</row>\n"; } $XML .= "</result>\n"; // output the whole XML string return $XML; }
function field_name() { $jml = $this->num_field(); for($i = 0; $i < $jml; $i++) { $arr_field[] = mysql_field_name($this->hasil, $i); } return $arr_field; }
function activewidgets_grid($name, &$data) { $row_count = @mysql_num_rows($data); $column_count = @mysql_num_fields($data); $columns = "var " . $name . "_columns = [\n"; for ($i = 0; $i < $column_count; $i++) { $columns .= "\"" . @mysql_field_name($data, $i) . "\", "; } $columns .= "\n];\n"; $rows = "var " . $name . "_data = [\n"; while ($result = @mysql_fetch_array($data)) { $rows .= "["; for ($i = 0; $i < $column_count; $i++) { $rows .= "\"" . activewidgets_html($result[$i]) . "\", "; } $rows .= "],\n"; } $rows .= "];\n"; $html = "<" . "script" . ">\n"; $html .= $columns; $html .= $rows; $html .= "try {\n"; $html .= " var {$name} = new Active.Controls.Grid;\n"; $html .= " {$name}.setRowCount({$row_count});\n"; $html .= " {$name}.setColumnCount({$column_count});\n"; $html .= " {$name}.setDataText(function(i, j){return " . $name . "_data[i][j]});\n"; $html .= " {$name}.setColumnText(function(i){return " . $name . "_columns[i]});\n"; $html .= " document.write({$name});\n"; $html .= "}\n"; $html .= "catch (error){\n"; $html .= " document.write(error.description);\n"; $html .= "}\n"; $html .= "</" . "script" . ">\n"; return $html; }
function query($query, $singleResult = 0) { $this->_result = mysql_query($query, $this->_dbHandle); if (preg_match("/select/i", $query)) { $result = array(); $table = array(); $field = array(); $tempResults = array(); $numOfFields = mysql_num_fields($this->_result); for ($i = 0; $i < $numOfFields; ++$i) { array_push($table, mysql_field_table($this->_result, $i)); array_push($field, mysql_field_name($this->_result, $i)); } while ($row = mysql_fetch_row($this->_result)) { for ($i = 0; $i < $numOfFields; ++$i) { $table[$i] = trim(ucfirst($table[$i]), "s"); $tempResults[$table[$i]][$field[$i]] = $row[$i]; } if ($singleResult == 1) { mysql_free_result($this->_result); return $tempResults; } array_push($result, $tempResults); } mysql_free_result($this->_result); return $result; } }
function mysql_query_cache($sql, $linkIdentifier = false, $timeout = 4) { //首先调用上面的getCache函数,如果返回值不为false的话,就说明是从memcached服务器获取的数据 //如果返回false,此时就需要直接从数据库中获取数据了。 //需要注意的是这里使用操作的命令加上sql语句的md5码作为一个特定的key,可能大家觉得使用数据项的 //名称作为key会比较自然一点。运行memcached加上"-vv"参数,并且不作为daemon运行的话,可以看见 //memcached处理时输出的相关信息 if (!($cache = getCache(md5("mysql_query" . $sql)))) { $cache = false; $r = $linkIdentifier != false ? mysql_query($sql, $linkIdentifier) : mysql_query($sql); //读取数据库,并将结果放入$cache数组中 if (is_resource($r) && ($rows = mysql_num_rows($r)) != 0) { for ($i = 0; $i < $rows; $i++) { $fields = mysql_num_fields($r); $row = mysql_fetch_array($r); for ($j = 0; $j < $fields; $j++) { if ($i == 0) { $columns[$j] = mysql_field_name($r, $j); } $cache[$i][$columns[$j]] = $row[$j]; } } //将数据放入memcached服务器中,如果memcached服务器没有开的话,此语句什么也不会做 //如果开启了服务器的话,数据将会被缓存到memcached服务器中 if (!setCache(md5("mysql_query" . $sql), $cache, $timeout)) { # If we get here, there isn’t a memcache daemon running or responding } } } return $cache; }
function OptionFields($language) { include '../../share/db_connect1.php'; //include 'meta_tag_translation.php'; //Welche Meta-Daten-Felder beinhaltet die Tabelle pictures? $result2 = mysql_query("SHOW FIELDS FROM {$table2}"); $num2 = mysql_num_rows($result2); $result3 = mysql_query("SELECT * FROM {$table2}"); $num3 = mysql_num_rows($result3); $CN = array(); //CN: ColumnName echo "<option selected value=''> ~ Bitte Datenfeld auswählen ~</option>"; for ($i2 = 0; $i2 < $num2; $i2++) { $CN[] = mysql_field_name($result3, $i2); } //nach dem Leerfeld werden die recherchierbare Felder der Pictures-Tabelle angeboten, jedoch ohne die der IF-Bedingung: asort($CN); foreach ($CN as $cn) { if (!stristr($cn, 'GPS') and !stristr($cn, 'City') and !stristr($cn, 'loc_id_0') and !stristr($cn, 'FileNameHQ') and !stristr($cn, 'FileNameHist') and !stristr($cn, 'FileNameHist_r') and !stristr($cn, 'FileNameHist_g') and !stristr($cn, 'FileNameHist_b') and !stristr($cn, 'FileNameMono') and !stristr($cn, 'FileNameV') and !stristr($cn, 'has_kat') and !stristr($cn, 'md5sum')) { //ggf. Uebersetzung des angezeigten Feld-Namens: if ($language !== 'en') { $result3 = mysql_query("SELECT {$cn} FROM {$table20} WHERE lang = '{$language}'"); $tag_name = mysql_result($result3, isset($i3), $cn); if ($tag_name == '') { $tag_name = $cn; } } echo "<option VALUE = '{$cn}'>" . $tag_name . "</option>"; } } }
function OptionFields() { include '../../share/db_connect1.php'; //Welche Felder beinhaltet die Tabelle meta_data? $result2 = mysql_query("SHOW FIELDS FROM {$table2}"); $num2 = mysql_num_rows($result2); $result3 = mysql_query("SELECT * FROM {$table2}"); $num3 = mysql_num_rows($result3); $CN = array(); echo "<option selected value=''> ~ Bitte Datenfeld auswählen ~</option>"; for ($i2 = 0; $i2 < $num2; $i2++) { $CN[] = mysql_field_name($result3, $i2); } //nach dem Leerfeld werden standardmaessig einige recherchierbare Felder der Pictures-Tabelle angeboten: /* echo " <optgroup label='Nicht-Meta-Daten'> <option VALUE = 'pic_id'>interne Bild-Nr.</option> <option VALUE = 'FileNameOri'>Original-Dateiname</option> <option VALUE = 'Owner'>Bild-Eigentümer</option> <option VALUE = 'note'>Bild-Qualität</option> <option VALUE = 'ranking'>Anzahl der Downloads</option> </optgroup> <optgroup label='Meta-Daten'>"; */ //dann folgen Felder der Meta-Daten-Tabelle (alle ausser der locations-Felder): asort($CN); foreach ($CN as $cn) { if (!stristr($cn, 'GPS') and !stristr($cn, 'City')) { echo "<option VALUE = '{$cn}'>{$cn}</option>"; } } }
function formatJSON($result) { $str = "["; $numRows = 0; while ($row = mysql_fetch_array($result)) { if ($numRows > 0) { $str = $str . ", "; } $numRows++; $n = mysql_num_fields($result); for ($i = 0; $i < $n; $i++) { $fld = mysql_field_name($result, $i); $val = addslashes($row[$fld]); $val = str_replace("\t", "", $val); $val = str_replace("'", "\\'", $val); $val = str_replace("\r\n", "", $val); if ($i == 0) { $str = $str . "{\"{$fld}\":\"{$val}\""; } else { $str = $str . ", \"{$fld}\":\"{$val}\""; } } $str = $str . "}\r\n"; } $str = $str . "]"; return $str; }
function display_db_query($query_string, $connection) { $result_id = mysql_query($query_string, $connection) or die(mysql_error()); $column_count = mysql_num_fields($result_id) or die(mysql_error()); echo "<table class=\"sortable\" border=\"1\" style=\"width:auto;margin-top:1em;\">\n<tr>"; for ($column_num = 0; $column_num < $column_count - 1; $column_num++) { echo "<th>", mysql_field_name($result_id, $column_num), "</th>"; } echo "</tr>\n"; while ($row = mysql_fetch_row($result_id)) { echo "<tr>"; for ($column_num = 0; $column_num < $column_count - 1; $column_num++) { echo "<td class=\"c{$column_num}\">"; if ($column_num == 2) { echo "<a href=\"hebconj.php?verb_root=", urlencode($row[$column_num]), "&tense_id={$row[4]}\">"; } if ($column_num == 1 && empty($row[5])) { echo '<del>'; } echo $row[$column_num]; if ($column_num == 1 && empty($row[5])) { echo '</del>'; } if ($column_num == 2) { echo "</a>"; } echo "</td>"; } echo "</tr>\n"; } echo "</table>\n"; }
function tabledump($result) { if ($result == 0) { echo "<b>Error " . mysql_errno() . ": " . mysql_error() . "</b>"; } else { if (@mysql_num_rows($result) == 0) { echo "<b>Query completed. Empty result.</b><br>"; } else { $nf = mysql_num_fields($result); $nr = mysql_num_rows($result); echo "<table border='1'> <thead>"; echo "<tr>"; for ($i = 0; $i < $nf; $i++) { echo "<th>" . mysql_field_name($result, $i) . "</th>"; } echo "</tr>"; echo "</thead><tbody>"; for ($i = 0; $i < $nr; $i++) { echo "<tr>"; $row = mysql_fetch_array($result); for ($j = 0; $j < $nf; $j++) { echo "<td>" . $row[$j] . "</td>"; } echo "</tr>"; } echo "</tbody></table>"; } } return $row; }
function display_db_query($query_string, $connection, $header_bool, $table_params) { // perform the database query $result_id = mysql_query($query_string, $connection) or die("display_db_query:" . mysql_error()); // find out the number of columns in result $column_count = mysql_num_fields($result_id) or die("display_db_query:" . mysql_error()); // Here the table attributes from the $table_params variable are added print "<TABLE {$table_params} >\n"; // optionally print a bold header at top of table if ($header_bool) { print "<TR>"; for ($column_num = 0; $column_num < $column_count; $column_num++) { $field_name = mysql_field_name($result_id, $column_num); print "<TH>{$field_name}</TH>"; } print "</TR>\n"; } // print the body of the table while ($row = mysql_fetch_row($result_id)) { print "<TR ALIGN=LEFT VALIGN=TOP>"; for ($column_num = 0; $column_num < $column_count; $column_num++) { print "<TD>{$row[$column_num]}</TD>\n"; } print "</TR>\n"; } print "</TABLE>\n"; }
function selectrec($fields, $table, $cond = "") { $a = array(); $query = "select " . $fields . " from " . $table; if (!($cond == "")) { $query = $query . " where " . $cond; } //echo "<br>".$query; $result = mysql_query($query); //echo mysql_error(); //if (mysql_error()!="") //echo "<br>".$query; $numrows = mysql_num_rows($result); $numfields = mysql_num_fields($result); $i = $j = 0; while ($i < $numrows) { while ($j < $numfields) { $a[$i][$j] = mysql_result($result, $i, mysql_field_name($result, $j)); $j++; } $i++; $j = 0; } mysql_free_result($result); return $a; }
function getNameFieldsAll() { $this->NumFields = mysql_num_fields($this->doQueryS); for ($iterador = 0; $iterador < $this->NumFields; $iterador++) { echo $this->fieldNamesArray[$iterador] = mysql_field_name($this->doQueryS, $iterador) . ","; } }
function update_restaurant() { $dbc = mysql_connect('localhost', 'root', 'rishi'); if (!$dbc) { die('NOT CONNECTED:' . mysql_error()); } $db_selected = mysql_select_db("restaurant", $dbc); if (!$db_selected) { die('NOT CONNECTED TO DATABASE:' . mysql_error()); } echo "<form name = \"form1\" action = \"update_restaurant_values.php\" method =\"post\" align=\"center\" onsubmit=\"return checkscript()\">" . "\n"; echo "<table style=\"text-align:center;\" align=\"center\" width=\"400\">" . "\n"; $query = "SELECT * from RESTAURANT;"; $rest = mysql_query($query); $num_fields = mysql_num_fields($rest); for ($i = 0; $i < $num_fields; $i++) { echo "<tr>" . "\n"; echo "<td>" . "\n"; $field = mysql_field_name($rest, $i); echo "<b>" . $field . "</b>" . "\n"; echo "</td>" . "\n"; echo "<td>" . "\n"; $res = mysql_result($rest, 0, $i); if ($i) { echo "<input type = \"text\" name = \"{$field}\" value=\"{$res}\">"; } else { echo "<input type = \"text\" name = \"{$field}\" value=\"{$res}\" readonly=\"readonly\">"; } echo "</td>" . "\n"; echo "</tr>" . "\n"; } echo "</table>" . "\n" . "<br/>"; echo "<input type=\"submit\" name=\"submitbutton\" value=\"Update\">" . "\n"; echo "</form>" . "\n"; }
function Tabler($table, $cols = array(), $filters = array(), $order = "") { $this->table($table); $this->pager = new Pager(); if (count($cols) == 0) { $what = '*'; } else { foreach ($cols as $title => $name) { if ($name != "") { $this->addCol($name); $this->col_option($name, 'title', $title); } $what .= $name . ','; } $what = substr($what, 0, strlen($what) - 1); } if (count($filters) > 0) { foreach ($filters as $add) { $filter = isset($filter) ? "{$filter} AND {$add}" : " WHERE {$add}"; } } foreach ($_GET as $key => $value) { if (ereg('^filter_', $key)) { $name = substr($key, 7); if ($value != '') { if ($_GET['f_' . $name . '_type'] == 'search') { $filter = isset($filter) ? "{$filter} AND {$name} LIKE '%{$value}%'" : " WHERE {$name} LIKE '%{$value}%'"; } else { $filter = isset($filter) ? "{$filter} AND {$name}='{$value}'" : " WHERE {$name}='{$value}'"; } } } } $query = "SELECT count(*) as max FROM {$table} {$filter}"; $result = mysql_query($query) or die("MySQL Error: " . mysql_error()); $row = mysql_fetch_array($result); $this->pager->max($row['max']); $query = "SELECT {$what} FROM {$table} {$filter}"; $keys = array_keys($this->cols); $order = isset($_GET['orderby']) ? $_GET['orderby'] : ($order == "" ? $keys['0'] . ' DESC' : $order); $query .= " ORDER BY {$order}"; $query .= " LIMIT " . $this->pager->from() . "," . $this->pager->incr(); $result = mysql_query($query) or die("MySQL Error: " . mysql_error()); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $this->add($row); } $fields = mysql_num_fields($result); for ($x = 0; $x < $fields; $x++) { $colinfo = @mysql_field_flags($result, $x); $colinfo = explode(' ', $colinfo); $name = mysql_field_name($result, $x); $type = mysql_field_type($result, $x); if (array_search('auto_increment', $colinfo) !== false) { $this->col_option($name, 'filter', 'submit'); $this->idcol = $name; } else { $this->col_option($name, 'filter', 'select'); } } }
protected function query($query) { mysql_pconnect($this->host, $this->user, $this->password); mysql_select_db($this->dbName) or trigger_error(mysql_error(), E_USER_WARNING); $result = mysql_query($query); #DO QUERY if (is_resource($result)) { while ($row = mysql_fetch_array($result, MYSQL_NUM)) { //BUILD UP AN ARRAY WITH NAMED FIELDS RATHER THAN NUMBERS $i = 0; foreach ($row as $f) { $fileds[] = mysql_field_name($result, $i); $field = mysql_field_name($result, $i); $arr[$field] = $row[$i]; $i++; } $resArr[] = $arr; } mysql_free_result($result); if (isset($resArr)) { return $resArr; } else { return false; } } else { return false; } }