Jump to content

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
https://forums.phpfreaks.com/topic/156331-results-as-columns/
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
https://forums.phpfreaks.com/topic/156331-results-as-columns/#findComment-823113
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
https://forums.phpfreaks.com/topic/156331-results-as-columns/#findComment-823995
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
https://forums.phpfreaks.com/topic/156331-results-as-columns/#findComment-824178
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
https://forums.phpfreaks.com/topic/156331-results-as-columns/#findComment-824184
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
https://forums.phpfreaks.com/topic/156331-results-as-columns/#findComment-825069
Share on other sites

Is there a reason you need that for loop inside that while loop? Mikedean did that because he doesn't know your table columns. You really shouldn't need it. It's a waste.

 

If you want a border, just add the border attribute to the table tag.

 

One more thing, read rule #13 - http://www.phpfreaks.com/page/forum-rules

Link to comment
https://forums.phpfreaks.com/topic/156331-results-as-columns/#findComment-825092
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.