Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Let's analyse this code:</p> <pre><code>// this query returns one row with column `count`, you're comparing column // `category` to the literal string `count($categories)` where // `$categories` is an array of numbers and therefore evaluates to `count(Array)` $query1 = mysql_query("SELECT count(*) as count FROM tag1 WHERE ($where) AND category ='count($categories)' "); $count = 0; // warning: overwriting previous $row variable while ($row = mysql_fetch_array($query1)) { // an if($row=...) is better since you've on row anyway // Contents of $row = array( 'count' =&gt; NUMBER ); // You're overwriting $count with the number of found articles $count = $row['count']; } // unless the query failed or there are no articles found, the next condition is true if($count) { // undeclared variable $ids; $row['id'] does not exist since it is overwritten $ids[] = $row['id']; // The next lines do not limit the number of updates, it only updates // if $count == 4; where $count is the number of articles in a category $count++; if($count == 5) { mysql_query("UPDATE articles SET cat = '$curCategory' WHERE id in ('".implode("', '", $ids)."')"); // so if the current catgeory has five articles, quit? if(!$curCategory = array_shift($categories)) { break; } // otherwise, reset for the next category $count = 0; $ids = array(); } } </code></pre> <p>You should definitely look at your code and see if you understand everything. I'm sure that overwriting <code>$row</code> is not intended, neither is your query in <code>$query1</code> correct. When naming your variables, make them more descriptive. Use <code>$catCount_row</code> instead of <code>$row</code> for example. Note that you're overwriting <code>$count</code> each time, perhaps you want to take that out of your <code>while</code> loop.</p> <p>If you do not reach an article count of 4, no update will be done.</p>
    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.
    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