RRPANDEY
RRPANDEY

Reputation: 235

To display photos of same alias name using php and mysql

I want to display many photos which belong to same alias, for example if i have many phographs of Apple and and want to show them all at once having one photo as main and others as a thumbnails of all apples.

$url=$_GET['photoUrl'];
$sql = "SELECT * FROM photos WHERE photoUrl='$url'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
    $photoId=$row['photoId'];$photoName=$row['photoName'];$photoDesc=$row['photoDesc'];$photoUrl=$row['photoUrl'];$photoCategory=$row['photoCategory'];}

Above code is the main file called photo.php (which works perfectly for fetching all photos) and below code is morephoto.php which i include in photo.php.

why i am writing this below code because if i have signle apple photo as main photo and just beneath or above a photo bar like carausal will appear having many apple photos

so thing is may be i am just failing to co-relate photo.php with morephoto.php

<?php
include('admin/config.php');
$aliasPhoto=$_GET['alias'];
$sql = "SELECT * FROM photos WHERE alias='$aliasPhoto' LIMIT 0, 8";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
    $photoId=$row['photoId'];
    $photoName=$row['photoName'];
    $photoDesc=$row['photoDesc'];
    $photoUrl=$row['photoUrl'];
    $photoCategory=$row['photoCategory'];       
?>
                <div class="col-md-3">      
                    <a href="<?php echo"$photoUrl.html";?>">
                        <img class="img-responsive thumbnail" src="images/<?php echo"$photoUrl.jpg";?>" <?php echo "alt=\"$photoName\" title=\"$photoName\"";?>>
                    </a>                
                </div>

Upvotes: 0

Views: 98

Answers (2)

M.K
M.K

Reputation: 398

Please try following code:

<?php
 include('admin/config.php');
 $aliasPhoto = $_GET['alias'];
 $sql = sprintf("SELECT * FROM photos WHERE alias='%s' LIMIT 0, 8",mysql_real_escape_string($aliasPhoto));
 // Perform Query
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
    $photoId = $row['photoId'];
    $photoName = $row['photoName'];
    $photoDesc = $row['photoDesc'];
    $photoUrl = $row['photoUrl'];
    $photoCategory = $row['photoCategory'];
    echo "<div class='col-md-3'>
            <a href='$photoUrl.html'>
              <img class='img-responsive thumbnail' src='images/$photoUrl.jpg' alt='$photoName' title='$photoName'/>
            </a>
        </div>";
}


?>

the key point is you need make sure your sql execute correct , please use print the sql statement and copy it execute in mysql , see what happened.

Upvotes: 1

varunsinghal
varunsinghal

Reputation: 329

You are missing the $photoName in your HTML image source. that is,

<img class="img-responsive thumbnail" src="images/<?php echo $photoUrl.$photoName.".jpg";?>" <?php echo "alt=\"$photoName\" title=\"$photoName\"";?>>

Upvotes: 0

Related Questions