Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $hostname = "localhost";
- $dbuser = "thestory_carl";
- $dbpassword = "carl";
- $dbname = "thestory_mancstore";
- $db_link=mysql_connect($hostname, $dbuser, $dbpassword)
- or die("Unable to connect to the server!");
- mysql_select_db($dbname)
- or die("Unable to connect to the database");
- $fields_array=array();
- $num_fields=0;
- $num_row=0;
- $sql="select * from customers ";
- // find position of "FROM" in query
- $fpos=strpos($sql, 'from');
- // get string starting from the first word after "FROM"
- $strfrom=substr($sql, $fpos+5, 50);
- // Find position of the first space after the first word in the string
- $Opos=strpos($strfrom,' ');
- //Get table name. If query pull data from more then one table only first table name will be read.
- $table=substr($strfrom, 0,$Opos);
- // Get result from query
- $result=mysql_query($sql);
- $num_row=mysql_numrows($result);
- print('<html>');
- print('<head><title>');
- print('View '.$table.'</title>');
- print("</head>");
- print('<body><br>');
- if($num_row >0)
- {
- //Get number of fields in query
- $num_fields=mysql_num_fields($result);
- # get column metadata
- $i = 0;
- //Set table width 15% for each column
- $width=10 * $num_fields;
- print('<br><table width='.$width.'% align="center"><tr>');
- print('<tr><th colspan='.$num_fields.'>View '.$table.'</th></tr>');
- while ($i < $num_fields)
- {
- //Get fields (columns) names
- $meta = mysql_fetch_field($result);
- $fields_array[]=$meta->name;
- //Display column headers in upper case
- print('<th><b>'.strtoupper($fields_array[$i]).'</b></th>');
- $i=$i+1;
- }
- print('</tr>');
- //Get values for each row and column
- while($row=mysql_fetch_row($result))
- {
- print('<tr>');
- for($i=0; $i<$num_fields; $i++)
- {
- //Display values for each row and column
- print('<td>'.$row[$i].'</td>');
- }
- print('</tr>');
- }
- }
- $db_link=mysql_connect($hostname, $dbuser, $dbpassword)
- or die("Unable to connect to the server!");
- mysql_select_db($dbname)
- or die("Unable to connect to the database");
- $fields_array=array();
- $num_fields=0;
- $num_row=0;
- $sql="select * from customers ";
- // find position of "FROM" in query
- $fpos=strpos($sql, 'from');
- // get string starting from the first word after "FROM"
- $strfrom=substr($sql, $fpos+5, 50);
- // Find position of the first space after the first word in the string
- $Opos=strpos($strfrom,' ');
- //Get table name. If query pull data from more then one table only first table name will be read.
- $table=substr($strfrom, 0,$Opos);
- // Get result from query
- $result=mysql_query($sql);
- $num_row=mysql_numrows($result);
- print('<html>');
- print('<head><title>');
- print('View '.$table.'</title>');
- print("</head>");
- print('<body><br>');
- if($num_row >0)
- {
- //Get number of fields in query
- $num_fields=mysql_num_fields($result);
- # get column metadata
- $i = 0;
- //Set table width 15% for each column
- $width=10 * $num_fields;
- print('<br><table width='.$width.'% align="center"><tr>');
- print('<tr><th colspan='.$num_fields.'>View '.$table.'</th></tr>');
- while ($i < $num_fields)
- {
- //Get fields (columns) names
- $meta = mysql_fetch_field($result);
- $fields_array[]=$meta->name;
- //Display column headers in upper case
- print('<th><b>'.strtoupper($fields_array[$i]).'</b></th>');
- $i=$i+1;
- }
- print('</tr>');
- //Get values for each row and column
- while($row=mysql_fetch_row($result))
- {
- print('<tr>');
- for($i=0; $i<$num_fields; $i++)
- {
- //Display values for each row and column
- print('<td>'.$row[$i].'</td>');
- }
- print('</tr>');
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement