"; // Only permit sql SELECT statements if(!eregi("^select .*$", $query)) { echo " Invalid SQL Query "; echo "
$query
"; return; } opendb(); $tmpq = str_replace("\\", "", $query); $endPos=$curPos+$linesPerPage; $tcurpos = $curPos+$startapi; $tendpos = $endPos+$startapi; // set a limit if not already set if(!stristr($query, "limit")) $tmpq .= " LIMIT $tcurpos,$linesPerPage"; // execute the db query $tstamp = time(); $result = mysql_query($tmpq); $tstamp = time() - $tstamp; if(debugging()) echo " QUERY TIME: $tstamp seconds
\n"; // query error! if(!$result) { echo "$query

\n"; echo "A QUERY error occurred: ".mysql_error()."\n"; exit; } $numRows = mysql_num_rows($result); $numCols = mysql_num_fields($result); $curPage = $curPos/$linesPerPage; $tmendpos = $curPos + $numRows; $explain = "stdquery.php?query=".urlencode("EXPLAIN $tmpq"); echo html_br(2); // set $debug to enable query debugging if($debug || stristr($tmpq, "explain")) { $str = eregi_replace("(SELECT|EXPLAIN|DISTINCT|FROM|WHERE|AND". "|OR |IS NULL|IS NOT NULL|LIMIT|ORDER BY". "|GROUP BY)", "
\\1
", $tmpq); echo "
$str
\n"; } echo html_echo("
"); add_pn_buttons($vars, $tmendpos); echo html_br(2); // output table header echo html_table_begin("width='80%' cellspacing=1 border=0 rules=rows frame=hsides"); $helems = array(); for($k = 0; $k < $numCols; $k++) { $name = mysql_field_name($result, $k); $helems[] = $name; if($name == "apiid") $have_apiid = 1; } echo html_th($helems, "title"); $curapiid=0; $curName="[NONAME]"; for($i = 0; $i < $numRows; $i++) { $row = mysql_fetch_array($result, MYSQL_BOTH); $color = ($i % 2); $arr = array(); for($k = 0; $k < $numCols; $k++) { $fname = mysql_field_name($result, $k); if($fname == "username") { $username = $row[$k]; $userid = $row["userid"]; $arr[] = html_ahref($username." ", apidb_url("edituser.php?userid=$userid&username=$username")); continue; } if($fname == "vendorName") { initFields(); $url = "vendorview.php?vendorId=".$row["vendorId"]; $arr[] = html_ahref($row[$k], $url); continue; } if($fname == "appName") { initFields(); $url = "appview.php?appId=".$row["appId"]; $arr[] = html_ahref($row[$k], $url); continue; } if($fname == "versionName") { $versionId = $row["versionId"]; $url = "admin/editAppVersion.php?versionId=$versionId"; $arr[] = html_ahref($row[$k], $url); continue; } if($fname == "webPage") { $url = $row[$k]; $theLink = "$url"; $arr[] = html_ahref($url, $theLink); continue; } if(mysql_field_type($result, $k) == "int") { $val = (int)$row[$k]; $arr[] = "
$val
"; } else { if(!$row[$k]) $arr[] = " "; else $arr[] = "$row[$k]"; } } echo html_tr($arr, "color$color"); } echo html_table_end(); echo html_br(); add_pn_buttons($vars, $tmendpos); echo html_echo("
"); mysql_free_result($result); closedb(); } ?>