Replace text from Colum names titles - PHP MYSQL

Hello,

When I get  the results from a search engine, the column names comes up with the same name that has in the database.

http://postimg.org/image/59y36mih7/

I will like to change the titles for the columns:

name= Market Report Title
organizer_id= Publisher
no_pages= Nº of Pages
publication_date: Date Published
price: Price

This is an extract of the code where I get the results from the query and the columns

<?php


// DB Connection //
/* Change the following 3 values to reflect your MySQL Server */
	$MySQLPassword = "***";	
	$HostName = "***";	
	$UserName = "****";
	$Database = "****";

	mysql_connect($HostName,$UserName,$MySQLPassword)
	or die("ERROR: Could not connect to database!");
 	mysql_select_db($Database) or die("cannot select db");

// Data Sorting Variables //
/* The following are used to set the columns for data sorting                */
/* Change these to the table field names in your MySQL database              */
	$default_sort = 'ID';
	$allowed_order = array ('name','publication_date', 'price');
	

/* if order is not set, or it is not in the allowed
 * list, then set it to a default value. Otherwise, 
 * set it to what was passed in. */
	if (!isset ($_GET['order']) || 
	    !in_array ($_GET['order'], $allowed_order)) {
	    $order = $default_sort;
	} else {
	    $order = $_GET['order'];
	}

// The following line stops the undefined index error on initial page load
	if (isset($_GET['keyword'])) {

	        if(!$_GET['keyword']) {
	          die('<p>Please enter a search term.</p>');
	  	}     

// Database Query Settings //
/* Change these to match your database table, the fields you want displayed and the fields to run the query against. */
	$opcion_busqueda = $_GET['radio'];
	
	if ($opcion_busqueda == 2){
		
		$tables = 'swots';
	}
	
	else {
		$tables = 'reports';
		}
	
	
	
	$return_fields = 'id name organizer_id no_pages publication_date price currency';
	if  ($opcion_busqueda == 3){
		
		$check_fields = 'table_content description';

	}
	
	else {
	$check_fields = 'name';
	}

// Get the keyword from the search form.
 	$query_text = $_GET['keyword'];
    

// Sanitize Data Input
	$clean_query_text =cleanQuery($query_text);


// Call the bq_simple function and store the //
// resulting SQL Query in $newquery variable //
	$newquery=bq_simple ($return_fields, $tables, $check_fields, $clean_query_text);
	$newquery = $newquery . " ORDER BY $order;";




// sql data query construction //
	$result = mysql_query($newquery) or die(mysql_error());

/* make sure data was retrieved */
	$numrows = mysql_num_rows($result);
	if ($numrows == 0) {
	    echo "<H4>No data to display!</H4>";
	    exit;
	}
	echo 	"<p>Your search: '$query_text' within </p>\n";	
	
	if ($opcion_busqueda == 1){
		echo " market reports titles";}
		else if ($opcion_busqueda == 3) {
		echo " All content";}
	 else {echo " SWOTS";} 	
	 
	 echo "<p>returned ".$numrows. " results.</p>\n";
	echo 	"<p>Click on the headings to sort.</p>\n";


/* now grab the first row and start the table */
	$row = mysql_fetch_assoc ($result);
	echo "<TABLE cellspacing=\"3\" cellpadding=\"8\">\n";
	
	echo "</TR>\n";
	 foreach ($row as $heading=>$column) {
      if ($heading != 'id') { //don't create a column for ID!
         echo "<TD><b>";
         if (in_array ($heading, $allowed_order)) {
            echo "<a href=\"{$_SERVER['PHP_SELF']}?order=$heading&keyword=$query_text\">$heading</a>";
         } else {
            echo $heading;
         }                
         echo "</b></TD>\n";
      }
   }
echo "</TR>\n";

/* reset the $result set back to the first row and 
 * display the data */
	
	mysql_data_seek ($result, 0);
	while ($row = mysql_fetch_assoc ($result)) {
   //get the publisher name
  $organizerSql = mysql_query("SELECT nazwa FROM baza_obiektow_inne WHERE id=" . $row['organizer_id'] . " LIMIT 1");
   $organizer = mysql_fetch_assoc($organizerSql);
   $pretty_date = date('F Y', strtotime($row['publication_date']));
   echo "<tr>\n";
   $simbolos_reemplazar = array (" ","%","/");
   printf("<td><a href='http://embs-group.com/%s,%s'>%s</a></td>", $row['id'], str_replace( $simbolos_reemplazar, "_", $row['name']), $row['name']);
   printf("<td>%s</td>", $organizer['nazwa']);
   printf("<td>%s</td>", $row['no_pages']);
 printf("<td>%s</td>", $pretty_date);
   printf("<td>%s</td>", $row['price']);
   printf("<td>%s</td>", $row['currency']);
  
   echo "</tr>\n";

}

}

Open in new window

Klaus AndersenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GaryCommented:
if ($heading != 'id') { //don't create a column for ID!
	echo "<TD><b>";
	// Just add in here your changes
	if($heading=="name"){$new_heading="Market Report Title";}
	elseif($heading=="organizer_id"){$new_heading="Publisher";}
	// etc
	// etc
	if (in_array ($heading, $allowed_order)) {

		echo "<a href=\"{$_SERVER['PHP_SELF']}?order=$heading&keyword=$query_text\">$new_heading</a>"; // Use new var here
	} else {
		echo $new_heading;
	 }                
	echo "</b></TD>\n";
 }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Klaus AndersenAuthor Commented:
It worked like a charm Gary, many thanks!

By the way, taking advance that you understood quite quickly my code, could you give me a hand with this question?

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28239690.html

I´m stuck there from some days and will be amazing if you can give me a hand, thanks!
0
Klaus AndersenAuthor Commented:
@GaryC123 provided me a fast and exact answer for my problem. After the test it worked perfectly. Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.