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

Link to comment
Share on other sites

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!!

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.