I am not sure I can give you an answer but with a few tips you can improve what you posted and make it easier to understand what the code is doing for the next person that comes along.
First for readability it is real handy when you post code in these forums to wrap them in the phpbb PHP tags. There is a quick tool in the bar above the textarea that you can use to quickly set them up.
Second your SQL queries are out of step will standard practices. Check out the MySQL 5.0 Reference Manual Particualarly chapter 7 Optimization will help you some.
First usually in an SQL query your functions are capitalize. So SELECT, WHERE, FROM and all other MySQL functions are best capitalized. The primary reason for this is readablitity.
Second, usually it best to not have tables, columns, or data capitalized as it can interfer with the same readablity. In your case it looks to be random as to what is and is not capitalized. And it looks like in a couple palces you make a call to the a capitalized table (PRODUCTS) and in another place a call to a lower case table (products). I suspect this may have some bearing on the query as all other programing languages that difference would make those two tables totally diffenert tables.
You should also remember you may have to try and figure out what you coded 3 or 4 years down the road. Or worse yet you may run into the guy who has to edit it 3 or 4 years down the road. :glare:
So while those queries may work it is very hard to make heads or tails of what you they are doing without having to study it excesively.
To try and help I copied your code out to a editor and got it looking more readable
<table border="0" cellpadding="0" cellspacing="1" align="center">
<tr>
<?php
$sql_query = mysql_query("SELECT products_id, itemname, itemnumber FROM products, categoies WHERE products.products_id = categories.products_id ");
while ($sql = fetch_array($sql_query)) {
?>
<td>
<?php
$next_query = mysql_query("SELECT product_id FROM order, paypal WHERE orders.orders_id = paypal.item_number and paypal.result = 'verified'");
// i dont know what is right thing to do next its all wrong and what i get is lots of results spewing out from the db
while ($next=fetch_array($next_query) )
if($sql['products_id'] == $next['products_id']) {
for ($i=0, $n=sizeof($next); $i<$n; $i++) {
echo "sql[number]";
else
echo <a href="product_info.php">echo "sql[number]";[/url]
?>
</td>
<?php }?>
</tr>
</table>
And I found several mistakes
First I put the opening <?php tag in after the <td> in your first while statement.
Second, your second "while" statement doesn't have an opening or closing brackets { }
Third your "if" doesn't have a closing bracket }
Fourth your "for" doesn't have a closing bracket }
Fifth your "else" does have the open or closing brackets { }
Sixth I suspect that sql[number] should be $sql[number] (uncertain on that, still figuring your code out)
As well as you can see I made some massive changes to your SQL queries.
So see if after resolving all of that you can get it to work.
If not repost your edited code ( in the phpbb PHP tags) and let us know if you have any erros or what it does.
On a side note I do hope this is MySQL database. I just noticed are using query()instead of mysql_query(). And I looked up query() on php.net and that function doesn't exists.