Jump to content

colums and links


freemancomputer

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/230135-colums-and-links/
Share on other sites

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>';
}
?>

Link to comment
https://forums.phpfreaks.com/topic/230135-colums-and-links/#findComment-1185214
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.