Page 1 of 2
New paragraph for every 20 entries
Posted: Mon Jul 16, 2007 9:27 am
by beloveddoll
I have the following code:
Code: Select all
<?
$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;
if ($comments) 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>
<?
}
?>
How do I tell the code to insert a new paragraph after every 20 entries?
Posted: Mon Jul 16, 2007 9:34 am
by Gente
Add the $counter, increment it in every iteration and if $counter divides into 20 add paragraph

Posted: Mon Jul 16, 2007 9:43 am
by beloveddoll
Gente wrote:Add the $counter, increment it in every iteration and if $counter divides into 20 add paragraph

Could you make an example? I`m still new the php world. ^^;
Posted: Mon Jul 16, 2007 9:47 am
by Gente
Code: Select all
$countrer = 0
echo '<p>';
foreach ($a as $b)
{
....
if ($counter % 20 == 0)
{
echo '</p><p>';
}
....
$counter++;
}
echo '</p>'
Something like this...
Posted: Mon Jul 16, 2007 10:08 am
by beloveddoll
Gente wrote:Code: Select all
$countrer = 0
echo '<p>';
foreach ($a as $b)
{
....
if ($counter % 20 == 0)
{
echo '</p><p>';
}
....
$counter++;
}
echo '</p>'
Something like this...
Ok, I want to be sure I understand this.
I would have the code as:
Code: Select all
<?
$countrer = 0
echo '<p>';
foreach ($a as $b)
{
$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;
if ($comments) foreach($comments as $c){
if ($counter % 20 == 0)
{
echo '</p><p>';
}
?>
<?
$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++;
}
echo '</p>'
?>
Right?
Posted: Mon Jul 16, 2007 10:19 am
by Gente
No. $a and $b were abstract... I tried to show yours foreach.
BTW. It looks very strange... Every time you execute the same query.
Posted: Mon Jul 16, 2007 10:24 am
by beloveddoll
Gente wrote:
BTW. It looks very strange... Every time you execute the same query.
What do you mean?
This code is to show what a user would have in their inventory if they added anything to their inventory.
Posted: Mon Jul 16, 2007 10:26 am
by beloveddoll
Ok, I tweaked it, does it look the way it should?
Code: Select all
<?
$countrer = 0
echo '<p>';
foreach ($comments as $c)
{
$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;
if ($counter % 20 == 0)
{
echo '</p><p>';
}
?>
<?
$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++;
}
echo '</p>'
?>
Posted: Mon Jul 16, 2007 10:31 am
by Gente
Looks good but please but that's would be better:
Code: Select all
<?
$countrer = 0
echo '<p>';
foreach ($comments as $c)
{
$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;
?>
<?
$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 12:44 pm
by beloveddoll
I get this error:
Parse error: syntax error, unexpected T_ECHO in /home/secrett1/public_html/testing/collection.php on line 36
Posted: Mon Jul 16, 2007 12:52 pm
by ianhull
whoops
Posted: Mon Jul 16, 2007 1:13 pm
by RobertGonzalez
This will give you problems for more than one reason...
Posted: Mon Jul 16, 2007 2:13 pm
by beloveddoll
I fixed that and it still gives me this error message:
Parse error: syntax error, unexpected T_ECHO in /home/secrett1/public_html/testing/collection.php on line 36
line 36 is:
Posted: Mon Jul 16, 2007 2:14 pm
by RobertGonzalez
Show us the fix you implemented.
Posted: Mon Jul 16, 2007 2:17 pm
by beloveddoll
Code: Select all
<?
$counter = 0
echo "<p>";
foreach ($comments as $c)
{
$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;
?>
<?
$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>'
?>