Forum Moderators: coopster

Message Too Old, No Replies

displaying entries in rows instead of on top of each other

php displaying rows

         

pixelfrog

5:55 am on Aug 2, 2004 (gmt 0)

10+ Year Member



I'm altering a voting script for our dog rescue so that we can hold an online photo contest.
I'm very new to php & mysql..kinda just muddling my way about with this.

I want to display the entries in a row across about 4 or 5 photos and then keep it going that way, but I haven't a clue as to how to do this.
Any help with this would be appreciated.

<table><tr><td><form method="POST" action="votechoice.php">


<?
$n=0;
while ($myrow = mysql_fetch_array($result)) {
$n++;
$votes = $myrow["votes"];
if ($votes == 0) { $per = 0; }
else { $per = ($votes / $total_votes) * 100; }
?>
</td></tr><tr><td><center><font face="verdana" size="-2"><b>Entry Number:<?php echo $n."."?></b></font>
<br><img src=<?php echo $myrow["name"]?> width=100 height=100><br><font face="verdana" size="-2" color=black><b><?php echo $myrow["pet"]?></b></font><br><a href=mailto://<?php echo $myrow["email"]?>><img src=email.gif border=0></a> <input type="radio" value="<?php echo $myrow["id"]?>" name="choice"> <a href=<?php echo $myrow["name"]?>><img src=photo.gif border=0></a><br></center><center><?php echo number_format($per,0,".","")."%"?></center>



<?
}
?></td>


</tr><tr><td><center><input type="submit" value="Vote" name="vote"></center>


</form></td></tr></table>

<b>Total votes submitted: <? echo $total_votes?> </b></font>


excuse the crappy coding...as I said before, I'm just figuring things out as I go.

[edited by: jatar_k at 7:03 am (utc) on Aug. 2, 2004]
[edit reason] no personal urls thanks [/edit]

dkin

6:03 am on Aug 3, 2004 (gmt 0)

10+ Year Member



"I want to display the entries in a row across about 4 or 5 photos and then keep it going that way, but I haven't a clue as to how to do this."

Im not completely sure what you mean by this.

Do you mean you would like the images to keep going as long as there is one left in the database.

Please Advise

dkin

6:22 am on Aug 3, 2004 (gmt 0)

10+ Year Member



I think this may be closer to what you are trying to do. This is completely untested. Please test it and print errors if there are some.

<?php
$n=0;
print "</td></tr><tr>";
while ($myrow = mysql_fetch_array($result)) {
$n++;
$votes = $myrow['votes'];
if ($votes == 0) {
$per = 0;
}
else {
$per = ($votes / $total_votes) * 100;
}
echo "<td>"
. "<center><font face=\"verdana\" size=\"-2\"><b>Entry Number:$n."."</b></font>"
. "<br>"
. "<img src=".$myrow['name']."width=100 height=100>"
. "<br>"
. "<font face=\"verdana\" size=\"-2\" color=\"000000\">"
. "<b>"
. "".$myrow['pet'].""
. "</b>"
. "</font>"
. "<br>"
. "<a href=\"mailto:".$myrow['email']."\">".$myrow['email']."</a>"
. "<img src=\"email.gif\" border=\"0\"></a>"
. "<input type=\"radio\" value=\"".$myrow['id']."\" name=\"choice\">"
. "<a href=\"".$myrow['name']."\"><img src=\"photo.gif\" border=\"0\"></a>"
. "<br>number_format($per,0,".","")."%"</center>"
. "</td>";
}
echo "</tr>"
. "<tr>"
. "<td>"
. "<center>"
. "<input type=\"submit\" value=\"Vote\" name=\"vote\"></center>"
. "</form>"
. "</td>"
. "</tr>"
. "</table>"
. "<b>Total votes submitted: $total_votes</b></font>";
?>

pixelfrog

2:11 pm on Aug 3, 2004 (gmt 0)

10+ Year Member



Okay I changed it:
<?php
. "<table>"
. "<tr>"
. "<td>"
. "<form method=\"POST\" action=\"votechoice.php\">"
$n=0;
print "</td></tr><tr>";
while ($myrow = mysql_fetch_array($result)) {
$n++;
$votes = $myrow['votes'];
if ($votes == 0) {
$per = 0;
}
else {
$per = ($votes / $total_votes) * 100;
}
echo "<td>"
. "<center><font face=\"verdana\" size=\"-2\"><b>Entry Number:$n."."</b></font>"
. "<br>"
. "<img src=".$myrow['name']."width=100 height=100>"
. "<br>"
. "<font face=\"verdana\" size=\"-2\" color=\"000000\">"
. "<b>"
. "".$myrow['pet'].""
. "</b>"
. "</font>"
. "<br>"
. "<a href=\"mailto:".$myrow['email']."\">".$myrow['email']."</a>"
. "<img src=\"email.gif\" border=\"0\"></a>"
. "<input type=\"radio\" value=\"".$myrow['id']."\" name=\"choice\">"
. "<a href=\"".$myrow['name']."\"><img src=\"photo.gif\" border=\"0\"></a>"
. "<br>number_format($per,0,".","")."%"</center>"
. "</td>";
}
echo "</tr>"
. "<tr>"
. "<td>"
. "<center>"
. "<input type=\"submit\" value=\"Vote\" name=\"vote\"></center>"
. "</form>"
. "</td>"
. "</tr>"
. "</table>"
. "<b>Total votes submitted: $total_votes</b></font>";
?>

Now I'm getting this error:
Parse error: parse error, unexpected '.' in /home/pxlfrog/public_html/photovote/voteoradd.php on line 38

pixelfrog

2:13 pm on Aug 3, 2004 (gmt 0)

10+ Year Member



also: basically what i'm trying to do is this

entry entry entry entry
entry entry entry entry
entry entry entry entry

instead of

entry
entry
entry
entry

BTW thanks for your help...this thing has been giving me migraines.

pixelfrog

2:59 pm on Aug 3, 2004 (gmt 0)

10+ Year Member



Okay now it's working using this code.
Thanks for your help. My knowledge is so limited, but seeing code examples helped me realize what I was looking for.
<table><tr><td><form method="POST" action="votechoice.php">
<?
$columns= 5;
$n=0;
echo "<tr>\n";
while ($myrow = mysql_fetch_array($result))
{
$n++;
if ($n == $columns)
{$n= 0;echo"</TR>\n";echo"<TR>\n";}
$votes = $myrow["votes"];
if ($votes == 0) { $per = 0; }
else { $per = ($votes / $total_votes) * 100; }
?>
<td align="center">
<font face="verdana" size="-2"><b>Entry Number:<?php echo

$n."."?></b></font>
<br>
<img src=<?php echo $myrow["name"]?> width=100 height=100><br>
<font face="verdana" size="-2" color=black><b><?php echo

$myrow["pet"]?></b></font><br>
<a href=mailto://<?php echo $myrow["email"]?>><img

src=email.gif border=0></a> <input type="radio" value="<?php echo

$myrow["id"]?>" name="choice">
<a href=<?php echo $myrow["name"]?>><img src=photo.gif

border=0></a><br>
<?php echo number_format($per,0,".","")."%"?></td>
<?
}
echo "</tr>\n";
?>
<tr><td align="center"><input type="submit" value="Vote"

name="vote"></td></tr>
</form>
</table>

coopster

3:34 pm on Aug 3, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, pixelfrog!

What you need to do is alter when you want to print out a new table row (<tr>). In order to do so, you need to use some form of "row counter" and print out the <tr>'s and <td>'s within your loop. An often used technique is the modulus operator. Modulus will return the remainder of the division.

$n=0; 
while ($myrow = mysql_fetch_array($result)) {
$votes = $myrow["votes"];
if ($votes == 0) { $per = 0; }
else { $per = ($votes / $total_votes) * 100; }
if ($n%4) {
print "\n</td><td>";
} else {
print "\n\n</td></tr><tr><td>";
}
$n++;
?>
<center><font...

<edit>Should have checked before posting, see you have it -- nice work ;)

pixelfrog

6:22 pm on Aug 3, 2004 (gmt 0)

10+ Year Member



Yeah, I did finally get it. Things are starting to click a bit.
PHP ain't that bad.
Things are starting to make sense when I'm working with it.
Thanks for your help though. :)
(& thanks for the welcome)