|
-
Sep 11th, 2003, 07:45 PM
#1
Thread Starter
Hyperactive Member
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.
-
Sep 12th, 2003, 08:22 AM
#2
Stuck in the 80s
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++;
}
-
Sep 12th, 2003, 10:06 PM
#3
Thread Starter
Hyperactive Member
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?
-
Sep 12th, 2003, 10:40 PM
#4
Stuck in the 80s
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>';
?>
-
Sep 12th, 2003, 10:41 PM
#5
Stuck in the 80s
That's just off the top of my head, mind you. So there may be syntax errors.
-
Sep 13th, 2003, 04:13 PM
#6
Thread Starter
Hyperactive Member
thank you very mmuch it workes great! exacly what i needed no syntax errors either. thanks again
-
Sep 13th, 2003, 07:57 PM
#7
Stuck in the 80s
Wow, I think that's a sign that I need to find a new hobby.
Don't forget to mark the thread resolved.
-
Sep 13th, 2003, 09:34 PM
#8
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|