The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Display results from query in HTML-table
Discuss Display results from query in HTML-table in the PHP Development forum on Dev Shed. Display results from query in HTML-table PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

April 11th, 2000, 07:18 AM
|
|
Junior Member
|
|
Join Date: Apr 2000
Posts: 14
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Hi,
I'm working with PHP3 and Oracle 8.
Can anyone tell me how to display the results from a query into my HTML-table?
Thanx,
Dj
|

April 11th, 2000, 08:43 AM
|
|
Junior Member
|
|
Join Date: Apr 2000
Posts: 8
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
i am currently working on the same thing, albeit slowly. i want to run queries on a mysql database and populate the cells of a template with the results. i will post up when i find the time to get this accomplished.
[This message has been edited by geosync (edited April 11, 2000).]
|

April 11th, 2000, 09:23 AM
|
|
Junior Member
|
|
Join Date: Apr 2000
Posts: 14
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Well, ok, but do remember that the syntax with an Oracle 8 database is quite different from PHP with MySQl.
I'll wait and see what you've come up with.
Dj
|

April 11th, 2000, 03:21 PM
|
|
Junior Member
|
|
Join Date: Apr 2000
Posts: 8
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
once you have the concept then translating from mySQL to Oracle shouldn't be too difficult.
i have found some code that displays data in the following way:
-----------------------------
row1 | field 1 | field 2 | field 3 |
-----------------------------
row2 | field 1 | field 2 | field 3 |
-----------------------------
i didn't have a difficult time comprehending the code and am now trying to work through a modification that does the following:
-------------------------------
| row 1 | row 2 | row 3 | row 4 |
-------------------------------
| row 5 | row 6 | row 7 | row 8 |
------------------------------
being a once in a while pseudo-programmer i am pretty please with how its going so far. any hints on populating the row data across the cells in an HTML table would be great.
dG
|

April 11th, 2000, 03:37 PM
|
|
Junior Member
|
|
Join Date: Apr 2000
Posts: 8
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
modified from nova2's code gallery example of table coloring on www.zend.com
<html>
<body>
<?
mysql_pconnect("localhost", "*****", "*****") or die("error connecting to database");
mysql_select_db("events") or die("error selecting database");
$rs = mysql_query("SELECT ID, Name, City, County, Date FROM events order by $listEvents ASC");
$num = mysql_num_rows($rs);
$i = 0;
echo "<TABLE width=650 align=center cellpadding=4 cellspacing=0>";
echo "<tr>";
echo "<td width=35%>Event Name</td>";
echo "<td width=20%>City</td>";
echo "<td width=20%>County</td>";
echo "<td width=20%>Date</td>";
echo "<td width=5%>*</td>";
echo "</tr>";
while ($i < $num):
$id = mysql_result($rs,$i,"ID");
$name = mysql_result($rs,$i,"Name");
$city = mysql_result($rs,$i,"City");
$county = mysql_result($rs,$i,"County");
$date = mysql_result($rs,$i,"Date");
$name = "<a href=details.php3?id=$id&mode=1>" . $name . "</a>";
echo "<tr>"
echo "<td>" . $name . "</td>";
echo "<td>" . $city . "</td>";
echo "<td>" . $county . "</td>";
echo "<td>" . date("M j, Y", $date) . "</td>";
echo "<td><a href=Action.php3?id=$id&mode=2 title="Edit"><img src="edit.gif" border=0></a></td>";
echo "</tr>";
$i+;
endwhile;
break;
?>
</body>
</html>
i hope i haven't butchered it too bad. i a am at work w/o access to apache, php3, or mysql.
[This message has been edited by geosync (edited April 11, 2000).]
[This message has been edited by geosync (edited April 11, 2000).]
[This message has been edited by geosync (edited April 11, 2000).]
|

April 12th, 2000, 03:27 AM
|
|
Junior Member
|
|
Join Date: Apr 2000
Posts: 14
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
Ok,
I'll try out your code (converting it to Oracle) and I'll see what happens
Thanx,
Yomo
|

April 12th, 2000, 08:03 PM
|
|
Junior Member
|
|
Join Date: Apr 2000
Posts: 8
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
this should be it. i don't have a box to test it on right now. i am not sure if i need the extra break; in there
<?
mysql_pconnect("locahost", "*****", "*****") or die("error connecting to database");
mysql_select_db("events") or die("error selecting database");
$rs = mysql_query("SELECT ID, Name, City, County, Date FROM events order by $listEvents ASC");
$num = mysql_num_rows($rs);
$i=0;
echo "<table width=650 align=center cellpadding=4 cellspacing=0>";
echo "<tr>"'
echo "<td width=35%>Event Name</td>";
echo "<td width=20%>City</td>";
echo "<td width=20%>County</td>";
echo "<td width=20%>Date</td>";
while ($i < $num):
a$ = $i;
echo "<tr>";
while ($a < $num):
$id = mysql_results($rs,$a,"ID");
$id = mysql_results($rs,$a,"Name");
$id = mysql_results($rs,$a,"City");
$id = mysql_results($rs,$a,"County");
$id = mysql_results($rs,$a,"Date");
echo "<td>"
echo "<p>" . $name . "</p>";
echo "<p>" . $city . "</p>";
echo "<p>" . $county . "</p>";
echo "<p>" . $date . "</p>";
echo "</td>
$a = $a++;
endwhile;
break;
$i = $i + 3;
endwhile;
break;
?>
dG
|

