Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your <code>foreach()</code> loop is unnecessary if <code>$sql2['id']</code> contains only 1 object.</p> <p>Also why do you make a <code>$value = $sql2['id'];</code>? The <code>$value</code> variable is used by the <code>foreach()</code> loop, that is automatically assign the current object of the collection (which is in our case a collection of one object) to it. What increase the incomprehensibility is why did you created the <code>foreach()</code> loop and done the assign I described previously if you doesn't even use the <code>$value</code> variable?</p> <p>Also in this case <code>$sql2</code> is very misleading naming because that object doesn't represent an SQL related thing.</p> <p>If you look at the <a href="http://php.net/manual/en/function.mysql-fetch-array.php" rel="nofollow noreferrer">mysql-fetch-array()</a> documentation, you see some examples, how you should use it. Also notice the naming of the variables! Your code should look like something like this:</p> <pre><code>$result = mysql_query(' SELECT c.id, c.name, c.description, c.price, c.quantity, c.itemid, c.imgname, c.position, (SELECT Count(t.id) FROM topics AS t WHERE t.parent = c.id AND t.id2 = 1) AS topics, (SELECT Count(t2.id) FROM topics AS t2 WHERE t2.parent = c.id AND t2.id2 != 1) AS replies FROM categories AS c GROUP BY c.id ORDER BY c.position ASC '); while ($row = mysql_fetch_array($result)) {?&gt; &lt;div class="itemInset"&gt; &lt;p&gt;&lt;?php echo $row['name']; ?&gt;&lt;/p&gt; &lt;img src="admin/image/&lt;?php echo $row['imgName']; ?&gt;" alt="&lt;?php echo $row['imgName']; ?&gt;"&gt; &lt;/div&gt; &lt;?php } ?&gt; </code></pre> <p>Please note that <code>mysql_*</code> functions are deprecated and <a href="https://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php">you shouldn't use them</a>.</p> <p><strong>Edit:</strong> As I see, you do/think about things really bad. You should use the first technique I gave you and create the <code>&lt;div&gt;</code>s that way. If that doesn't works for you, than you wrote a bad SQL query or your database design is wrong. According to your SQL <code>SELECT</code> there should be only a number in <code>sql2['id']</code> if not, than your database design/naming is totally wrong, not to mention that if it isn't a number than it is some kind of string and you can't <code>foreach()</code> a naked string and wait for some kind of miracle to happen that will generate the whole layout you want. At this point I have to say, that if the first solution I gave you didn't work, than you have to rethink your database and the way how do you insert/select things from those tables, because as I see you have misconceptions about how your could should work.</p> <p>Each row that you get from <code>while ($row = mysql_fetch_array($result))</code> should represent one category, and the columns of your categories table should represent properties of a category, as well as every object you got from your <code>$row</code> array. So when you get a value from the <code>$row</code> array than you should index it with the name of the property (the column's name if you didn't renamed it in the SQL query) and you should get a single value. For example <code>$row['name']</code> should contain the name of that specific category, <code>$row['id']</code> should be the id of that specific category. You can't do anything with a <code>foreach()</code> loop in these, unless they contain something like <code>"auto,mobile,car"</code> that you have to <code>explode()</code> first to loop it. And to repeat myself the id should be a specific, unique number of that specific category, like <code>1</code>, <code>2</code>, <code>56</code> or <code>468</code> it can't contain other/more things because in that case your naming and your conception about the id is wrong.</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.
 

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