Your mysql_query() calls can fail in many ways, so they need error handling.
To debug query calls, stub out the query that your program has built, copy & paste it into the mysql program to see what query building errors you need to fix in your code.
Re formatting, absent html tables or an equivalent library, you need to format the data yourself, as in this very basic c code ...
for( lrow = 0; lrow < rows; lrow++ ) {
if(( row = mysql_fetch_row( rset )) != NULL ) {
for( icol = 0; icol < cols; icol++ ) {
column = columns[icol];
if( column != NULL ) {
if( strlen( row[icol] ) > column->max_length ) {
column->max_length = strlen( row[icol] );
}
}
}
}
}
for( icol = 0; icol < cols; icol++ ) {
printf( "%-*s ", columns[icol]->max_length, strupr( columns[icol]->name ));
}
printf( "\n" );
mysql_data_seek( rset, 0 );
for( lrow = 0; lrow < rows; lrow++ ) {
if(( row = mysql_fetch_row( rset )) != NULL ) {
for( icol = 0; icol < cols; icol++ ) {
printf( "%-*s ", columns[icol]->max_length, row[icol] );
}
printf( "\n" );
}
}
printf( "%d %s\n", rows, "rows returned." );
mysql_free_result( rset );
mysql_close( conn );
return 0;