Jump to content

[SOLVED] Displaying News


Deathwillow

Recommended Posts

So i'm COMPLETELY new to php and was looking for a place to help me learn and hopefully I've found it.  I'm currently just writing a simple news script using mySQL to store the information.  I've come across a problem though. Maybe you guys can help me out with it:

 

<?php
//Open connection
include("config.php");
//Select database
$connection = mysql_select_db("**********") or die(mysql_error());
echo "Connected";
//Create Query
$query = "SELECT * FROM news";
$result = mysql_query($query);
if ($result) {
echo "<link href=news.css rel=stylesheet type=text/css>";
while ($row = mysql_fetch_array($result)) {
	echo "<table id=news class=newsBox cellpadding=0 cellspacing=0>";
	echo "<tr>";
		echo "<td colspan=2 rowspan=4 class=topLeft><img src=images/" . $row["icon"] . "></td>";
	echo "</tr>";
	echo "<tr>";
		echo "<td class=topTop colspan=2></td>"
		echo "<td class=topRight rowspan=3></td>"
	echo "</tr>";
	echo "<tr>";
		echo "<td class=titleBack><div class=newsTitle>" . $row["title"] . "</div></td>";
	echo "</tr>";
	echo "<tr>";
		echo "<td class=topBottom colspan=2></td>"
	echo "</tr>";
	echo "<tr>";
		echo "<td class=left></td>";
		echo "<td class=left2 colspan=2>";
			echo "<div class=boxContent>" . $row["blog"] . "</div>";
		echo "</td>";
		echo "<td class=boxContent></td>";
		echo "<td class=right></td>";
	echo "</tr>";
	echo "<tr>";
		echo "<td class=bottomLeft></td>";
		echo "<td class=bottomLeft2></td>";
		echo "<td class=bottom></td>";
		echo "<td class=bottomRight></td>";
	echo "</tr>";
	echo "</table>";		
}
echo "</table>";
} else {
echo "<div>Error</div>";
}

 

Doesn't display anything, nor give any errors.  I could be going about it completely the wrong way, but I'm only following examples I've come across and I usually jump right into things pretty quickly.  Any help would be greatly appreciated! :)

Link to comment
Share on other sites

Fixed the extra    echo "</table>"; at the end, still get a blank screen.

