Page 2 of 2

Posted: Mon Jul 16, 2007 2:20 pm
by RobertGonzalez
Like I said, more than one reason... What is missing at the end of this line?

Code: Select all

<?php
$counter = 0
?>

Posted: Mon Jul 16, 2007 2:23 pm
by beloveddoll
I added in the ; to the end of it. Now this error comes up:

Warning: Invalid argument supplied for foreach() in /home/secrett1/public_html/testing/collection.php on line 37

Posted: Mon Jul 16, 2007 2:30 pm
by beloveddoll
Aha, line 37 needed to be moved down a few lines. Thus the code becomes:

Code: Select all

<?

$counter = 0;
echo "<p>";

$res = mysql_query("SELECT id, user, item, price FROM coll_inven WHERE user='$log' ORDER BY id ASC");
while($r = mysql_fetch_row($res) ) $comments[] = $r;
foreach ($comments as $c)
{
?>
<?
$res = mysql_query("SELECT id, name, description, url, price, preview FROM collection WHERE id='$c[2]'");
$comico = mysql_fetch_row($res);
mysql_free_result($res);
?>
<a href="collectionview.php?id=<? echo "$comico[0]" ?>"><img src="collection/<? echo "$comico[5]" ?>" border=0></a>

<?
$counter++;
if ($counter % 20 == 0)
  {
    echo '</p><p>';
  }
}
echo '</p>'
?>

Posted: Mon Jul 16, 2007 3:38 pm
by dxm
beloveddoll wrote:Aha, line 37 needed to be moved down a few lines. Thus the code becomes:

Code: Select all

<a href="collectionview.php?id=<? echo "$comico[0]" ?>"><img src="collection/<? echo "$comico[5]" ?>" border=0></a>

Code: Select all

}
echo '</p>'
?>
Take a look at these lines... You're missing three semicolons here.

Also, try not to break in and out of PHP so much, for example, after the foreach ($comments as $c) {, you close and open PHP when you don't need to. A good structure can help alot when debugging. :)

Posted: Mon Jul 16, 2007 3:51 pm
by RobertGonzalez
You are also using short PHP tags, which is a no-no.

Posted: Mon Jul 16, 2007 4:26 pm
by John Cartwright
Kind of unrelated, but your better off using a single query to minimize the amount of queries you make.

Something like

Code: Select all

$counter = 0;

$sql = '
SELECT *
FROM coll_inven ON coll_inven.item = collection.id
INNER JOIN collection `col` 
WHERE coll_inven.user=\''.$log.'\' 
ORDER BY coll_inven.id ASC';

$res = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($res) > 0) {
   
   echo '<p>';
   while($row = mysql_fetch_assoc($res)) {
      //ouput stuff
      
      $counter++;
      if ($counter % 20 == 0) {
         echo '</p><p>';
      }
   }
   echo '</p>';
}