PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 11th, 2000, 07:18 AM
djmouse djmouse is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2000
Posts: 14 djmouse User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #2  
Old April 11th, 2000, 08:43 AM
geosync geosync is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2000
Posts: 8 geosync User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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).]

Reply With Quote
  #3  
Old April 11th, 2000, 09:23 AM
djmouse djmouse is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2000
Posts: 14 djmouse User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #4  
Old April 11th, 2000, 03:21 PM
geosync geosync is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2000
Posts: 8 geosync User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #5  
Old April 11th, 2000, 03:37 PM
geosync geosync is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2000
Posts: 8 geosync User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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).]

Reply With Quote
  #6  
Old April 12th, 2000, 03:27 AM
djmouse djmouse is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2000
Posts: 14 djmouse User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #7  
Old April 12th, 2000, 08:03 PM
geosync geosync is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2000
Posts: 8 geosync User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #8  
Old April 13th, 2000, 12:15 PM
djmouse djmouse is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2000
Posts: 14 djmouse User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #9  
Old April 13th, 2000, 02:35 PM
geosync geosync is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2000
Posts: 8 geosync User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #10  
Old April 14th, 2000, 03:59 AM
tony styles tony styles is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2000
Posts: 10 tony styles User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #11  
Old April 14th, 2000, 09:17 AM
moliver moliver is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2000
Location: Jackson, TN, USA
Posts: 18 moliver User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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>

Reply With Quote
  #12  
Old April 14th, 2000, 11:27 AM
CAL128 CAL128 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2000
Posts: 4 CAL128 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #13  
Old April 14th, 2000, 01:22 PM
geosync geosync is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2000
Posts: 8 geosync User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #14  
Old April 17th, 2000, 09:12 AM
moliver moliver is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2000
Location: Jackson, TN, USA
Posts: 18 moliver User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Display results from query in HTML-table

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap