Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Unrelated to your error, but I do believe your code is flawed on many levels, and wont be doing what you think it's doing. Let me show you:</p> <pre><code>$videos = mysql_fetch_assoc($videos); foreach($videos as $video){ echo '&lt;div class="video"&gt;'; echo '&lt;a href="video.php?v="'.$video['video_id'].'"&gt; &lt;h3&gt;"'.$video['title'].'"&lt;/h3&gt;&lt;/a&gt;'; echo '&lt;/div&gt;'; } </code></pre> <p>You may think that code is going to run for each video that is returned by the query, but it's not. You're actually foreach'ing over a single video, and that's it. The value of $video inside the foreach loop won't be an array. It will be the individual values within a single video array.</p> <p>But there's more:</p> <pre><code>if($videos){ </code></pre> <p>The value of mysql_query is either false, which means there was an error, or a resource pointing towards <strong>zero</strong> or more rows. It does not tell you if there were rows returned or not.</p> <p>This is how your code <em>should</em> be written:</p> <pre><code>$query = "SELECT video_id,title FROM video_id"; $videos = mysql_query($query); /** * There was an error if $videos is false. Use mysql_error() * to get a message explaining the error. */ if (!$videos) { die(mysql_error()); } /** * You use the function mysql_num_rows() to find out how many * rows were returned by the query. */ if(mysql_num_rows($videos) &gt; 0) { /** * You need to keep calling mysql_fetch_assoc() until there are * no more rows to return. */ while($video = mysql_fetch_assoc($videos)) { echo '&lt;div class="video"&gt;'; echo '&lt;a href="video.php?v="'.$video['video_id'].'"&gt; &lt;h3&gt;"'.$video['title'].'"&lt;/h3&gt;&lt;/a&gt;'; echo '&lt;/div&gt;'; } } else { echo "&lt;p&gt;No new videos actually&lt;/p&gt;"; } mysql_close(); </code></pre>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    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