简体   繁体   English

PHP SQL每个代码显示一行

[英]PHP SQL Show one line per code

I've written the following code, but I really think it's the wrong way of doing it. 我已经编写了以下代码,但我确实认为这是错误的方法。 Especially if I have more then 5 lines. 特别是如果我有5行以上。 What I'm trying to achieve is getting all lines from the table and output them one by one. 我想要实现的是从表中获取所有行,并一一输出。 I tried a while loop but the problem is that every block uses different .css classes. 我尝试了while循环,但问题是每个块都使用不同的.css类。 I think I'm going wrong in the SQL Query, any sugestions would be appreciated. 我想我在SQL查询中出错了,任何建议都将不胜感激。

The code is : 代码是:

$image_one_sql = mysql_query("SELECT * FROM {$home_table} WHERE home_id=1"); 
$image_one_row = mysql_fetch_array($image_one_sql);
$image_one = 'data:image/jpeg;base64,' . base64_encode( $image_one_row['data'] ) . '"';

$image_two_sql = mysql_query("SELECT * FROM {$home_table} WHERE home_id=2"); 
$image_two_row = mysql_fetch_array($image_two_sql);
$image_two = 'data:image/jpeg;base64,' . base64_encode( $image_two_row['data'] ) . '"';
    $image_one_sql = mysql_query("SELECT * FROM {$home_table}");
     WHILE ($rows = mysql_fetch_array($image_one_sql)){
    $image[]='data:image/jpeg;base64,' . base64_encode($rows['data'] )
    }
//pr($image);

then using foreach:

foreach($image as $rows_image){
  //Some code
   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM