ช่วยดูโค๊ดหน่อยค่ะ (ถามทุกวันเลย อิอิ)

เริ่มโดย icenobu, 23 สิงหาคม 2012, 09:36:35

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

icenobu

พอดีทำหน้าโชว์ข่าวสารอ่ะค่ะ พอกดแอดข่าวไปเรื่อยๆ มันไม่ยอมขึ้นบรรทัดใหม่อ่ะค่ะ มันต่อออกไปขวามือเราเรื่อยๆเลย
จะทำยังไงให้ข่าวล่าสุดขึ้นไปบนสุด ข่าวเก่าถูกดันลง


<table width="99%" border=0 align="center" cellpadding=2 cellspacing=0>
  <tr>
    <td width="100%" height="76" align=center class="type_C"><p>แจ้งข่าวสาร</p>
      <p>
        <?
      $sql="SELECT news_detail FROM news WHERE isused='T' ";
$query=mysql_query($sql);
while($rs=mysql_fetch_array($query)){
  ?>
        <?=$rs['news_detail']?>
        <? }?>
      </p>
</p>
    <p>&nbsp;</p></td>
  </tr>
</table>
มือใหม่หัดเขียนเว็บ O(x^^)o
[direct=http://petdeecare.com]สุนัขป่วย[/direct]
[direct=http://petdeecare.com]แมวป่วย[/direct]
[direct=http://petdeecare.com]กระต่ายป่วย[/direct]
[direct=http://www.petdeecare.com/index.php?topic=199.0]แจกสุนัข[/direct]
[direct=http://www.viptashop.com]จำหน่ายชุดเดรส[/direct]

ccsakuna


หนูว่าจะต้องมีบรรทัดนี้เพิ่มนะ

$number = mysql_num_rows($query);
for($i=1;$i<=$number;$i++) {
xxxxxx
xxxxxx
<? } ?>

เว็บดูการ์ตูน ขายแบนเนอร์ 300 บาทต่อเดือน| [direct=http://www.cartoondek.com]ดูการ์ตูนออนไลน์[/direct] , [direct=http://www.ondims.com]สอนการตลาดออนไลน์[/direct] , [direct=http://www.dooconcert.com]ดูคอนเสิร์ตออนไลน์[/direct], [direct=http://www.pranui.com]ตลับพระ,ตลับเงินลงยา[/direct],
[direct=http://www.waxena.com]วาซีน่า ไวท์เทนนิ่ง[/direct],

verysims

#2
อ้างถึงจาก: icenobu ใน 23 สิงหาคม 2012, 09:36:35
พอดีทำหน้าโชว์ข่าวสารอ่ะค่ะ พอกดแอดข่าวไปเรื่อยๆ มันไม่ยอมขึ้นบรรทัดใหม่อ่ะค่ะ มันต่อออกไปขวามือเราเรื่อยๆเลย
จะทำยังไงให้ข่าวล่าสุดขึ้นไปบนสุด ข่าวเก่าถูกดันลง


<table width="99%" border=0 align="center" cellpadding=2 cellspacing=0>
  <tr>
    <td width="100%" height="76" align=center class="type_C"><p>แจ้งข่าวสาร</p>
      <p>
        <?
      $sql="SELECT news_detail FROM news WHERE isused='T' ";
$query=mysql_query($sql);
while($rs=mysql_fetch_array($query)){
  ?>
        <?=$rs['news_detail']?>
        <? }?>
      </p>
</p>
    <p>&nbsp;</p></td>
  </tr>
</table>



ลองแบบนี้ดูครับ


<table width="99%" border=0 align="center" cellpadding=2 cellspacing=0>
  <tr>
    <td width="100%" height="76" align=center class="type_C"><p>แจ้งข่าวสาร</p></td>
</tr>

<?php
      
$sql="SELECT news_detail FROM news WHERE isused='T' order by your_table_id desc ";
$query=mysql_query($sql);
while($rs=mysql_fetch_array($query)){ ?>

              <tr><td><?=$rs['news_detail']?></td></tr>
<?php }?>
</table>


อย่าลืมเปลี่ยนตรง order by your_table_id desc ให้เป็นชื่อฟิลด์ ID ของtableคุณนะครับ
ทำได้ไม่ได้ยังไงก็บอกด้วยนะครับพอดีเขียนสดยังไม่ได้ลองเทสดู

verysims

#3
 order by your_table_id desc ตรง desc หมายถึงการเรียงลำดับ ID จากมากมาน้อยครับ
ปกติ idจะรัน
ID|data
1 | ข่าวแรก
2 | ข่าวที่สอง
3 | ข่าวล่าสุด

แต่ถ้าใช้ desc ก็จะได้ข้อมูลเป็น
ID|data
3| ข่าวล่าสุด
2| ข่าวที่สอง
1| ข่าวแรก

เมื่อมีข่าวใหม่ ข่าวล่าสุดก็จะขึ้นไปบนสุด ข่าวเก่าก็จะถูกดันลง ครับ :-[

XXL

เพิ่มขึ้นบรรทัดใหม่ <br />
   <?
   $sql="SELECT news_detail FROM news WHERE isused='T' ";
   $query=mysql_query($sql);
   while($rs=mysql_fetch_array($query)){
   ?>
       <?=$rs['news_detail']?> <br />
   <? }?>

อ้างถึงจาก: icenobu ใน 23 สิงหาคม 2012, 09:36:35
พอดีทำหน้าโชว์ข่าวสารอ่ะค่ะ พอกดแอดข่าวไปเรื่อยๆ มันไม่ยอมขึ้นบรรทัดใหม่อ่ะค่ะ มันต่อออกไปขวามือเราเรื่อยๆเลย
จะทำยังไงให้ข่าวล่าสุดขึ้นไปบนสุด ข่าวเก่าถูกดันลง


<table width="99%" border=0 align="center" cellpadding=2 cellspacing=0>
  <tr>
    <td width="100%" height="76" align=center class="type_C"><p>แจ้งข่าวสาร</p>
      <p>
        <?
      $sql="SELECT news_detail FROM news WHERE isused='T' ";
$query=mysql_query($sql);
while($rs=mysql_fetch_array($query)){
  ?>
        <?=$rs['news_detail']?>
        <? }?>
      </p>
</p>
    <p>&nbsp;</p></td>
  </tr>
</table>

รถไฟวิ่ง ฉึกฉัก..[direct=1].[/direct][direct=2].[/direct][direct=3].[/direct][direct=4].[/direct][direct=5].[/direct]...ถึงก็ช่าง..ไม่ถึงก็ช่าง..

MeenyFancy

อ้างถึงจาก: XXL ใน 23 สิงหาคม 2012, 09:55:26
เพิ่มขึ้นบรรทัดใหม่ <br />
   <?
   $sql="SELECT news_detail FROM news WHERE isused='T' ";
   $query=mysql_query($sql);
   while($rs=mysql_fetch_array($query)){
   ?>
       <?=$rs['news_detail']?> <br />
   <? }?>

อ้างถึงจาก: icenobu ใน 23 สิงหาคม 2012, 09:36:35
พอดีทำหน้าโชว์ข่าวสารอ่ะค่ะ พอกดแอดข่าวไปเรื่อยๆ มันไม่ยอมขึ้นบรรทัดใหม่อ่ะค่ะ มันต่อออกไปขวามือเราเรื่อยๆเลย
จะทำยังไงให้ข่าวล่าสุดขึ้นไปบนสุด ข่าวเก่าถูกดันลง


<table width="99%" border=0 align="center" cellpadding=2 cellspacing=0>
  <tr>
    <td width="100%" height="76" align=center class="type_C"><p>แจ้งข่าวสาร</p>
      <p>
        <?
      $sql="SELECT news_detail FROM news WHERE isused='T' ";
$query=mysql_query($sql);
while($rs=mysql_fetch_array($query)){
  ?>
        <?=$rs['news_detail']?>
        <? }?>
      </p>
</p>
    <p>&nbsp;</p></td>
  </tr>
</table>


ง่ายสุดตามนี้่ครับ :)
Have a good trip.
[direct=http://petdeecare.com]สุนัขป่วย[/direct] [direct=http://petdeecare.com]แมวป่วย[/direct]
[direct=http://petdeecare.com]หนูป่วย[/direct] [direct=http://petdeecare.com]อาหารแมว[/direct] [direct=http://petdeecare.com]อาหารหมา[/direct]

smapan

ส่ง loop ผิดครับเนื้อหาเลยไปกองที่เดียวกัน
[direct=http://cp.siamhostweb.com/cart.php?gid=1]จูมล่าโฮส สยามโฮสเว็บ[/direct] [direct=http://www.modty.com]modty.com[/direct]
[direct=http://www.apartment.in.th]รวมที่พัก เช่ารายวัน ที่พักเช่ารายเดือนมากที่สุดแจ่มจริง[/direct]
***Tel 083-757-1515 ติดปัญหา Joomla ตรงไหนรับปรึกษาฟรี โทรมาเถอะครับ ถ้าตอบได้ช่วยแน่นอน ไม่มีกั้ก. ***

p44n

มีคนบอกวิธีทำง่ายๆไปแล้ว ผมขอบอกแนวคิดแล้วกันคับ เผื่อจะต่อยอดไปอย่างอื่น

ถ้าคุณมี table ลักษณะนี้ สามารถ print ขึ้นบรรทัดใหม่ได้ ด้วยวิธีต่อไปนี้

1. while <tr><td>เนื้อหา</td></tr>
เพราะ tag <tr> มันก็คือ การสร้างบรรทัดใหม่
จะได้โค้ดออกมาดังนี้
<table>
<tr><td>แจ้งข่าวสาว</td></tr>
<tr><td>เนื้อหา</td></tr><!---while--->
<tr><td>เนื้อหา</td></tr><!---while--->
<tr><td>เนื้อหา</td></tr><!---while--->
</table>

2. while <br> ซึ่งก็คือเพิ่ม <br> ไว้ท้ายสุดของเนื้อหา แบบที่เพื่อนๆ ตอบไว้

3. while <p></p> ซึ่ง tag <p> จะขึ้นบรรทัดใหม่ด้วยตัวมันเองอยู่แล้ว คล้าย tag <tr> ในข้อ 1

4. while ทั้ง <table></table> อันนี้ผม คือก็ while ครอบทั้งตาราง แล้ว ตารางมันจะขึ้นบรรทัดใหม่เอง

ลองเลือกใช้ให้เข้ากับโคร้งสร้างโค้ดครับ

ปล. แต่ก่อนผมจะเจอปัญหาเรื่องการจัดเรียง แบบนี้

1 2 3
4 5 6
7 8 9

ทำยังไงให้มัน ขึ้นบรรทัดใหม่ในตำแหน่ง 3 6 9
ต้องเขียนโค้ด php เพิ่มเอง แต่พอมี css แมร่งสบายขึ้นเยอะคับ
Python, PHP OOP, MVC CodeIgniter, MongoDB, MySQL, MsSQL ,CSS Tableless, Responsive Design, Cross-platform, Javascript, jQuery, AngularJS, NodeJS,  Fackbook API, Paypal API, Omise API, Google Map API, C# Window Applications, .NET Framework, JAVA (Android Developer, JSP), Hybrid Application with Cordova + Ionic Framework, ReactJS, React Native

icenobu

มือใหม่หัดเขียนเว็บ O(x^^)o
[direct=http://petdeecare.com]สุนัขป่วย[/direct]
[direct=http://petdeecare.com]แมวป่วย[/direct]
[direct=http://petdeecare.com]กระต่ายป่วย[/direct]
[direct=http://www.petdeecare.com/index.php?topic=199.0]แจกสุนัข[/direct]
[direct=http://www.viptashop.com]จำหน่ายชุดเดรส[/direct]