Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Instead of your <code>for</code> loop, try using:</p> <pre><code>while($row = mysql_fetch_assoc($result)) { echo "&lt;div id='contentItem'&gt;"; echo "&lt;a href='".$row['fullURL']."' title='".$row['description']."'&gt;&lt;img src='". $row['thumbURL']."' width='200px' height='150px' /&gt;&lt;/a&gt;"; echo "&lt;/div&gt;"; } </code></pre> <p>In this case, <code>mysql_fetch_assoc</code> is doing basically the same thing as <code>mysql_fetch_array($result, MYSQL_BOTH)</code> without the numeric keys. It's up to you which you use there really.</p> <p>For future database interactions, though, I'd recommend reading into either <a href="http://php.net/manual/en/book.mysqli.php" rel="nofollow">MySQLi</a> or <a href="http://php.net/manual/en/book.pdo.php" rel="nofollow">PDO</a> as the <code>mysql</code> prefix and functions using it are now deprecated.</p> <p>Edit:</p> <p>As requested by a few users, an example using the updated MySQLi functions instead:</p> <pre><code>&lt;?php $db = new mysqli('localhost', 'user', 'pass', 'db'); if($db-&gt;connect_error) { die("Connection error: ".$db-&gt;connect_error); } $filesSQL = $db-&gt;query("SELECT * FROM files"); $numItems = $db-&gt;num_rows; //this can also be done procedurally as mysqli_num_rows($filesSQL) $sql = $db-&gt;query("SELECT * FROM files WHERE fileID = 1"); if(!$sql) { echo $db-&gt;error; } //personally, if I wanted an SQL error after a query I would use: $sql = $db-&gt;query('query') or die($db-&gt;error); //then to follow, your while loop becomes while($row = mysqli_fetch_assoc($sql)) { //can also be done with object as $row = $sql-&gt;fetch_assoc //do your loop } </code></pre> <p>Sadly, I'm not aware of PHP templates as suggested by Your Common Sense in the comments, so examples for that are welcome!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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