twilitegxa Posted February 18, 2011 Share Posted February 18, 2011 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?? :-( Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted February 18, 2011 Share Posted February 18, 2011 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 Quote Link to comment Share on other sites More sharing options...
lalnfl Posted February 18, 2011 Share Posted February 18, 2011 I wouldn't store images in a table. I would just upload them in a folder and then grab them from there. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted February 19, 2011 Author Share Posted February 19, 2011 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. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted February 19, 2011 Author Share Posted February 19, 2011 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? Quote Link to comment Share on other sites More sharing options...
litebearer Posted February 19, 2011 Share Posted February 19, 2011 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 ?> Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted February 19, 2011 Author Share Posted February 19, 2011 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.