Jump to content

Results as columns


gokhul

Recommended Posts

Hi

Please check my code once.

 

 

mport_request_variables('p','p_');

      $connect=mysql_connect('localhost','gkkilaru','gkkilaru')

or die('could not open:'. mysql_error());

mysql_select_db('gkkilaru_db');

$result=mysql_query("SELECT * FROM human WHERE $p_Searchtype='$p_Search'");

 

 

if (mysql_num_rows($result)>0)

{

echo "<table cellpadding='1' cellspacing='1' bordercolor=pink width='800' border='1'>";

echo "<tr align='center'>";

echo "<td><b>KEGG_ID</b></td>";

echo "<td><b>Gene_Name</b></td>";

echo "<td><b>Uniprot_ID</b></td>";

echo  "</tr>";

 

while($row = mysql_fetch_object($result))

{

echo "<tr align='center'><td>";

echo $row->KEGG_ID;

echo "</td><td>";

echo $row->Gene_Name;

echo "</td><td>";

echo $row->Uniprot_ID;

echo "</td><td>";

 

}

}

else

{

echo "<tr align='center'><td>";

echo "<p><font size='4' color='red'>";

echo "No Records Found!</p>";

echo "</td></tr>";

}

//mysql_close($connection);

}

break;

}

 

 

I am getting the results horizontally.

Can someone help me with how to view my results vertically?

In the code above, I gave only 3 variables but in real time I need to work on large sets of data.

Please help me.

 

Link to comment
Share on other sites

while($row = mysql_fetch_object($result))

              {     

                  echo "<tr align='center'><td>";

                  echo $row->KEGG_ID;

                  echo "</td><td>";

                  echo $row->Gene_Name;

                  echo "</td><td>";

                  echo $row->Uniprot_ID;

                  echo "</td><td>";

                 

              }

 

 

Try:

while($row = mysql_fetch_object($result))

              {     

                  echo "<tr align='center'><td>";

                  echo $row->KEGG_ID;

                  echo "</td><td>";

                  echo $row->Gene_Name;

                  echo "</td><td>";

                  echo $row->Uniprot_ID;

                  echo "</td></tr>";

                 

              }

Link to comment
Share on other sites

      if (mysql_num_rows($result)>0)
         {
               echo "<table cellpadding='1' cellspacing='1' bordercolor=pink width='800' border='1'>";
               echo "<tr align='center'>";
               echo   "<td><b>KEGG_ID</b></td>";
               echo   "<td><b>Gene_Name</b></td>";
               echo   "<td><b>Uniprot_ID</b></td>";
               echo  "</tr>";

               $first_col = $second_col = $third_col = '<tr align="center">';

               while($row = mysql_fetch_object($result)) {
                    $first_col .= '<td>' . $row->KEGG_ID . '</td>';
                    $second_col .= '<td>' . $row->Gene_Name . '</td>';
                    $third_col .= '<td>' . $row->Uniprot_ID . '</td>';
               }

               $first_col .= '</tr>';
               $second_col .= '</tr>';
               $third_col .= '</tr>';
               echo $first_col . $second_col . $third_col;
         }

 

Does that work for you?

Link to comment
Share on other sites

the results are coming in columns but the titles are in row forms itself.

the result is like this

 

keggid genename uniprotid

xxx

yyy

zzz

 

 

but i want the result as

 

keggid        xxx

genename    yyy

uniprotid      zzz

 

 

 

thanks to everyone...who was helping me.

Link to comment
Share on other sites

I turned it in to a function so you're able to use it somewhere else a lot easier.

 

function returnResultsInColumns( $mysqlResult )
{
$queryResults = NULL;
if( mysql_num_rows($mysqlResult) > 0 )
{
	while($resultRow = mysql_fetch_array($mysqlResult))
	{
		for ($intPos = 0; $intPos < mysql_num_fields($mysqlResult); $intPos++)
		{
			$fieldName = mysql_field_name($mysqlResult, $intPos);
			$currentArrayPos = count( $queryResults[$fieldName] );
			$queryResults[$fieldName][$currentArrayPos] = $resultRow[$fieldName];
		}
	}
	$htmlTable = "<table>";
	foreach( $queryResults as $field => $results )
	{
		$htmlTable.= "<tr>";
		$htmlTable.= "<td>" . $field . "</td><td>" . implode( ", ", $results ) . "</td>";
		$htmlTable.= "</tr>";
	}
	$htmlTable.= "</table>";

	return $htmlTable;
}
else
{
	return "The query returned no results.";
}
}
// Pass the result of the MySQL query into the function.
$tableLayout = returnResultsInColumns( $result );

echo $tableLayout;

 

It's untested but should work :).

Link to comment
Share on other sites

hey thank you...

i got my desired results....

but it is giving an error like undefined index: genename

and undefined index:unprot_id near the line

 

$currentArrayPos = count( $queryResults[$fieldName] );

 

 

can u  check this out.

Link to comment
Share on other sites

mike.....thanks a lot

thankkkkkkkkkkkksssssssssssssssss

its working mike.

 

 

one more doubt is like can we put the results in a table?

please help regarding this one issue.

plzzzzzzzzzzzzzzzzzzzzzzz mike.

Link to comment
Share on other sites

hello,

i am getting the results in two columns after using the following code...

 

import_request_variables('p','p_');

      $connect=mysql_connect('localhost','gkkilaru','gkkilaru')

or die('could not open:'. mysql_error());

mysql_select_db('gkkilaru_db');

$result=mysql_query("SELECT * FROM human WHERE $p_Searchtype='$p_Search'");

 

function returnResultsInColumns( $mysqlResult )

{

$queryResults = NULL;

if( mysql_num_rows($mysqlResult) > 0 )

{

while($resultRow = mysql_fetch_array($mysqlResult))

{

for ($intPos = 0; $intPos < mysql_num_fields($mysqlResult); $intPos++)

{

$fieldName = mysql_field_name($mysqlResult, $intPos);

$currentArrayPos = ( isset( $queryResults[$fieldName] ) ? count( $queryResults[$fieldName] ) : 0);

$queryResults[$fieldName][$currentArrayPos] = $resultRow[$fieldName];

}

}

$htmlTable = "<table>";

foreach( $queryResults as $field => $results )

{

$htmlTable.= "<tr>";

$htmlTable.= "<td>" . $field . "</td><td>" . implode( ", ", $results ) . "</td>";

$htmlTable.= "</tr>";

}

$htmlTable.= "</table>";

return $htmlTable;

 

}

else

{

return "The query returned no results.";

}

}

// Pass the result of the MySQL query into the function.

 

$tableLayout = returnResultsInColumns($result);

echo $tableLayout;

 

 

 

can anyone let me know the code for how to place a border or table for the result obtained?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.