Jump to content

Using CSS to format MySQL query


ja_blackburn

Recommended Posts

Hi,

 

If i want to have a news page on my site, which displays all records of a table in descending order by date I am using the below code. I can display it all in a big table but this is a bit boring. Can I use CSS to present these records and still have them repeat like when using a table? Or is it best to just use plain old tables?? How would I add the divs to the below statement? Thanks!

 

Here is my code...

 

<?

 

include'E:\domains\s\domain.com\user\private\mysql_connect.php';

 

mysql_select_db("pix", $con);

 

$result = mysql_query("SELECT * FROM news_article ORDER BY date DESC");

 

 

 

while($row = mysql_fetch_array($result))

  {

 

  echo  $row['title']  ;

  echo  $row['date']  ;

  echo  $row['content']  ;

  echo  $row['image_url']  ;

  }

 

 

mysql_close($con);

?>

Link to comment
https://forums.phpfreaks.com/topic/177330-using-css-to-format-mysql-query/
Share on other sites

echo  "<div class='whatever'><h3>$row['title']</h3></div> ";

 

now weather you use class or id, h3 or h1 doesn't matter. this is just an example of how to format such. i use single quotes(as shown above) so i don't have to do all of the escaping of double quotes also cutting down on how much code the server has to render( / for every quote adds up quick). you will need to double quote the echo string. hope this helps.

Thanks in the end i have used classes on a table.

 

In my code below you will see that I have applied classes to the TD tag and this has been sucessful. I want to apply a class to each row that I have called news_row which has a bottom margin and border to distinguish my list of news articles. But the class I have written is not being applied to the TR tag?

 

Here is my CSS:

 

.news_row{

margin: 0px 0px 10px 0px;

border-bottom: 1px solid #fff;

}

 

Here is the PHP:

 

<?

 

include'E:\domains\s\domain.com\user\private\mysql_connect.php';

 

mysql_select_db("pix", $con);

 

$result = mysql_query("SELECT * FROM news_article ORDER BY date DESC");

 

echo "<table border='0'>

<tr>

<th></th>

<th></th>

<th></th>

<th></th>

</tr>";

 

while($row = mysql_fetch_array($result))

 

  {

  echo "<tr class='news_row'>";

  echo "<td class='large' width='300'>" . $row['title'] . "</td>";

  echo "<td class='medium' width='100'>" . $row['date'] . "</td>";

  echo "<td>" . $row['content'] . "</td>";

  echo "<td width='200'>" . $row['image_url'] . "</td>";

  echo "</tr>";

  }

echo "</table>";

 

 

mysql_close($con);

?>

 

As always help much appreciated!!

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.