PHP queries the database and displays the results in columns

Source: Internet
Author: User

PHP query MySQL database, and the results columns display, the following code:

 
  1. <?php
  2. Session_Start ();
  3. Include ("conn.php");?>
  4. <title> Query Results columns Display-www.cxybl.com</title>
  5. <body>
  6. <table width= "450" border= "1" align= "center" cellpadding= "0" cellspacing= "0" >
  7. <?php for ($i =1 $i <=4; $i + +) {//if variable <=4, loop by row, output line
  8. echo "<tr>"; ?>
  9. <?php if ($i ==1) {
  10. $query = "SELECT * from Tb_picture where ID order by id DESC"; Get emoticons from datasheet MR_LTTB
  11. $LTTB =mysql_query ($query); }
  12. $j = 1; Set Variable $j=1
  13. while ($LTTB _row=mysql_fetch_array ($LTTB)) {//For While loop output
  14. if ($j <=6) {//<=8 the number of emoticons per row, output the following
  15. if ($c ==0) {$c = "checked";}
  16. ?>
  17. <TD height= "align=" center "valign=" Middle ">
  18. <input name= "XQ" type= "Radio" value= "<?php echo $LTTB _row[id];? > "<?php echo $c;? >>
  19. "width=" height= "></td>"
  20. <?php}
  21. $c = 1;
  22. + + $j; As the number of emoticons increases,
  23. if ($j ==7) {break; //When the number of emoticons equals 9 o'clock, jump to the next line to cycle again
  24. }
  25. echo "</tr>";
  26. }
  27. ?>
  28. </table>
  29. </body>

conn.php:

 
  
  1. <?php
  2. $id =mysql_connect ("localhost", "root", "MySQL") or Die (' Connection failed: '. mysql_error ());
  3. if (mysql_select_db ("phpjcdb", $id))//Description: PHPJCDB is the database name
  4. echo "";
  5. Else
  6. Echo (' Database selection failed: '. mysql_error ());
  7. mysql_query ("Set names gb2312"); Set to Simplified Chinese
  8. ?>






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.