porta325 Posted June 19, 2007 Share Posted June 19, 2007 How should the script look if i wanna return let's say 20 entries in rows with 3 columns. Something like ... 1 | 2 | 3 4 | 5 | 6 ...etc. Quote Link to comment https://forums.phpfreaks.com/topic/56187-return-querry-by-rows/ Share on other sites More sharing options...
grlayouts Posted June 19, 2007 Share Posted June 19, 2007 what do you have so far? Quote Link to comment https://forums.phpfreaks.com/topic/56187-return-querry-by-rows/#findComment-277526 Share on other sites More sharing options...
MasterACE14 Posted June 19, 2007 Share Posted June 19, 2007 try: <?php echo '<pre>'; echo ($queryresults); echo '</pre>'; ?> This should format your layout, but I don't know how to work how many columns you want, your best bet is to display results in a HTML table. Regards ACE Quote Link to comment https://forums.phpfreaks.com/topic/56187-return-querry-by-rows/#findComment-277528 Share on other sites More sharing options...
porta325 Posted June 19, 2007 Author Share Posted June 19, 2007 I have this but it displays only on single column. <head> <title>Untitled Document</title> </head> <body> <?php //connect mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("directory") or die(mysql_error()); //select table $result = mysql_query ("SELECT * FROM countries WHERE statut = 1"); //print result while ($row = mysql_fetch_array ($result)){ $id=$row["id"]; $statut=$row["statut"]; $country=$row["country"]; echo "<a href=\"showlinks.php?country={$country}\">{$country}</a><br />"; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/56187-return-querry-by-rows/#findComment-277529 Share on other sites More sharing options...
porta325 Posted June 19, 2007 Author Share Posted June 19, 2007 Thx ACE but that only changes the font or something. Quote Link to comment https://forums.phpfreaks.com/topic/56187-return-querry-by-rows/#findComment-277530 Share on other sites More sharing options...
grlayouts Posted June 19, 2007 Share Posted June 19, 2007 porta your script has no table html. ie rows and colums. Quote Link to comment https://forums.phpfreaks.com/topic/56187-return-querry-by-rows/#findComment-277533 Share on other sites More sharing options...
porta325 Posted June 19, 2007 Author Share Posted June 19, 2007 I know, because i don't know how to associate the HTML table with the variables.I know i need a table but i don't know where to go next even if i have a table. Quote Link to comment https://forums.phpfreaks.com/topic/56187-return-querry-by-rows/#findComment-277537 Share on other sites More sharing options...
MasterACE14 Posted June 19, 2007 Share Posted June 19, 2007 I'm so close! take a look: <head> <title>Untitled Document</title> </head> <body> <?php //connect mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("directory") or die(mysql_error()); //select table $result = mysql_query ("SELECT * FROM countries WHERE statut = 1"); //print result while ($row = mysql_fetch_array ($result)){ $id=$row["id"]; $statut=$row["statut"]; $country=$row["country"]; echo '<table border="1">'; echo '<tr>'; echo '<td><a href="showlinks.php?country={$country}">$country</a></td>'; echo '</tr>'; echo '</table>'; } ?> </body> </html> just having trouble echo'ing the $country that is displayed in the table. Regards ACE Quote Link to comment https://forums.phpfreaks.com/topic/56187-return-querry-by-rows/#findComment-277541 Share on other sites More sharing options...
porta325 Posted June 19, 2007 Author Share Posted June 19, 2007 This can't possibly work, it must be some kinda loop. Quote Link to comment https://forums.phpfreaks.com/topic/56187-return-querry-by-rows/#findComment-277543 Share on other sites More sharing options...
MasterACE14 Posted June 19, 2007 Share Posted June 19, 2007 the table does work with the loop, it will add a new column to the table for every result etc. unless I've missed something and your trying to do something else ??? UPDATED: Got it! I don't know if its what you wanted or not, but I got it working <head> <title>Untitled Document</title> </head> <body> <?php //connect mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("directory") or die(mysql_error()); //select table $result = mysql_query ("SELECT * FROM countries WHERE statut = 1"); //print result while ($row = mysql_fetch_array ($result)){ $id=$row["id"]; $statut=$row["statut"]; $country=$row["country"]; echo '<table border="1">'; echo '<tr>'; echo '<td>'; echo '<td><a href="showlinks.php?country=$country">' . $country . '</a></td>'; echo '</td>'; echo '</tr>'; echo '</table>'; } ?> </body> </html> you can also show other things in the table that relate to that one result. echo '<table border="1">'; echo '<tr>'; echo '<td>'; echo '<td>' . $id . '</td>'; echo '<td>' . $statut . '</td>'; echo '<td><a href="showlinks.php?country=$country">' . $country . '</a></td>'; echo '</td>'; echo '</tr>'; echo '</table>'; Regards ACE Quote Link to comment https://forums.phpfreaks.com/topic/56187-return-querry-by-rows/#findComment-277546 Share on other sites More sharing options...
porta325 Posted June 19, 2007 Author Share Posted June 19, 2007 I don't want to build a table for what i have, i just want my entries in my database to look like this 1 | 2 | 3 4 | 5 | 6 So...first 3 entries on the first row next 3 entries on the second row and so on. Quote Link to comment https://forums.phpfreaks.com/topic/56187-return-querry-by-rows/#findComment-277551 Share on other sites More sharing options...
MasterACE14 Posted June 19, 2007 Share Posted June 19, 2007 hmm, I'm guessing you need to use arrays to do that, but I'm no good with arrays sorry :-\ Regards ACE Quote Link to comment https://forums.phpfreaks.com/topic/56187-return-querry-by-rows/#findComment-277553 Share on other sites More sharing options...
porta325 Posted June 19, 2007 Author Share Posted June 19, 2007 Thx anyway. Quote Link to comment https://forums.phpfreaks.com/topic/56187-return-querry-by-rows/#findComment-277555 Share on other sites More sharing options...
grlayouts Posted June 19, 2007 Share Posted June 19, 2007 i'm on pda so i cant write the code you need. http://www.terrawebdesign.com/multidimensional.php that should help you get a rough idea using arrays to create what you need.. if you cant get it msg me and i'll code it when im on a pc. Quote Link to comment https://forums.phpfreaks.com/topic/56187-return-querry-by-rows/#findComment-277559 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.