i'm not sure it matters but you never opened <html> and <body> (unless your include file does that for ya), but either way, you could add a border to the table temporarily to see if it's even drawing the table (meaning data isn't being pulled from the database)

 

good luck

 

 

Link to comment
Share on other sites

This is the source code that calls the newscript

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>A useless website designed by Deathwillow</title>
<link href="news.css" rel="stylesheet" type="text/css">
    <link href="main.css" rel="stylesheet" type="text/css">
    <script src="http://www.wowhead.com/widgets/power.js"></script>
    <script type="text/javascript" src="jquery.js"/><!-- kicks so much ass --></script>
</head>

<body>
<center>
<table height="100%" class="main" cellpadding="0" cellspacing="0">
<tr>
    	<td class="mainLeft" rowspan="3"></td>
        <td class="mainCenter"></td>
        <td class="mainRight" rowspan="3"></td>
    </tr>
    <tr>
        <td class="mainLinks">
        	<div class="linkBarsTop">Top division</div>
            <div class="linkBarsBottom">Bottom Division</div>
        </td>
    </tr>
    <tr>
    	<td class="mainContent" valign="top" align="center">
		<?php include("addNews.php"); ?>
        </td>
    </tr>
</table>
</center>
</body>
</html>

Link to comment
Share on other sites

What I'm thinking might be is maybe the CSS file?  all the information as far as the width, height, background etc etc of the table are held in that file.  Am I not able to use the news.css file?

 

here's the code in the css file I'm talking about:

 

#news { width: 600px; height: auto }
table.newsBox { margin: 0px; border: 0px; font-family: Arial, Helvetica, Sans-serif; font-size: 0.7em; width: 100% }
table.newsBox td { padding: 0px }
table.newsBox td.topLeft { width: 80px; height: 80px; background-position: 15% 15% }
table.newsBox td.topBlank { width: 500px; height: 10px }
table.newsBox td.topTop { width: 500px; height: 14px }
table.newsBox td.topBottom { width: 500px; height: 48px }
table.newsBox td.topRight { width: 18px; height: 80px }
table.newsBox td.left { width: 22; height: auto }
table.newsBox td.left2 { width: 58; height: auto }
table.newsBox td.boxContent { width: auto; height: auto }
table.newsBox td.right { width: 18; height: auto }
table.newsBox td.bottomLeft { width: 22px; height: 12px }
table.newsBox td.bottomLeft2 { width: 58px; height: 12px }
table.newsBox td.bottom { width: 500px; height: 12px }
table.newsBox td.bottomRight { width: 18px; height: 12px }
table.newsBox td.titleBack { width: auto; height: 18px }
table.newsBox caption { caption-side: bottom; text-align: right }
table.newsBox td h1 { font: 5pt Verdana; font-weight: bold; color: #ffcc00 }
table.newsBox td div.newsTitle { width: 400; height: 30; font-weight: bold; color: #ffcc00; font-size: 12px Verdana }

.topLeft { background: url(itemdb/Ability_Druid_ManaTree.png) no-repeat top left }
.topBlank { background: url(images/spacer.gif) repeat }
.topTop { background: url(images/top-top.jpg) repeat-x }
.topBottom { background: url(images/top-bottom.jpg) repeat-x }
.topRight { background: url(images/top-right.jpg) no-repeat top right }
.left { background: url(images/left.jpg) repeat-y }
/* .left2 { background: url(images/bg3.jpg) repeat } */
.left2 { background-color: #292828 }
.right { background: url(images/right.jpg) repeat-y }
.bottomLeft { background: url(images/bot-left.jpg) no-repeat bottom left }
.bottomLeft2 { background: url(images/bot.jpg) repeat bottom }
.bottom { background: url(images/bot.jpg) repeat-x }
.bottomRight { background: url(images/bot-right.jpg) no-repeat bottom right }
.titleBack { background: url(images/bg2.jpg) repeat-x; }
/* .boxContent { background: url(images/bg3.jpg) repeat } */
.boxContent { background-color: #292828 }
.boxContent p { font-family: Verdana, Arial, Helvetica, sans-serif; font: 10px; color: #6f6e6e; margin-left: 15px; margin-right: 15px; }
.boxContent p.comment { float: right }

 

 

Now all this code works by itself, as I tested it before I started adding the php code.  Honestly that's the only problem I can think of.

Link to comment
Share on other sites

include("config.php");

 

That's how I open the connection to the server, and it works.  That line you quoted simply selects the database that the table is in.  Obviously the ********* are replaced with the name of the database.

 

 

I should also point out if I remove all the tables etc etc, and just use

echo $row["title"];

it works just fine.  It's only when I try and make the table.

Link to comment
Share on other sites

Doesn't display anything, not even the Connected.

 

On the other hand if I replace all the table code with just:

 

	
while ($row = mysql_fetch_array($result)) {
echo $row["title"];
        echo $row["id"];
}

 

 

the script works perfectly. The problem comes when I start trying to place the information inside of a table using a CSS file.

Link to comment
Share on other sites

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>A useless website designed by Deathwillow</title>
<link href="news.css" rel="stylesheet" type="text/css">
    <link href="main.css" rel="stylesheet" type="text/css">
    <script src="http://www.wowhead.com/widgets/power.js"></script>
    <script type="text/javascript" src="jquery.js"/><!-- kicks so much ass --></script>

</head>

<body>
<center>
<table height="100%" class="main" cellpadding="0" cellspacing="0">
<tr>
    	<td class="mainLeft" rowspan="3"></td>
        <td class="mainCenter"></td>
        <td class="mainRight" rowspan="3"></td>
    </tr>
    <tr>

        <td class="mainLinks">
        	<div class="linkBarsTop"></div>
            <div class="linkBarsBottom"></div>
        </td>
    </tr>
    <tr>
    	<td class="mainContent" valign="top" align="center">

 

Right where i have the include it goes blank =/

Link to comment
Share on other sites

strange nothing there which should kill it without displaying anything.

 

but thats where it is dying.

 

could you try replacing that line with:

 

mysql_connect("CORRECT SERVER", "USERNAME", "PASSWORD") or die("it died here");

 

just because im curious if it is dying there.

Link to comment
Share on other sites

acctually found a few more like that,

 

and meant 19 not 9

 

so line 18, 19, and 25 are all missing the closing ;

 

haha yea I caught the other one once you posted the first 2... a noob mistake by a noob programmer! :)

 

thanks for your persistent help on the matter, it's much appreciated.  The table with the correct information's appearing now, it's just making it look pretty now.

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.