Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to retrieve and output images from multiple columns with php and mysql?
    text
    copied!<p>UPDATE:</p> <p>I have have ten columns in my SQL table: id, imgid, urlid, image1, image2, image3, image4, image5, and comment. Id, imgid, and urlid are int type. Image[1-5] are mediumblob type. Url and comment are text type. Imgid is the number of images uploaded (which should be 5), urlid is the number of urls submitted (which should be one right now), url holds the url, and comment holds user comments. I'd like to retrieve and output all the image data from the image columns in a row but I'm getting torn page icons. I am using a front.php to output images and a get.php to convert images to viewable format.</p> <p>Here's my front.php:</p> <pre><code>&lt;?php mysql_connect ("","","") or die(mysql_error()); mysql_select_db ("") or die(mysql_error()); $defaultqry = mysql_query ("SELECT * FROM dbp"); while($row = mysql_fetch_assoc($defaultqry)) { echo ($row['image1'] != NULL) ? '&lt;img src="get.php?id='.$row[id].'&amp;col=1 " width="30" height="30"/&gt; ' : ''; echo ($row['image2'] != NULL) ? '&lt;img src="get.php?id='.$row[id].'&amp;col=2 " width="30" height="30"/&gt; ' : ''; echo ($row['image3'] != NULL) ? '&lt;img src="get.php?id='.$row[id].'&amp;col=3 " width="30" height="30"/&gt; ' : ''; echo ($row['image4'] != NULL) ? '&lt;img src="get.php?id='.$row[id].'&amp;col=4 " width="30" height="30"/&gt; ' : ''; echo ($row['image5'] != NULL) ? '&lt;img src="get.php?id='.$row[id].'&amp;col=5 " width="30" height="30"/&gt; ' : ''; } ?&gt; </code></pre> <p>Here's my get.php:</p> <pre><code>&lt;?php mysql_connect ("","","") or die(mysql_error()); mysql_select_db ("") or die(mysql_error()); $query = mysql_query("SELECT * FROM dbp WHERE id = ".mysql_real_escape_string($_GET['id'])); $row = mysql_fetch_array($query); $col = intval($_GET['col']); if(isset($row['image'.$col]) &amp;&amp; $row['iamge'.$col] != NULL){ $content = $row['image'.$col]; }else{ exit; // col is not existent, or image is empty } header('Content-type: image/jpg'); echo $content; exit; ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload