【问题标题】:how to return a colomn value from only one row如何仅从一行返回列值
【发布时间】:2016-05-25 15:35:13
【问题描述】:

我使用此代码将表格中的图片放入使用 jquery 作为幻灯片动画的 div 中,但问题是我只需要在图片上而不是同时在所有图片上?我能做些什么 ? 代码:

    <?php
    require_once 'includes/connect.php';

    $stmt = $bdd->prepare('SELECT userPic FROM AddOffer WHERE id_user=:id ORDER BY id_user DESC');
    $stmt->bindParam(':id',$id);
    $stmt->execute();

    if($stmt->rowCount() > 0)
    {
        while($row=$stmt->fetchColumn())
        {
            extract($row);
    ?>

    <img src="user_offers/<?php echo $row['userPic']; ?>" class="img-roundeds" width="200px" height="200px" />     
    <?php
        }
    }
    else
    {
    ?>
    <span> Ajouter une Photo à votre Profil</span>
    <?php
    }

    ?>

【问题讨论】:

  • 研究使用 LIMIT 为 1 的分页。
  • 并学会使用sprintf或更好的模板引擎来清理代码。

标签: php mysqli pdo


【解决方案1】:

将 LIMIT 1 添加到您的 SQL 中

$stmt = $bdd->prepare('SELECT userPic FROM AddOffer WHERE id_user=:id ORDER BY id_user DESC LIMIT 1');

【讨论】:

  • 他们的其他图片呢?他们将如何展示其他人? I believe I answered that,只是没有完整的代码;-)
  • 我有一个 jquery 幻灯片,我想调用表格中的图像
  • 对我来说,问题看起来像是为了限制 SQL 查询中的行。最好只是开始一个关于 jquery 和 javascript 和 ajax 的新问题。
  • jquery 代码是正确的,幻灯片是用固定图像正确构建的。我想将固定图像转换为日期表中的调用图像
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-16
相关资源
最近更新 更多