#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    14
    Rep 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
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    8
    Rep 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).]
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    14
    Rep 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
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    8
    Rep 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
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    8
    Rep 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).]
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    14
    Rep Power
    0
    Ok,

    I'll try out your code (converting it to Oracle) and I'll see what happens

    Thanx,
    Yomo
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    8
    Rep 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
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    14
    Rep 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
  16. #9
  17. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    8
    Rep 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
  18. #10
  19. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    10
    Rep 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.
  20. #11
  21. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Location
    Jackson, TN, USA
    Posts
    18
    Rep 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>
  22. #12
  23. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    4
    Rep 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
  24. #13
  25. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    8
    Rep 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.
  26. #14
  27. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Location
    Jackson, TN, USA
    Posts
    18
    Rep 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

Similar Threads

  1. League table problem
    By silverduck in forum MySQL Help
    Replies: 8
    Last Post: February 10th, 2004, 01:38 PM
  2. populating table using another table and query
    By wombatwoo in forum PHP Development
    Replies: 0
    Last Post: February 9th, 2004, 06:24 AM
  3. Can anyone help with mysql query and results?
    By msmith29063 in forum MySQL Help
    Replies: 3
    Last Post: February 8th, 2004, 04:43 AM
  4. multiple table query
    By thestillman in forum MySQL Help
    Replies: 5
    Last Post: February 4th, 2004, 06:19 PM
  5. CONVERT Date? How to display results?
    By nadin in forum MS SQL Development
    Replies: 2
    Last Post: February 4th, 2004, 08:00 AM

IMN logo majestic logo threadwatch logo seochat tools logo