채택완료

테이블 나누기

2015-09-10 (목) 18:03:53 2,970

그 최신글을 불러오는데 생긴 문제가있습니다.

<table width="600" border="0" align="center">

<?

$sql = "select * from $board where bo_table='freeboard' ";

$result = mysql_query($sql, $connect);

while($row = mysql_fetch_array($result)){

?>

<tr>

<td><?=$row[name]?>

</td>

</tr>

<?

}

?>

</table>

이렇게해서 나뒀는데

이렇게 이미지를 보시다시피

밑으로만 나옵니다. 밑으로 나오면서 옆으로도 나오게하는방법이 없을까요?

그래서

<?

if($cnt%2==0) echo "<tr><td></td></tr>";

?>

이렇게 했는데.. 잘 모르겠떠라구요.. 밑으로 나오면서 옆으로도 나오게하고싶은데..ㅜ

도와주세요우ㅜcf0c5a40b05ee8ef710f50ea6be84539_1441875723_0633.jpg 

답변 3개 / 댓글 8개

채택된 답변
+20 포인트

tr 태그가 저렇게 loop 돌때마다 나오면 당연히 줄바꿈해서 나옵니다

아래처럼

<table width="600" border="0" align="center">

<tr><-----------여기 tr추가

<?

$sql = "select * from $board where bo_table='freeboard' ";

$result = mysql_query($sql, $connect);

$k=0; //---추가 

while($row = mysql_fetch_array($result)){

$k++;

if($k % 2 == 1) echo "</tr>tr>"; <--- 조건 3,5,7,9...일때 줄바꿈

?>

<td><?=$row[name]?></td>

<?}?>

</tr> <---추가

</table> 

답변에 대한 댓글 1개

정말 감사합니다. ㅜㅜ
2015-09-10 (목) 23:34:27

<table width="600" border="0" align="center">

<?

$sql = "select * from $board where bo_table='freeboard' ";

$result = mysql_query($sql, $connect);

while($row = mysql_fetch_array($result)){

?>

<tr>

<td>

<div style="width:250px; display:inline-block;"><?=$row['name']?></div>

<div style="width:250px; display:inline-block;"><?=$row['name']?></div>

</td>

</tr>

<?

}

?>

</table>

이런 식으로 바꿔 보세요. 

2015-09-10 (목) 20:17:03

while($row = mysql_fetch_array($result)){

?>

<tr>

<td><?php $row['name']?></td>

<td><?php $row['필드이름2']?></td>

<td><?php $row['필드이름3']?></td>

<td><?php $row['필드이름4']?></td>

</tr>

<?php

}

?> 

답변에 대한 댓글 7개

아.. 네 그렇게는되는데.. 옆으로도 좀 나오게하고싶어서

그거물어본건데ㅎㅎㅎ
옆으로 나온다는 게 구체적으로 어떤 것인지요?
테이블 하나 더 병렬로 나오게 하시려는 건가요?
네 마자용 ㅠㅠ 옆으로 하나더 행을 만들고싶은데..
그러면 그누보드처럼 해당소스(위의 소스)를 함수에 담아서 출력하시면 여러번 중복해서 구현할 수 있습니다.

그렇지 않다면 다음과 같이 위의 소스를 한 번 더 실행해야 할 겁니다.
[code]
<!-- freeboard 의 최신글 -->
<table width="300" border="0" align="left">
<?php
$sql = "select * from $board where bo_table='freeboard' ";
$result = mysql_query($sql, $connect);

while($row = mysql_fetch_array($result)){
?>
<tr><td><?=$row[name]?></td></tr>
<?php } ?>
</table>

<!-- noticeboard 의 최신글 -->
<table width="300" border="0" align="right">
<?php
$sql = "select * from $board where bo_table='noticeboard' ";
$result = mysql_query($sql, $connect);

while($row = mysql_fetch_array($result)){
?>
<tr><td><?=$row[name]?></td></tr>
<?php } ?>
</table>
[/code]
아니 알려주신대로만 하면 밑으로만 나와요
table 의 넓이를 300으로 하고 각각 align 을 left, right 로 해도 그렇습니까?
만약 그렇다면 width 값을 좀더 줄여 보시고,
그래도 안되면
<table border="0" style="display:inline-block; width:300px; text-align:left;">
이런 식으로 테이블에 스타일을 적용해 보세요.
알려주신대로만하면

내용물
내용물
내용물
내용물

이렇게나오고

제가 원하는것은

내용물 내용물
내용물 내용물
내용물 내용물
내용물 내용물

이런식으로 나오게하는거라구요

답변을 작성하려면 로그인이 필요합니다.