April 13th, 2000, 12:15 PM
|
|
Junior Member
|
|
Join Date: Apr 2000
Posts: 14
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Thanx Geosync.
I have it already. The code is quite different from mySQL, but it works.
Your code helped me on my way though.
Dj
|

April 13th, 2000, 02:35 PM
|
|
Junior Member
|
|
Join Date: Apr 2000
Posts: 8
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
When you get the time, would you post your code for Oracle? I'd like to see the differences between them.
thanks,
dG
|

April 14th, 2000, 03:59 AM
|
|
Junior Member
|
|
Join Date: Mar 2000
Posts: 10
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
I was asked to generate html tables from the results of mysql - in C++ on Unix.
I have a nicely contained class that interfaces with a mysql database through its C API.
If anyone is in need I will be happy to send them the code.
|

April 14th, 2000, 09:17 AM
|
|
Junior Member
|
|
Join Date: Apr 2000
Location: Jackson, TN, USA
Posts: 18
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Ok, guys, you really seem to know what you are doing. I am new to PHP and mySQL, but really excited about using it. I have no problems getting a query in tables, but I want to alternate the color of the row. I have tried and tried to no avail. I am posting my code below that works to get the table, but thus far, has not produced alternating colors. I am sure you guys have done this with ease, and I could really use your help.
Here it is: (that format is not great, but it's just a test)
<table cellspacing=0 cellpadding=0 border=1>
<?
# setup SQL statement
$SQL = " SELECT * FROM mytable ";
# execute SQL statement
$retid = mysql_db_query($db, $SQL, $cid);
# Get num of rows
$numrows = mysql_numrows($retid);
# check for errors
if (!$retid) { echo( mysql_error()); }
else {
# display results
while ($row = mysql_fetch_array($retid))
{
$name = $row["Name"];
$add1 = $row["Add1"];
$add2 = $row["Add2"];
$add3 = $row["Add3"];
$desc = $row["Description"];
$contact = $row["Contact"];
$phone = $row["Phone"];
$tfree = $row["Tollfree"];
$fax = $row["Fax"];
$url = $row["URL"];
$email = $row["Email"];
for ($i=0; $i<$numrows; $i++);
if (($i % 2) == 0) { $bgcolor = ffffff; }
else { $bgcolor = DCDCDC; }
echo ( "<tr bgcolor=$bgcolor>
<td valign=top>
<font face=arial size=2><b>$name</b>n" );
if ($add1 > "")
{ echo ("<br> $add1 n"); }
if ($add2 > "")
{ echo ("<br> $add2 n"); }
if ($add3 > "")
{ echo ("<br> $add3 n"); }
if ($desc > "")
{ echo ("<br><br> $desc n"); }
echo ( "</font>
<td valign=top>
<font face=arial size=2>n" );
if ($contact > "")
{ echo ("$contact n"); }
if ($phone > "")
{ echo ("<br> $phone n"); }
if ($tfree > "")
{ echo ( "<br> $tfree n"); }
if ($fax > "")
{ echo ("<br> $fax n"); }
if ($url > "")
{ echo ("<br> <a href=http://$url>$url</a> n"); }
if ($email > "")
{ echo ("<br> <a href=mailto:$email>$email</a> n"); }
echo ("</font>
</td></tr>n");
}
}
?>
</table>
|

April 14th, 2000, 11:27 AM
|
|
Junior Member
|
|
Join Date: Apr 2000
Posts: 4
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Re: Alternating cell colors
I'm new to PHP, but I once did something similar in Perl to what you're trying to accomplish.
Basically, I set a boolean flag called "isgray" and alternated it. This is a Perl snippet:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
# Alternating lines
$isgray = 0;
for ($x = 0; $x < 5; $x++) {
if ($isgray) {
print ("This line is grayn");
} else {
print ("This line is whiten");
}
$isgray = abs ($isgray - 1);
}
[/code]
I'm not certain if this would work in PHP, but give it a try and tell me what happens!
Chris
|

April 14th, 2000, 01:22 PM
|
|
Junior Member
|
|
Join Date: Apr 2000
Posts: 8
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
moliver,
the code i started with was for alternating colors in a table. i pulled it from nova2's code gallery example of table coloring on www.zend.com
if you look you will it. it is pretty straight forward. oh and this code was my first attempt at using both mySQL and PHP. i have limited experience in Python, Perl. i can follow code but tend not to write it out of laziness. 
|

April 17th, 2000, 09:12 AM
|
|
Junior Member
|
|
Join Date: Apr 2000
Location: Jackson, TN, USA
Posts: 18
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
geosync,
I used the code from www.zend.com and it worked. Thanks to all for the support, I really appreciated it. I have already converted it to do other things I needed.
Mike
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|