freemancomputer Posted March 9, 2011 Share Posted March 9, 2011 I am trying to get the output for a mysql query to be displayed in colums. I have it where it does this but it goes from left to right. I would rather it go from top to bottem, it would look better this way. I will also need it to brake into sevral pages when there are a certain amout of entrys shown. If you know of a good how to on that let me know please. The other problom that I am having is to make the output a link. I was able to do this before I attemped to devide everything but if I add in what I had before it comes back with no data. Here's what I have now that put shows the data from left to right in 2 colums. <?php include"scripts/connect.php" ; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM movies WHERE type LIKE 'movie' ORDER BY title"; if(mysql_query($query)) { $result=mysql_query($query); $num=mysql_numrows($result); } for($i=0; $i<$num; $i++) { if($i%2==0){ echo "<tr><td>"; } else{ echo "<td>"; } print mysql_result($result,$i,"title"); if ($i%2==0){ echo "</td>"; } else{ echo "</td>"; } } echo "</tr>"; ?> Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/230135-colums-and-links/ Share on other sites More sharing options...
RussellReal Posted March 9, 2011 Share Posted March 9, 2011 link to the page that currently works please.. Aswell as a better description of what it is you want top to bottom, single collumn, multiple collumns? you needa be more specific. Quote Link to comment https://forums.phpfreaks.com/topic/230135-colums-and-links/#findComment-1185191 Share on other sites More sharing options...
Maq Posted March 9, 2011 Share Posted March 9, 2011 Please use code tags. Quote Link to comment https://forums.phpfreaks.com/topic/230135-colums-and-links/#findComment-1185192 Share on other sites More sharing options...
freemancomputer Posted March 9, 2011 Author Share Posted March 9, 2011 Right now you can only reach the site from inside of my network. What its showing now is 1 2 3 4 5 6 I would like it to show 1 4 2 5 3 6 Quote Link to comment https://forums.phpfreaks.com/topic/230135-colums-and-links/#findComment-1185196 Share on other sites More sharing options...
jcbones Posted March 9, 2011 Share Posted March 9, 2011 See what this gives you. <?php include"scripts/connect.php" ; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM movies WHERE type LIKE 'movie' ORDER BY title"; $result = mysql_query($query) or trigger_error($query . ' has encountered an error: <br />' . mysql_error()); $num = mysql_num_rows($result) $half_rows = floor($num / 2); $i = 0; if($num > 0) { echo '<div style="float:left">'; while($row = mysql_fetch_assoc($result)) { echo $result['title'] . '<br/>'; if(++$i == $half_rows) { echo '</div><div>'; } } echo '</div>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/230135-colums-and-links/#findComment-1185214 Share on other sites More sharing options...
freemancomputer Posted March 10, 2011 Author Share Posted March 10, 2011 jcbones thanks for the reply. When I added that and go to the page I get the page, header, footer and the such just none of the data that should be there. Going to look at it to see if I can figure it out. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/230135-colums-and-links/#findComment-1185385 Share on other sites More sharing options...
freemancomputer Posted March 10, 2011 Author Share Posted March 10, 2011 I added the ini_set ("display_errors", "1"); error_reporting(E_ALL); to what jcbones gave me and received no errors Quote Link to comment https://forums.phpfreaks.com/topic/230135-colums-and-links/#findComment-1185394 Share on other sites More sharing options...
jcbones Posted March 10, 2011 Share Posted March 10, 2011 You should get a parse error, I forgot the semi-colon on $num = mysql_num_rows($result) Must add semi-colon on it. $num = mysql_num_rows($result); Quote Link to comment https://forums.phpfreaks.com/topic/230135-colums-and-links/#findComment-1185433 Share on other sites More sharing options...
freemancomputer Posted March 10, 2011 Author Share Posted March 10, 2011 sorry, I already added that in after it didn't work on the first go around. Quote Link to comment https://forums.phpfreaks.com/topic/230135-colums-and-links/#findComment-1185434 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.