PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Mon Jul 16, 2007 2:20 pm
Like I said, more than one reason... What is missing at the end of this line?
beloveddoll
Forum Commoner
Posts: 40 Joined: Sat Jul 14, 2007 6:18 pm
Post
by beloveddoll » Mon Jul 16, 2007 2:23 pm
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
beloveddoll
Forum Commoner
Posts: 40 Joined: Sat Jul 14, 2007 6:18 pm
Post
by beloveddoll » Mon Jul 16, 2007 2:30 pm
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>'
?>
dxm
Forum Newbie
Posts: 8 Joined: Fri Jun 29, 2007 5:18 pm
Location: Wales
Post
by dxm » Mon Jul 16, 2007 3:38 pm
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>
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.
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Mon Jul 16, 2007 3:51 pm
You are also using short PHP tags, which is a no-no.
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Mon Jul 16, 2007 4:26 pm
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>';
}