Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
gegeor
Forum Newbie
Posts: 4 Joined: Wed Jul 09, 2003 6:09 am
Post
by gegeor » Wed Jul 09, 2003 6:09 am
Hello.
)
I am trying to display mysql results into a php page but i want them into a simple table...How can i do that..? I have tried many ways using html but nothing worked.....
Here is my code:
Code: Select all
<?php
$serv_cnx = mysql_connect("localhost" , "db_username", "db_password");
$db_cnx = mysql_select_db("db_name",$serv_cnx);
$query = mysql_query("select * from efit_results order by 'id'");
while ($row = mysql_fetch_array($query)) {
echo " "
. $rowї"cell"] # reult 1
. "-->"
."<b>". $rowї"value"] ."</b>" #result 2
. "<br/>"
."</p>" ;
}
?>
Any help is appreciated
Thanks
:):)
Johnm
Forum Contributor
Posts: 344 Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:
Post
by Johnm » Wed Jul 09, 2003 8:31 am
This should get you going in the right direction.
FYI: I did not test this code...
Code: Select all
<?php
$serv_cnx = mysql_connect("localhost" , "db_username", "db_password");
$db_cnx = mysql_select_db("db_name",$serv_cnx);
$query = mysql_query("select * from efit_results order by 'id'");
echo "<table>\n";
echo "<tr>\n";
while ($row = mysql_fetch_array($query))
{
echo "<td>\n";
echo $rowї"cell"]."# reult 1\n";
echo "<b>". $rowї"value"]."</b>#result 2\n";
echo "</td>\n";
}
?>
</tr>
</table>
John M
gegeor
Forum Newbie
Posts: 4 Joined: Wed Jul 09, 2003 6:09 am
Post
by gegeor » Wed Jul 09, 2003 1:15 pm
I have managed to create the following:
(see webpage)
http://www.kastelliotis.net/sql4.php
The code is :
Code: Select all
<?php
include("something.php");
#if (!isset($mainfile)) { include("mainfile.php"); }
#$index = 1;
#include("header.php");
#OpenTable();
##################################
#include("header1.php");
while ($row = mysql_fetch_array($query)) {
$cell=$rowї"cell"];
$value=$rowї"value"];
$submit=$rowї"date"];
print"<html>\n";
print"<head>\n";
print"</head>\n";
print"<body>\n";
print"<center>\n";
print"<table width="50%" cellspacing="1" cellpadding="1" border="1">\n";
print"<tr>\n";
print"<td> $cell</td>\n";
print"<td> <b>$value</td>\n"; #OMADES
print" </tr>\n";
print"</table>\n";
print"</center>\n";
print"</body>\n";
print"</html>\n";
}
echo " <p><a href='sql4.php?add=12'> Page #1</a></p>" ;
echo " <p><a href='sql4.php?add=24'> Page #2</a></p>" ;
echo " <p><a href='sql4.php?add=36'> Page #3</a></p>" ;
?>
<?php
#CloseTable();
#include("footer.php");
#?>
But the table isnt very straight as you can see... Also is there a way to have background colors different at specific cells??
Any ideas.??
Thanks
Johnm
Forum Contributor
Posts: 344 Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:
Post
by Johnm » Wed Jul 09, 2003 2:18 pm
This is some pretty basic html stuff here but look at this:
Code: Select all
<?php
include("something.php");
#if (!isset($mainfile))
#{
# include("mainfile.php");
#}
#$index = 1;
#include("header.php");
#OpenTable();
##################################
#include("header1.php");
echo"<center>\n";
echo"<table width="50%" cellspacing="1" cellpadding="1" border="1">\n";
while ($row = mysql_fetch_array($query))
{
$cell=$row["cell"];
$value=$row["value"];
$submit=$row["date"];
echo "<tr>\n";
echo "<td width="50%" bgcolor="blue" align="right">$cell</td>\n";
echo "<td width="50%" bgcolor="red" align="right"><b>$value</td>\n"; #OMADES
echo "</tr>\n";
}
echo "</table>\n";
echo "</center>\n";
echo "<p><a href='sql4.php?add=12'>Page #1</a></p>" ;
echo "<p><a href='sql4.php?add=24'>Page #2</a></p>" ;
echo "<p><a href='sql4.php?add=36'>Page #3</a></p>" ;
#CloseTable();
#include("footer.php");
?>
I did not test this but you should be able to get the idea. Pay attention to the way you code as well.
John M
gegeor
Forum Newbie
Posts: 4 Joined: Wed Jul 09, 2003 6:09 am
Post
by gegeor » Wed Jul 09, 2003 4:04 pm
Your code worked fine.
)) Thank you very much and forgive me about my code...I am new to all these....
Thanks again:)))