Jump to content

Table Layout. PHP :(


payney

Recommended Posts

Hi guys, I cant figure out how to do the following.

 

My query returns 10 rows, and I want the layout to do the following.

 

Each row as 2 columns and then they are listed under one another. Just like the products are here:

 

http://www.yorkfitness.com/Treadmills-cat-501/Index.html

 

This is my code:

 

<?php

 

 

 

if (!($connection = @ mysql_pconnect($hostname,$username, $password)))

                        showerror();

 

                    if (!mysql_select_db($databaseName, $connection))

                        showerror();

 

$query = "SELECT n.name As News_Name FROM NEWS n";

  if (!($result = @ mysql_query ($query, $connection)))

                          showerror();

 

  // execute query

$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

 

if (mysql_num_rows($result) > 0) {

     

}

 

else {

 

    echo "No information for the home page set!";

  }

while ($row = mysql_fetch_assoc($result)) {

 

?>     

       

          <? echo $row['News_Name']; ?>

          <?

    }

 

mysql_free_result($result);

 

// close connection

mysql_close($connection);

 

 

?>

 

Link to comment
https://forums.phpfreaks.com/topic/104222-table-layout-php/
Share on other sites

this is how i would do it:

 

<?php
  if (!($connection = @ mysql_pconnect($hostname,$username, $password)))
    showerror();
  if (!mysql_select_db($databaseName, $connection))
    showerror();
  $query = "SELECT n.name As News_Name FROM NEWS n";
  if (!($result = @ mysql_query ($query, $connection)))
    showerror();   
                   
  // execute query
  //$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
  //Query was already executed above
   
  if(mysql_num_rows($result) > 0){
    print '<table>';
    for($n = 0;$row = mysql_fetch_assoc($result);$n++){
      if($n && !($n%2))
        echo '</tr><tr>';
      echo "<td>{$row['News_Name']}</td>";
    }
  } else {
    echo "No information for the home page set!";
  }
  mysql_free_result($result);

  // close connection
  mysql_close($connection);    
?>

Link to comment
https://forums.phpfreaks.com/topic/104222-table-layout-php/#findComment-533576
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.