Jump to content

table output to multiple pages?


eraxian

Recommended Posts

You know when you click on a link on some website and it gives you a list or a table, w/ say 50 results, and at the bottom will show you <next page> 1, 2, 3,...7 <last> and so on. So these other pages are created dynamically to show the next 50 results. Is there a way to do this w/ php and mysql?

 

I have a database w/ names, and a table w/ the letters of the alphabet, and when a user clicks a letter it shows a table w/ all the names starting w/ that letter, but i dont want the table to be a mile long, so i wanted it to create other pages, is there a way to do this w/ php, if not what do i need to do it?

 

 

Also, perhaps an alternative to that, i have this simple code to create a dynamic html table from a mysql query, but it only puts the data into 1 column, what if i wanted to create a table w/ 2 or 3 columns? Perhaps some nested loop is needed, but i am very noobish, so any help would be appreciated, thanks.

 

<?php
$con = mysql_connect("server","username","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("bands", $con);

$result = mysql_query("SELECT * FROM list WHERE name LIKE 'B%' ORDER BY name");

echo "<table border='1'>
<tr>
<th>Bands</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . "<a href=\"/bands/list/" . $row['link'] . ".html\">" . $row['name'] .  "</a>" . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>

Link to comment
Share on other sites

try this one:

echo '<tr>
				<td width = "20" align = "left" valign = "top"><font class = "questions">'.$row['link'].'.</span><td>';
				echo '<td width = "280" align = "left" valign = "top" ><font class = "questions">'.$row['name'].'</span></td>';		

			'</tr>';

Link to comment
Share on other sites

Ok here is what i got so far, based off of the tutorial you linked me to, however i keep getting the error "no database selected" when clearly i have selected the database...

 

<?php
$con = mysql_connect("server","username","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("list", $con);
$query = "SELECT * FROM name WHERE name LIKE \'A%\' ORDER BY name";
$result = mysql_query($query) or die("There was a problem with the SQL query: " . mysql_error()); 
if($result && mysql_num_rows($result) > 0)
{
    $i = 0;
    $max_columns = 3;
    while($row = mysql_fetch_array($result))        
   {
       // make the variables easy to deal with
       extract($row);

       // open row if counter is zero
       if($i == 0)
          echo "<tr>";

       // make sure we have a valid product
       if($name != "" && $name != null)
          echo "<td>" . "<a href=\"/bands/list/" . $row['link'] . ".html\">" . $name .  "</a>" . "</td>";
    
       // increment counter - if counter = max columns, reset counter and close row
       if(++$i == $max_columns) 
       {
           echo "</tr>";
           $i=0;
       }  // end if 
   } // end while
} // end if results

// clean up table - makes your code valid!
if($i < $max_columns)
{
    for($j=$i; $j<$max_columns;$j++)
        echo "<td> </td>";
}
?>
</tr>
</table>

 

is my syntax wrong or something? :(

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.