troubleshooting Question

Show text instead of row data - PHP /MYSQL

Avatar of Klaus Andersen
Klaus AndersenFlag for Germany asked on
Web DevelopmentPHPMySQL Server
7 Comments1 Solution940 ViewsLast Modified:
I have a search engine connected to a database that gives the results in a table.

How the table looks

The column organizer_id contains a number used as reference. Instead, should be the organizer name.


1280132044 should be Corporate Inc

In pseudo code I think should be like this:

If organizer_id is equal to (nº xxxxxxxxxx) THEN change it to (name of the organizer)

Can you give me a hand how to make this? I'm new in PHP/MYSQL

// DB Connection //

	$MySQLPassword = "***";	
	$HostName = "***";	
	$UserName = "***";
	$Database = "*****";

	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>');

	$tables = 'reports';
	$return_fields = 'id name organizer_id no_pages publication_date price currency';
	$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>";
	echo 	"<p>Your search '$query_text' 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 border=1>\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)) {
   echo "<tr>\n";

   printf("<td><a href=',%s'>%s</a></td>", $row['id'], str_replace(" ", "_", $row['name']), $row['name']);
   	$nombres_publisher = "SELECT t.nazwa AS nazwa FROM baza_obiektow_inne as t WHERE";
   printf("<td>%s</td>", $row['organizer_id']);
   printf("<td>%s</td>", $row['no_pages']);
   printf("<td>%s</td>", $row['publication_date']);
   printf("<td>%s</td>", $row['price']);
   printf("<td>%s</td>", $row['currency']);
   echo "</tr>\n";
	echo "</TABLE>\n";
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros