Forum Moderators: coopster

Message Too Old, No Replies

Mysql, Certain tds and trs, help please

i found some info in another thread, need help gettin this to work

         

GamingLoft

9:25 am on Dec 2, 2007 (gmt 0)

10+ Year Member



Its supposed to put 3 tds in one row, but it ends up making all rows with only 1 td in each, help please!

$pidcheck = mysql_query("SELECT * FROM phpbb_posts_text
WHERE post_id='$pid'");

$tdcount = 1;
$numtd = 3; // number of cells per row
?>
<table border="0">
<?php
while ($row = mysql_fetch_array ($pidcheck))
{
$text = $row['short_desc'];
$text = stripslashes($text);
$subject = $row['post_subject'];

if ($tdcount == 1)
echo "<tr>";
?>
<td>
<?php
echo "<b><a href='videos.php?view=" . $topicid . "'></b><p>
<img src='images/videoimgs/" . $topicid . ".png' border='0' height='60px' width='60px' align='left'/><span class='genbig'>
" . $subject . "</a></span><br><span class='gensmall'>" . $text;
echo "</p></span><br><center>___________</center><br>"; // display as you like
?>
</td>
<?php
if ($tdcount == $numtd)
{
echo "</tr>";
$tdcount = 1;
} else {
$tdcount++;
}
}
}
}// time to close up our table
if ($tdcount!= 1)
{
while ($tdcount <= $numtd) {
echo "<td>&nbsp;</td>";
$tdcount++; } echo "</tr>";
}
?>
</table>

Habtom

9:42 am on Dec 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The surprise is that you have two extra brackets, which should generate an error unless there is something else above the code you mentioned.

I will go through the code one more time, and see if there is anything wrong in it, but it seems fine except what is mentioned above.

phranque

9:44 am on Dec 2, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



your brackets don't match up so it's hard to tell just from the code fragment what happens with that pile at the bottom...

GamingLoft

10:02 am on Dec 2, 2007 (gmt 0)

10+ Year Member



this might make em appear to line up, the complete code:

