Jump to content

Displaying image from table?


twilitegxa

Recommended Posts

I just can't get anything right today! Now I am trying to have a list of images, and when the user clicks on the image, the next page will display the image along with other fields for that record. I am sending the id through the hyperlink to the next page, and I have echoed it to ensure it's comign through, but I cannot get anythign to display ont he next page. What am I doin wrong? Here is the link to the page. If you click on one of the images, you 'll see that the next page is empty:

 

 

http://webdesignsbyliz.com/wdbl_wordpress/test-submit/

 

 

Here is my code:

 

 


this is the gallery


<?php
$dbhost = 'localhost';
$dbuser = 'user';
$dbpass = 'pass';


$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');


$dbname = 'jewelry';
mysql_select_db($dbname);


$all_records = "SELECT * FROM gallery";
$all_records_res = mysql_query($all_records);
$image = mysql_result($all_records_res, 0, 'image');
$id = mysql_result($all_records_res, 0, 'id');


while($nt=mysql_fetch_array($all_records_res)){
echo "<a href=http://webdesignsbyliz.com/wdbl_wordpress/test-display/?id=" .$nt['id']." ><img src=http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/".$nt['image']." width=133 height=86></a>";
}


?>

 

 

 

 

display page:


<?php


$id = $_GET['id'];


$dbhost = 'localhost';
$dbuser = 'user';
$dbpass = 'pass';


$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');


$dbname = 'jewelry';
mysql_select_db($dbname);


$all_records = "SELECT * FROM gallery WHERE id = $_GET[id]";
$all_records_res = mysql_query($all_records);
$image = mysql_result($all_records_res, 0, 'image');
$id = mysql_result($all_records_res, 0, 'id');


while($nt=mysql_fetch_array($all_records_res)){
echo "<img src=http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/".$nt['image']." width=133 height=86></a>";
}








?>

 

 

What an I doing wrong this time?? :-(

Link to comment
Share on other sites

To start with, the html you are outputting is missing quotes around all the attribute values.

 

A link is -

 

<a href='a_url'>some content/image here</a>

 

An image is -

 

<img src='a_url' alt='some alt text' width='133' height='86'>

 

I recommend validating your resulting pages at validator.w3.org

Link to comment
Share on other sites

They are stored in a folder. The path to them is the only thing that is stored in the table. I am having no trouble pulling all records at once, it's just grabbing a single record based on the thumbnail they select that I'm having trouble with. I must have typed something wrong in my code. I'm just hoping someone can help me figure out where and what it was.

Link to comment
Share on other sites

Okay, there must be something wrong with the way I am writing my WHERE statement because this works:

 

 


<?php


$id = $_GET['id'];


echo $id;


$dbhost = 'localhost';
$dbuser = 'user';
$dbpass = 'pass';


$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');


$dbname = 'jewelry';
mysql_select_db($dbname);


$all_records = "SELECT * FROM gallery";
$all_records_res = mysql_query($all_records);
$image = mysql_result($all_records_res, 0, 'image');
$id = mysql_result($all_records_res, 0, 'id');


while($nt=mysql_fetch_array($all_records_res)){
echo "<img src=http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/".$nt['image']." width=133 height=86></a>";
}








?>

 

 

I'm echoing out the id and it's working right, but when i try to add the WHERE statement:

 

 

WHERE id = '$id'

 

 

It's not displaying anything. What am I doing wrong? I'm using Wordpress...does Wordpress have to have the WHERE statement a certain way or something?

Link to comment
Share on other sites

If you only want the image that corresponds to $id, then you might try...

<?PHP
$id = $_GET['id'];
$dbhost = 'localhost';
$dbuser = 'user';
$dbpass = 'pass';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$dbname = 'jewelry';
mysql_select_db($dbname);
$query = "SELECT image FROM gallery WHERE id = '$id'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$image = $row['image'];
$path = "http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/";
?>
<IMG src="<?PHP echo $path . $image; ?>" width="133" height="86">
<?PHP
?>

Link to comment
Share on other sites

Right before i read this post I redid my coding and got it to work. I had something wrong when I was outputting the data from both pages:

 

 


this is the gallery


<?php


$all_records = "SELECT * FROM gallery";
$all_records_res = mysql_query($all_records);


while($image=mysql_fetch_array($all_records_res)){
echo "<a href='http://www.webdesignsbyliz.com/test-display.php?id=" .$image['id']. "'><img src='http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" .$image['image']. "' width='133' height='86' /></a>";
}


?>

 

 


this is the gallery


<?php


$all_records = "SELECT * FROM gallery WHERE id = '$_GET[id]'";
$all_records_res = mysql_query($all_records);


while($image=mysql_fetch_array($all_records_res)){
echo "<a href='http://www.webdesignsbyliz.com/test-display.php?id=" .$image['id']. "'><img src='http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" .$image['image']. "' width='133' height='86' /></a>";
}


?>

 

 

Thanks for all your hard work and help guys!

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.