integrating PHP with HTML page to execute SQL Query

A

Anonymous

Guest
Ive had a quick look. I havent looked at every little part so heres what is wrong with what I have looked at. There may be more wrong with it:

This while loop below...I guess that if there are 50 images you want to view them all?
The while loop below just reads through all of the images and overwrites the variables each time .

You need to extend the while loop to include the image divs.

You also need to specify the file name to the src tag of img : <img src="data/images" <img src="$filename"

You also have floating text. you should be using <p> <span> tags etc...

Your code:
Code:
                       <?php
      $link = mysql_connect("server", "user","pwd");
mysql_select_db("db");
$sql=("SELECT * FROM images WHERE user_id='".$user_id."'");
$result=mysql_query($sql);
while($r=mysql_fetch_array($result))
{   
  
   $user_id=$r["user_id"];
   $date_image_taken=$r["date_image_taken"];
   $image_taken_by=$r["image_taken_by"];
   $file_name=$r["file_name"];
   $notes=$r["notes"];

 
}
?>
                         
                        
                        <div class="category" data-title="Images" data-thumb="data/images">
                    
                            <ul>
                        
                                <li>
                                     <img src="data/images" alt="data/images/images" width="80" height="53" title="<?php echo $file_name; ?>" data-description= USER ID:   "<?php echo $user_id; ?>"<br/><br/>   
Date Image Taken:   "<?php echo $date_image_taken; ?>"<br/><br/>
Image Taken By:      "<?php echo $image_taken_by; ?>"<br/><br/>
Notes:            "<?php echo $notes; ?>""/>
                                </li>
                                                                                       
                         </ul> 
                    
                    </div>


After my changes:

(there is still a lot of room for improving this code but here is an example of it working)

Code:
<?php
$link = mysql_connect("server", "user","pwd");
mysql_select_db("db");
$sql=("SELECT * FROM images WHERE user_id='".$user_id."'");
$result=mysql_query($sql);

$image_output ="<ul>"; //open the unordered list outside of the loop 

while($r=mysql_fetch_array($result))
{   
  
   $user_id=$r["user_id"];
   $date_image_taken=$r["date_image_taken"];
   $image_taken_by=$r["image_taken_by"];
   $file_name=$r["file_name"];
   $notes=$r["notes"];

     // build the image list here 
    $image_output  .= sprintf("
                                <li>
                        <img src='%s' alt=\"\" width=\"80\" height=\"53\" title='%s' data-description= USER ID:   %s<br/><br/>   
						Date Image Taken:   %s<br/><br/>
						Image Taken By:      %s<br/><br/>
						Notes:            %s />
                                </li>",$filename,$filename,$user_id,$date_image_taken,$image_taken_by,$notes);
}
$image_output .= "</ul>";

?>


Code:
                        <div class="category" data-title="Images" data-thumb="data/images">
                    
                            <?php echo $image_output; ?>
                    </div>
 
Back
Top