Results 1 to 8 of 8

Thread: load database in tables...*resolved*

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    448

    load database in tables...*resolved*

    how can i loop through my database and have it print it out into a table...i have this but i need it to loop through three tr's and then go to a new row.

    PHP Code:
    $a=0;
                while (
    $a<2) {
                    while (
    $row mysql_fetch_array($data)) {
                        echo
    "<td>";
                        echo 
    $row['alumni_name']; echo $a;
                        echo
    "</td>";
                        
    $a $a+1;
                            while (
    $a>2) {
                            echo
    "</tr>"
                            
    $a=0
                            };
                    };

                }; 
    but the line $a=0; in the while ($a>2) {... it seems to ver load the server.

    does anyone have a better way of doing this? i have done it in asp which was originaly how it was but we are moving server and i dont know how to do this...can someone help me thanks. if you want to see what i mean by what i want to do in asp http://www33.brinkster.com/clrkkid/alumni.asp and if you want to see the asp code here it is...

    Code:
       if intCurr=0 then response.write("<tr>")
    
            'Response(oRS("alumni_id"))
    	Response.Write("<td>")
    	Response.Write("<b>" & oRS("alumni_name").Value & "</b><br>")
    	Response.Write(oRS("alumni_year").Value & "<br>")
    	Response.Write(oRS("alumni_adress").Value & "<br>")
    	Response.Write(oRS("alumni_phone").Value & "<br>")
    	Response.Write(oRS("alumni_email").Value & "<br>")
    	Response.Write(oRS("alumni_afterschool").Value & "<br><br>")
    	Response.Write("</td>")
    	oRS.MoveNext
    intCurr = intCurr+1
    if intCurr=3 then 
    response.write("</tr>")
    intCurr=0
    end if 
    
    Loop
    if intCurr<>0 then response.write("</tr>")
    thanks.
    Last edited by Muk108; Sep 13th, 2003 at 09:33 PM.

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    What are you trying to do? That code just confuses the crap out of me.

    If you give the full code for the ASP, I could probably convert it for you (although I've never worked with ASP before...it seems simple enough).

    At the bottom of the ASP code, you have "Loop", but I do not see anywhere where the loop is started. In your PHP code, I can't even see where the <tr> is started.

    If I had to take a guess at what you need...

    Code:
    $i = 0;
    
    echo '<tr>';
    while ($row = mysql_fetch_array($data)) {
        if ($i == 2) {
            echo '</tr><tr>';
            $i = 0;
        }
         
        echo '<td>' . $row['alumni_name'] . '<br />' .
                    $row['alumni_year'] . '<br />
                </td>'; //etc
    
        $i++;
    }
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    448
    well here is my asp code...

    Code:
    <%
    
    Dim oConn
    Dim oRS
    Dim sSQL
    Dim sColor
    dim intCurr 
    intCurr=0
    
    
    Set oConn = Server.CreateObject("ADODB.Connection")
    oConn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\clrkkid\db\alumni.mdb"))
    
    sSQL = "SELECT alumni_id, alumni_name, alumni_year, alumni_adress, alumni_phone, alumni_email, alumni_afterschool FROM alumni"
    Set oRS = oConn.Execute(sSQL)
    
    
    	Response.Write("<table>")
    
    Do While NOT oRS.EOF 
    
    
       if intCurr=0 then response.write("<tr>")
    
            'Response(oRS("alumni_id"))
    	Response.Write("<td>")
    	Response.Write("<b>" & oRS("alumni_name").Value & "</b><br>")
    	Response.Write(oRS("alumni_year").Value & "<br>")
    	Response.Write(oRS("alumni_adress").Value & "<br>")
    	Response.Write(oRS("alumni_phone").Value & "<br>")
    	Response.Write(oRS("alumni_email").Value & "<br>")
    	Response.Write(oRS("alumni_afterschool").Value & "<br><br>")
    	Response.Write("</td>")
    	oRS.MoveNext
    intCurr = intCurr+1
    if intCurr=3 then 
    response.write("</tr>")
    intCurr=0
    end if 
    
    Loop
    if intCurr<>0 then response.write("</tr>")
    
    
    	Response.Write("</table><br>")
    
    oConn.Close
    Set oRS = Nothing
    Set oConn = Nothing
    
    %>
    anythoughts?

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Code:
    <?php
    
    $db = mysql_connect(/*blahblahblah*/) or die(mysql_error());
    mysql_select_db("database", $db);
    
    $sql = "SELECT * FROM alumni";
    $alumni = mysql_query($sql) or die(mysql_error());
    
    
    echo '<table>
        <tr>';
    
    while ($alumnus = mysql_fetch_array($alumni)) {
    
        if ($i == 2) {
            echo '</tr><tr>';
            $i = 0;
        }
    
        echo '<td><b>' . $alumnus['alumni_name'] . '</b><br>';
        echo $alumnus['alumni_year'] . '<br>';
        echo $alumnus['alumni_adress'] . '<br>';
        echo $alumnus['alumni_phone'] . '<br>';
        echo $alumnus['alumni_email'] . '<br>';
        echo $alumnus['alumni_afterschool'] . '<br><br></td>';
    
        $i++;
    }
    
    echo '</tr></table><br>';
    
    ?>
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    That's just off the top of my head, mind you. So there may be syntax errors.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    448
    thank you very mmuch it workes great! exacly what i needed no syntax errors either. thanks again

  7. #7
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Wow, I think that's a sign that I need to find a new hobby.

    Don't forget to mark the thread resolved.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    448
    Originally posted by The Hobo
    Wow, I think that's a sign that I need to find a new hobby.

    Don't forget to mark the thread resolved.
    na that just means your the best thanks agian, and it is now marked

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width