FrostedFlakes Posted April 8, 2007 Share Posted April 8, 2007 I have a problem with my php code; I'm trying to list links for downloading. Problem is that there are 3 different types that need to be echo-ed in their own table column. So far this is what I have; This will list only about 1/2 of the sql entries. <?php $rs1 = @mysql_connect( "******", "******", "******" ); $rs1 = @mysql_select_db( "******" ); $rs2 = @mysql_connect( "******", "******", "******" ); $rs2 = @mysql_select_db( "******" ); $rs3 = @mysql_connect( "******", "******", "******" ); $rs3 = @mysql_select_db( "******" ); $sql1 = "SELECT * FROM `downloads` WHERE (typen='1') AND (id>'0') LIMIT 0 , 100"; $rs1 = @mysql_query( $sql1 ); $sql2 = "SELECT * FROM `downloads` WHERE (typen='2') AND (id>'0') LIMIT 0 , 100"; $rs2 = @mysql_query( $sql2 ); $sql3 = "SELECT * FROM `downloads` WHERE (typen='3') AND (id>'0') LIMIT 0 , 100"; $rs3 = @mysql_query( $sql3 ); while( $row1 = mysql_fetch_array( $rs1 ) and $row2 = mysql_fetch_array( $rs2 ) and $row3 = mysql_fetch_array( $rs3 ) ) { ?> <tr valign="center" align="center"> <td valign="center" align="center"><font face="Arial" size="2"> <a href="<?php echo( $row1['url'] ); ?>"><?php echo( $row1['name'] ); ?></a> <?php echo( $row1['comment'] ); ?><br> </font> </td> <td valign="center" align="center"><font face="Arial" size="2"> <a href="<?php echo( $row2['url'] ); ?>"><?php echo( $row2['name'] ); ?></a> <?php echo( $row2['comment'] ); ?><br> </font> </td> <td valign="center" align="center"><font face="Arial" size="2"> <a href="<?php echo( $row3['url'] ); ?>"><?php echo( $row3['name'] ); ?></a> <?php echo( $row3['comment'] ); ?><br> </font> </td> </tr> <?php } ?> Please don't laugh at my barbaric ways. I've been doing PHP and MySQL by myself using trial and error. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 8, 2007 Share Posted April 8, 2007 um, you could while loop your querys i think, and also through your html output, loop throught the array not 100% sure what you want gd lk Quote Link to comment Share on other sites More sharing options...
FrostedFlakes Posted April 8, 2007 Author Share Posted April 8, 2007 I am using a while loop. Please don't randomly stab at answers. Quote Link to comment Share on other sites More sharing options...
esukf Posted April 8, 2007 Share Posted April 8, 2007 The problem is your while statement. <?php while( $row1 = mysql_fetch_array( $rs1 ) and $row2 = mysql_fetch_array( $rs2 ) and $row3 = mysql_fetch_array( $rs3 ) ) ?> Your while loop will stop as soon as any of of the mysql_fetch_array returns false. Say there are 10 rows in $rs1 and 100 in $rs3, the while loop will exit as soon as $row1 = mysql_fetch_array($rs1) returns false after the 10th rows. Quote Link to comment Share on other sites More sharing options...
FrostedFlakes Posted April 8, 2007 Author Share Posted April 8, 2007 Problem found, thanks. Now any suggestions for fixing it? Quote Link to comment Share on other sites More sharing options...
per1os Posted April 8, 2007 Share Posted April 8, 2007 EDIT: DAMN SPACE BAR, try this: <?php $rs1 = @mysql_connect( "******", "******", "******" ); $rs1 = @mysql_select_db( "******" ); $rs2 = @mysql_connect( "******", "******", "******" ); $rs2 = @mysql_select_db( "******" ); $rs3 = @mysql_connect( "******", "******", "******" ); $rs3 = @mysql_select_db( "******" ); $sql1 = "SELECT * FROM `downloads` WHERE (typen='1') AND (id>'0') LIMIT 0 , 100"; $rs1 = @mysql_query( $sql1 ); $sql2 = "SELECT * FROM `downloads` WHERE (typen='2') AND (id>'0') LIMIT 0 , 100"; $rs2 = @mysql_query( $sql2 ); $sql3 = "SELECT * FROM `downloads` WHERE (typen='3') AND (id>'0') LIMIT 0 , 100"; $rs3 = @mysql_query( $sql3 ); while($row = mysql_fetch_array( $rs1 )) { $rows1[] = $row; } while($row = mysql_fetch_array( $rs2 )) { $rows2[] = $row; } while($row = mysql_fetch_array( $rs3 )) { $rows3[] = $row; } for ($i=0;$i<count($rows1);$i++) { echo '<tr valign="center" align="center">'; if (isset($rows1[$i])) { ?> <td valign="center" align="center"><font face="Arial" size="2"> <a href="<?php echo( $rows1[$i]['url'] ); ?>"><?php echo( $rows1[$i]['name'] ); ?></a> <?php echo( $rows1[$i]['comment'] ); ?><br> </font> </td> <?php } if (isset($rows2[$i])) { ?> <td valign="center" align="center"><font face="Arial" size="2"> <a href="<?php echo( $rows2[$i]['url'] ); ?>"><?php echo( $rows2[$i]['name'] ); ?></a> <?php echo( $rows2[$i]['comment'] ); ?><br> </font> </td> <?php } if (isset($rows3[$i])) { ?> <td valign="center" align="center"><font face="Arial" size="2"> <a href="<?php echo( $rows3[$i]['url'] ); ?>"><?php echo( $rows3[$i]['name'] ); ?></a> <?php echo( $rows3[$i]['comment'] ); ?><br> </font> </td> <?php } echo ' </tr>'; } ?> Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 8, 2007 Share Posted April 8, 2007 or if that doesnt work, then simply in the original while, instead of and, place || Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 8, 2007 Share Posted April 8, 2007 First, why are you connecting the the database 3 time? You only need one connection. Change <?php $rs1 = @mysql_connect( "******", "******", "******" ); $rs1 = @mysql_select_db( "******" ); $rs2 = @mysql_connect( "******", "******", "******" ); $rs2 = @mysql_select_db( "******" ); $rs3 = @mysql_connect( "******", "******", "******" ); $rs3 = @mysql_select_db( "******" ); ?> to <?php $dbcon = mysql_connect( "******", "******", "******" ) or die("Couldn't connect, error: " . mysql_error()); $dbsel = mysql_select_db( "******" ) or die("Couldn't select database, error: " . mysql_error()); ?> Next, you can combine the three queries into one. Change: <?php $sql1 = "SELECT * FROM `downloads` WHERE (typen='1') AND (id>'0') LIMIT 0 , 100"; $rs1 = @mysql_query( $sql1 ); $sql2 = "SELECT * FROM `downloads` WHERE (typen='2') AND (id>'0') LIMIT 0 , 100"; $rs2 = @mysql_query( $sql2 ); $sql3 = "SELECT * FROM `downloads` WHERE (typen='3') AND (id>'0') LIMIT 0 , 100"; $rs3 = @mysql_query( $sql3 ); ?> to <?php $query = "SELECT * FROM `downloads` WHERE id > 0 and typen in ('1','2','3')"; $rs = mysql_query($query) or die("Problem with the query <pre>$query</pre><br>" . mysql_error()); ?> Now you can write your loop as: <?php while ($rw = mysql_fetch_assoc($rs)) { $tmp = array(); $tmp[rw['typen']] = '<a href="' . $rw['url'] . '"><' . $rw['name'] . '</a> ' . $rw['comment'] . '<br>'; } echo '<tr valign="center" align="center">'; for ($i=1;$i<4;$i++) { echo '<td valign="center" align="center"><font face="Arial" size="2">'; echo $tmp[$i]; echo '</font>'; echo '</td>'; } echo '</tr>'; ?> I think this will give you what you want. Untested, my have syntax errors and/or logic errors. Ken Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.