added function for html table labels
This commit is contained in:
parent
51830a8122
commit
3f04c1ad99
66
main.c
66
main.c
@ -23,6 +23,54 @@ inline char *get_filename(const char c) {
|
||||
return qout;
|
||||
}
|
||||
|
||||
inline char *get_tblheader(const char c) {
|
||||
char *out;
|
||||
switch (c) {
|
||||
default:
|
||||
out = "<TABLE class='center'>\
|
||||
<TH class='tablename' COLSPAN='4'> <H3><BR>Map List</H3> </TH>\
|
||||
<TR>\
|
||||
<TH class='columnname'>Name</TH>\
|
||||
<TH class='columnname'>Records</TH>\
|
||||
<TH class='columnname'>Best Time</TH>\
|
||||
<TH class='columnname'>Held By</TH>\
|
||||
</TR>";
|
||||
break;
|
||||
case 'm':
|
||||
out = "<TABLE class='center'>\
|
||||
<TH class='tablename' COLSPAN='3'><H3><BR>Leaderboard</H3></TH>\
|
||||
<TR>\
|
||||
<TH class='columnname'>Rank</TH>\
|
||||
<TH class='columnname'>Name</TH>\
|
||||
<TH class='columnname'>Time</TH>\
|
||||
</TR>";
|
||||
break;
|
||||
case 'p':
|
||||
out = "<TABLE class='center'>\
|
||||
<TH class='tablename' COLSPAN='3'> <H3><BR>Ranks</H3> </TH>\
|
||||
<TR>\
|
||||
<TH class='columnname'>Name</TH>\
|
||||
<TH class='columnname'>Map</TH>\
|
||||
<TH class='columnname'>Rank</TH>\
|
||||
</TR>";
|
||||
break;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
//display and format the results of the query.
|
||||
void qresult(sqlite3_stmt *sp) {
|
||||
int e;
|
||||
unsigned int cc, i;
|
||||
while ((e = sqlite3_step(sp)) == SQLITE_ROW) {
|
||||
cc = sqlite3_column_count(sp);
|
||||
for (i = 0; i < cc; i++) {
|
||||
printf("%s", sqlite3_column_text(sp, i));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
bool executequery(const char *sql, const char *p) {
|
||||
sqlite3 *db;
|
||||
char *error;
|
||||
@ -40,15 +88,7 @@ bool executequery(const char *sql, const char *p) {
|
||||
}
|
||||
// bind parameter with a string length that is the # of bytes to null char.
|
||||
con = sqlite3_bind_text(s, 1, p, -1, NULL);
|
||||
int e;
|
||||
unsigned int cc, i;
|
||||
while ((e = sqlite3_step(s)) == SQLITE_ROW) {
|
||||
cc = sqlite3_column_count(s);
|
||||
for (i = 0; i < cc; i++) {
|
||||
printf("%s, ", sqlite3_column_text(s, i));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
qresult(s);
|
||||
sqlite3_finalize(s);
|
||||
sqlite3_close(db);
|
||||
return true;
|
||||
@ -71,9 +111,9 @@ void getquery(const char *qs) {
|
||||
fread(qf, sizeof(char), size, f);
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
qp = strchr(qs, '=') + 1; // increment to exclude '='
|
||||
printf("%x: \n\n%s\n", qf, qf);
|
||||
qp = strchr(qs, '=') + 1;
|
||||
executequery(qf, qp);
|
||||
free(qf);
|
||||
}
|
||||
@ -89,9 +129,9 @@ void html(void) {
|
||||
In-game database is not directly synced with this web server.\
|
||||
</p>\
|
||||
</body></html>";
|
||||
getquery(getenv("QUERY_STRING"));
|
||||
// getquery(getenv("QUERY_STRING"));
|
||||
|
||||
printf("%s %s", html_top, html_bot);
|
||||
return;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
|
Loading…
Reference in New Issue
Block a user