Jump to content

Help with Image Display Embedded PHP Script


kb9cry

Recommended Posts

I'm a real newbie to PHP scripting and would like your experienced help.

I'm creating a website for Dog Rescue for my dog club.

On the Available Dogs webpage, the user will click on certain geographic regions  (consisting of select states) and info from a MySQL database on available dogs will display.  If no dogs are available, the No Available Dogs will be displayed.

 

If got a couple of questions and need help in displaying any pictures that might be uploaded for a certain dog.

 

The database info on each dog will be entered by me and each will be given a unique Serial Number (SN).  Any pictures will be stored in a directory on the server and each image will be pre-sized by me and each given a unique name consisting of the SN_1.jpg, SN_2.jpg, etc.

 

1)  First Question is:  In script below, will the results be displayed as Columns of info or in Rows?

I want Rows actually.

 

2)  The second question is:  How do I display any or all pictures that may be uploaded right after the dog's information?  Keep in mind that there may be multiple listings and therefore I want all the information and pictures of each dog to be displayed, then the next, etc.

 

I've been searching around and believe what I need to do is use a second PHP script to find and display the images selected in the main script.  I think the last line of the script would be something like:

 

print "<img src=getImg.php?name=" . $name . ">";

 

A getImg.php script that I've found it this:

 

<?php

  header("Content-type: image/jpg");

  $name = $_REQUEST["name"];

  $connection = mysql_connect(hostname,username,password);

  mysql_select_db(databaseName);

  $sql = "SELECT image FROM images WHERE name = '".$name."'";

  $result = mysql_query($sql);

  $nrows = mysql_num_rows($result);

  if($nrows == 1) {

    $row = mysql_fetch_array($result);

    echo $row["image"];

  }

?>

 

 

What I don't know how to do is to alter this basic script, or use something different, that will query the MySQL database for the particular dog's picture location using the dog's unique SN along with the _1, _2, name qualifier and display the results.  I also do not want any pictures displayed if there are none to be found (or display No Pictures Available).  Another concern is that once the first dog's info and pictures are displayed, how will this getImg script know to use the next dog's SN in finding their pictures?

 

Tnx in advance for any help.  Again, I'm a real newbie but I learn quick.  If this is too much to ask, then please steer me in any direction.

 

Phil

 

 

 

<?php

// Connects to the Database

mysql_connect("database server", "username", "password") or die( “Did not connect to database server.”);

 

mysql_select_db("database name") or die( “Did not connect to database.”);

 

$data = mysql_query("SELECT * FROM available WHERE ((Status=’A’) AND (State=’IL’ OR State=’IN’ OR State=’KY’ OR State=’OH’ OR State=’PA’ or State=’VA’ or State=’WV’))”)

or die( “No Dogs Available”);

 

Print "<table border cellpadding=3>";

while($info = mysql_fetch_array( $data ))

{

Print "<tr>";

Print "<th>SN:</th> <td>".$info['SN'] . "</td> ";

Print "<th>State:</th> <td>".$info['State'] . "</td> ";

Print "<th>Date Added:</th> <td>".$info['Date Added'] . "</td> ";

Print "<th>Sex:</th> <td>".$info['Sex'] . "</td> ";

Print "<th>Age:</th> <td>".$info['Age'] . "</td> ";

Print "<th>Medical:</th> <td>".$info['Medical'] . "</td> ";

Print "<th>Description1:</th> <td>".$info['Description1'] . "</td> ";

Print "<th>Description2:</th> <td>".$info['Description2'] . "</td> ";

Print "<th>Description3:</th> <td>".$info['Description3'] . "</td> ";

Print "<th>Description4:</th> <td>".$info['Description4'] . "</td> ";

Print "<th>Contact Name:</th> <td>".$info['Contact Name'] . "</td> ";

Print "<th>Contact Info:</th> <td>".$info['Contact Info'] . "</td> ";

Print "<th>Contact Email:</th> <td>".$info['Contact Email'] . "</td> ";

Print "<th>Contact Phone:</th> <td>".$info['Contact Phone'] . "</td></tr> ";

}

Print "</table>";

?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.