while($row = mysql_fetch_array($fidcheck))
{
$pid = $row['post_id'];
$posterid = $row['poster_id'];
$topicid = $row['topic_id'];

$first = mysql_query("SELECT * FROM phpbb_topics
WHERE topic_first_post_id='$pid'");

$vidnum = mysql_num_rows($first);

while($row = mysql_fetch_array($first))
{
$pid = $row['topic_first_post_id'];
$posterid = $row['topic_poster'];
$topicid = $row['topic_id'];

$getname = mysql_query("SELECT * FROM phpbb_users
WHERE user_id='$posterid'");

while($row = mysql_fetch_array($getname))
{
$author = $row['username'];
$authorid = $row['user_id'];
}
$pidcheck = mysql_query("SELECT * FROM phpbb_posts_text
WHERE post_id='$pid'");

$tdcount = 1;
$numtd = 3; // number of cells per row
?>
<table border="0">
<?php
while ($row = mysql_fetch_array ($pidcheck))
{
$text = $row['short_desc'];
$text = stripslashes($text);
$subject = $row['post_subject'];

if ($tdcount == 1)
echo "<tr>";
?>
<td>
<?php
echo "<b><a href='videos.php?view=" . $topicid . "'></b><p>
<img src='images/videoimgs/" . $topicid . ".png' border='0' height='60px' width='60px' align='left'/><span class='genbig'>
" . $subject . "</a></span><br><span class='gensmall'>" . $text;
echo "</p></span><br><center>___________</center><br>"; // display as you like
?>
</td>
<?php
if ($tdcount == $numtd)
{
echo "</tr>";
$tdcount = 1;
} else {
$tdcount++;
}
}
}
}// time to close up our table
if ($tdcount!= 1)
{
while ($tdcount <= $numtd) {
echo "<td>&nbsp;</td>";
$tdcount++; } echo "</tr>";
}
?>
</table>

Habtom

10:19 am on Dec 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You might start by editing one of the variables ($row) to something different, and edit the related code accordingly.

while($row = mysql_fetch_array($fidcheck))
. . .
while($row = mysql_fetch_array($first))
. . .

<added>
There is a third one also:
while($row = mysql_fetch_array($getname))
. . .

The $row variable needs to be different in all the cases.

[edited by: Habtom at 10:20 am (utc) on Dec. 2, 2007]

phranque

10:25 am on Dec 2, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



while it's not good practice, i'm not sure that is the problem here.
i would try habtom's suggestion nevertheless.
you might need to echo your test variables to see what is happening.

GamingLoft

10:32 am on Dec 2, 2007 (gmt 0)

10+ Year Member



k i fixed all the rows, they're all different but i still have the same problem, here this is the new code.

$fidcheck = mysql_query("SELECT * FROM phpbb_posts
WHERE forum_id='2' ORDER BY `post_id` DESC LIMIT 36");

while($row1 = mysql_fetch_array($fidcheck))
{
$pid = $row1['post_id'];
$posterid = $row1['poster_id'];
$topicid = $row1['topic_id'];

$first = mysql_query("SELECT * FROM phpbb_topics
WHERE topic_first_post_id='$pid'");

$vidnum = mysql_num_rows($first);

while($row2 = mysql_fetch_array($first))
{
$pid = $row2['topic_first_post_id'];
$posterid = $row2['topic_poster'];
$topicid = $row2['topic_id'];

$getname = mysql_query("SELECT * FROM phpbb_users
WHERE user_id='$posterid'");

while($row3 = mysql_fetch_array($getname))
{
$author = $row3['username'];
$authorid = $row3['user_id'];
}
$pidcheck = mysql_query("SELECT * FROM phpbb_posts_text
WHERE post_id='$pid'");

$tdcount = 1;
$numtd = 3; // number of cells per row
?>
<table border="0">
<?php
while ($row = mysql_fetch_array ($pidcheck))
{
$text = $row['short_desc'];
$text = stripslashes($text);
$subject = $row['post_subject'];

if ($tdcount == 1)
echo "<tr>";
?>
<td>
<?php
echo "<b><a href='videos.php?view=" . $topicid . "'></b><p>
<img src='images/videoimgs/" . $topicid . ".png' border='0' height='60px' width='60px' align='left'/><span class='genbig'>
" . $subject . "</a></span><br><span class='gensmall'>" . $text;
echo "</p></span><br><center>___________</center><br>"; // display as you like
?>
</td>
<?php
if ($tdcount == $numtd)
{
echo "</tr>";
$tdcount = 1;
} else {
$tdcount++;
}
}
}
}// time to close up our table
if ($tdcount!= 1)
{
while ($tdcount <= $numtd) {
echo "<td>&nbsp;</td>";
$tdcount++; } echo "</tr>";
}
?>
</table>

Habtom

10:49 am on Dec 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I suggest you do the following:

> See the the the html source, and check if you are really getting <tr><td></td></tr> or the opening and closing tags are messed. That might give you some hint, and the output on the screen might not show you what kind of code structure you have on the source. So, check the source.

> If it is generating the <tr><td></td></tr> opening and closing it properly, but displaying only one td in a tr: Though I know the increment is supposed to work that way, try changing it to: $tdcount = $tdcount + 1;

> if ($tdcount == 1) echo "<tr>";
if ($tdcount == 1) { echo "<tr>"; }

Let's narrow down the possible reasons, but the code in general seems ok with me.

GamingLoft

11:03 am on Dec 2, 2007 (gmt 0)

10+ Year Member



CODE FROM HTML SOURCE.
ok so obviously you can look at that and know whats going on so i wont bother explaining.

<table border="0">
<tr><td>
[ENTERS ONE HERE]</td>
<table border="0">
<tr><td>[ENTERS ONE HERE]</td>
<table border="0">
<tr><td>[ENTERS ONE HERE]</td>
<table border="0">
<tr><td>[ENTERS ONE HERE]</td>
<td>[PUTS SPACE HERE]</td><td>[PUTS SPACE HERE]</td></tr></table></td>
</tr>
</table>

[edited by: GamingLoft at 11:04 am (utc) on Dec. 2, 2007]

Habtom

11:09 am on Dec 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First thing you need to do is, move out the:
<table border="0">
up to close to the first line, out of the loops, there doesn't seem to be any reason why it should be in the loop.

GamingLoft

11:17 am on Dec 2, 2007 (gmt 0)

10+ Year Member



k i moved the <table> tag to the top of the file, outside the php, but the problem still exsits.

ok its doing this


[1]
[2]
[3]
[4][5(empty)][6(empty)]

like only 5 and 6 are empty (thats because i only have 4 rows in my table)

[1][edited by: GamingLoft at 11:29 am (utc) on Dec. 2, 2007]

Habtom

11:21 am on Dec 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Can you describe the result & edit your post - urls are not allowed here?

GamingLoft

11:26 am on Dec 2, 2007 (gmt 0)

10+ Year Member



kso haven't we pretty much eliminated all of the reasons things could be going wrong?

Habtom

11:36 am on Dec 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to take the following lines out of the loops:

$tdcount = 1;
$numtd = 3; // number of cells per row

Whenever it is running again, it is setting it back.

Put the lines out of all the loops right at the top.

[edited by: Habtom at 11:37 am (utc) on Dec. 2, 2007]

GamingLoft

11:39 am on Dec 2, 2007 (gmt 0)

10+ Year Member



Its fixed! great, wow, 2 lines in the wrong spot ruined the whole thing, thanks a lot, i know i took up a bunch of you're time. But i do, REALLY REALLY appreciate it.