bickyz Posted December 1, 2009 Share Posted December 1, 2009 hi, im trying to do one college project where i have to display images horizontally. The image links are saved in the mysql db with the surname. This is the script: <?php require_once('Connections/conn1.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?php $letter = isset($_GET['letter']) ? $_GET['letter'] : "0"; //alphabetical pagination links echo '<div align="center"><b>'; foreach(range('A','Z') as $c){ ($letter == $c) ? printf('%s ',$c) : printf('<a href="?letter=%s">%s</a> ',$c,$c); } echo "</b></div><p>"; mysql_select_db($database_conn1, $conn1); $query_rs1 = "SELECT * FROM tblvdo WHERE UCASE(surname) LIKE '{$letter}%' order by surname"; $rs1 = mysql_query($query_rs1, $conn1) or die(mysql_error()); ?> <table > <tr> <?php $rs1_endRow = 0; $rs1_columns = 4; // number of columns $rs1_hloopRow1 = 0; // first row flag do { if($rs1_endRow == 0 && $rs1_hloopRow1++ != 0) echo "<tr>"; ?> <td><img src="<?php echo $row_rs1['imgurl']; ?>" width="100px"><td> <?php $rs1_endRow++; if($rs1_endRow >= $rs1_columns) { ?> </tr> <?php $rs1_endRow = 0; } } while ($row_rs1 = mysql_fetch_assoc($rs1)); if($rs1_endRow != 0) { while ($rs1_endRow < $rs1_columns) { echo("<td> </td>"); $rs1_endRow++; } echo("</tr>"); }?> </table> </body> </html> <?php mysql_free_result($rs1); ?> In this project the alphabetical pagination will be pulling all the images horizontally with the particular letter from the surname field. you can check live demo here: http://centos.uk.to/vdo3.php The problem is if you click on letter B or S, there is a blank section of the same size as image before first image. I checked the source of html and found this line there and i dont no how its appearing <td><img src="" width="100px"><td> I will be grateful if someone can please help me finding the problem so that i dont get blank section before images. Link to comment https://forums.phpfreaks.com/topic/183622-horizontal-display-of-image-from-mysql/ Share on other sites More sharing options...
cags Posted December 2, 2009 Share Posted December 2, 2009 The blank image tag is on every page, it's only visible on B and Sbecause you go to the second row thus forcing the width of the firstcolumn in the table. As far as I can tell it's the nature of the loopyour using that is causing the problem. do { if($rs1_endRow == 0 && $rs1_hloopRow1++ != 0) echo "<tr>"; ?> <td><img src="<?php echo $row_rs1['imgurl']; ?>" width="100px"><td> <?php $rs1_endRow++; if($rs1_endRow >= $rs1_columns) { ?> </tr> <?php $rs1_endRow = 0; } } while ($row_rs1 = mysql_fetch_assoc($rs1)); With a do-while loop the contents will always be done once because the while is evaluated at the end. Thus in your case the first time the code is ran $row_rs1 is a null/empty array, thus it's outputting the HTML with no values. Simply switching to a convensional while loop should fix the problem. while ($row_rs1 = mysql_fetch_assoc($rs1)) { if($rs1_endRow == 0 && $rs1_hloopRow1++ != 0) echo "<tr>"; ?> <td><img src="<?php echo $row_rs1['imgurl']; ?>" width="100px"><td> <?php $rs1_endRow++; if($rs1_endRow >= $rs1_columns) { ?> </tr> <?php $rs1_endRow = 0; } } Link to comment https://forums.phpfreaks.com/topic/183622-horizontal-display-of-image-from-mysql/#findComment-969682 Share on other sites More sharing options...
bickyz Posted December 3, 2009 Author Share Posted December 3, 2009 thank u cags, its been solved. final view: http://centos.uk.to/vdo3c.php Link to comment https://forums.phpfreaks.com/topic/183622-horizontal-display-of-image-from-mysql/#findComment-970376 Share on other sites More sharing options...
cags Posted December 3, 2009 Share Posted December 3, 2009 Glad you fixed it, don't forget to click the 'Mark Solved' button (bottom left corner of threads you start). Link to comment https://forums.phpfreaks.com/topic/183622-horizontal-display-of-image-from-mysql/#findComment-970379 Share on other sites More sharing options...
bickyz Posted December 10, 2009 Author Share Posted December 10, 2009 another complication came up. while ($row_rs1 = mysql_fetch_assoc($rs1)) { if($rs1_endRow == 0 && $rs1_hloopRow1++ != 0) echo "<tr>"; ?> <td><img src="<?php echo $row_rs1['imgurl']; ?>" width="100px"></td> <?php $rs1_endRow++; if($rs1_endRow >= $rs1_columns) { ?> </tr> <?php $rs1_endRow = 0; } } with the above code i can successfully display image frm left to right,thanks IMAGE1 IMAGE2 IMAGE3 IMAGE4 IMAGE5 IMAGE6 IMAGE7 IMAGE8 how do i display another field below these pictures like IMAGE1 IMAGE2 IMAGE3 IMAGE4 SURNAME SURNAME SURNAME SURNAME IMAGE5 IMAGE6 IMAGE7 IMAGE8 SURNAME SURNAME SURNAME SURNAME surname is another field for each image in the database record. i modified the part of the code to: <td><td><img src="<?php echo $row_rs1['imgurl']; ?>" width="100px"> <br> <?php echo $row_rs1['surname']; ?> </td> now all the images with surnames are displayed vertically like this IMAGE1 SURNAME1 IMAGE2 SURNAME2 IMAGE3 SURNAME3 IMAGE4 SURNAME4 why is this happening. Link to comment https://forums.phpfreaks.com/topic/183622-horizontal-display-of-image-from-mysql/#findComment-974801 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.