使用PHP获取单击图像的ID并从MYSQL数据库加载它的信息

时间:2014-11-08 11:00:14

标签: php mysql database

我需要帮助加载已点击图片的特定信息。信息存储在MYSQL数据库中。

  1. 我需要确定点击了哪个图像,然后获取图像 ID
  2. 然后从数据库中获取有关该图像的信息
  3. 回显有关图像的信息
  4. 链接到数据库结构的图像:https://www.dropbox.com/sh/8xrifn64psmc9qh/AAA5j_eous8sBpg4WP0dgrmya?dl=0

    谢谢!这是我用来从数据库加载图像的代码行。

    $sql="SELECT * FROM klubbar ORDER BY namn ASC";
    $res = mysql_query($sql);
    
    if (!$res) {
       echo "Could not successfully run query ($sql) from DB: " . mysql_error();
       exit;
    }
    
    while ($row = mysql_fetch_assoc($res)) {
       echo '<div class="klubbar"><a href=""><img     src="'.$row['bild'].'"alt="'.$row['namn'].'"title="'.$row['namn'].'"/></a></div>';
    }
    

1 个答案:

答案 0 :(得分:0)

PHP:

$sel_club = $_GET['klub'];
      $sql="SELECT * FROM klubbar ORDER BY namn ASC";
      $res = mysql_query($sql);
      if (!$res) {
        echo "Could not successfully run query ($sql) from DB: " . mysql_error();
        exit;
      }

      if($sel_club)
      {
        $sqlC= "SELECT * FROM klubbar WHERE namn ='$sel_club'";
        $resC= mysql_query($sqlC);

        if($rowC = mysql_fetch_assoc($resC))
        {
          $id = $rowC['id'];
          $namn = $rowC['namn'];
          $bild = $rowC['bild'];
          $lank = $rowC['lank'];
          $alder = $rowC['alder'];
          $dresscode = $rowC['dresscode'];

          echo 'Klub: '.$namn.'<br>Webbsida: '.$lank.'<br>Åldersgräns: '.$alder.'+ <br> Dresskod: '.$dresscode;
          echo 
          '<form method="post" action="anmalan.php">
            <label name="namn">Namn:</label>
            <input type="text" name="namn" placeholder="Förnamn Efternamn"/><br>
            <label name="antalGuess">Antal gäster</label>
            <select>
              <option>+0</option>
              <option>+1</option>
              <option>+3</option>
              <option>+4</option>
              <option>+5</option>
              <option>+6</option>
            </select><br>
            <label name="mejl">E-post:</label>
            <input type="text" name="mejl" placeholder="example@ex.com"/><br>
            <label name="telefon">Mobilnr:</label>
            <input type="text" name="telefon" placeholder="07x xxx xx xx"/><br>
            <input type="submit" name="submit" value="Skicka" />
          </form>'; 
        }
        else
        {
          echo "Could not successfully run query ($sql) from DB: " . mysql_error();
        }

      }
      else
      {
        while ($row = mysql_fetch_assoc($res))
        {
          $id = $row['id'];
          $namn = $row['namn'];
          $bild = $row['bild'];
          $lank = $row['lank'];
          $alder = $row['alder'];
          $dresscode = $row['dresscode'];
          echo '<div class="klubbar" ><a href="?klub='.$namn.'" id="'.$id.'"><img src="'.$bild.'"alt="'.$namn.'"title="'.$namn.'"/></a></div>';
        }
      }