Web Hosting Talk







View Full Version : Why wont this work?????


Gamenati
04-15-2003, 08:43 PM
im haveing trouble querying data, but the weird thing is, it works on another page.

the page im having trouble w/ is http://www.gamenationx.com/news/full_story.php?story=1

here is the code:


<html>

<?php
function date_str($timestamp) {
$date_str = getdate($timestamp) ;
$year = $date_str["year"] ;
$mon = $date_str["mon"] ;
$mday = $date_str["mday"] ;
$hours = $date_str["hours"] ;
$minutes = $date_str["minutes"] ;
$seconds = $date_str["seconds"] ;

return "$mon/$mday/$year" ;
}
$color = "663333" ;
$name = "Full Story" ;
?>

<head>
<style>
body{font-family:verdana;}
font.scnd{font-family: sherwood;}
a{text-decoration:none}

a:link.first {color:888888; }
a:link.scnd {color:<?php echo $color ?>; }

a:visited.first {color:888888; }
a:visited.scnd {color:<?php echo $color ?>; }

a:hover.first{color:<?php echo $color ?>;}
a:hover.scnd{color:000000;}

BODY {
scrollbar-face-color: <?php echo $color ?>;
scrollbar-track-color: #444444;
scrollbar-shadow-color: #000000;
scrollbar-highlight-color: #000000;
scrollbar-3dlight-color: #000000;
scrollbar-darkshadow-color: #000000;
scrollbar-arrow-color: #cccccc;
}

</style>
<title><?php echo $name ?></title>
<base href="http://www.gamenationx.com/">
</head>

<body bgcolor="888888">
<div align="center">
<table width="840" style="border: 0px solid #000000" cellpadding="0" cellspacing="0">
<?php include("http://www.gamenationx.com/top_left.php"); ?>
<td width="20">
&nbsp;
</td>
<td width="500" valign="top"><br>
<?php
$link_id = mysql_connect ("localhost", "gamenat_admin", "rmb1990") ;
mysql_select_db ("gamenat_everything");

$sql = "SELECT newsid,date,date2,intro,title,poster,body FROM gnxnews";
$query = mysql_query($sql);

echo "<table width='500' cellspacing='0' cellpadding='0' style='border: 1px solid #000000'>" ;
echo "<tr><td style=\"border-bottom: 1px solid #000000\" bgcolor='" . $color . "' width='500'><font class='scnd' color='888888'>" . $query_data[title] . "&nbsp;</font></td></tr>" ;

while ($query_data = mysql_fetch_array($query)) {
$timestamp = $query_data[date2] ;
$timestamp = date_str($timestamp) ;
echo "<tr><td style=\"border-bottom: 1px solid #000000\" width='500'>" . $query_data[body] . "</td></tr>" ;
}

echo "<tr><td align='right' style=\"border-bottom: 1px solid #000000\" bgcolor='" . $color . "' width='400'><font class='scnd' color='888888'>posted by: " . $query_data[poster] . "</font></td></tr>" ;
echo "</table><br><br>" ;
?>
</td>
<td width="20">
&nbsp;
</td>
<td width="150" valign="top">
<?php include("http://www.gamenationx.com/right.php"); ?>
</td>
</tr>
<tr>
<?php include("http://www.gamenationx.com/bottom.php"); ?>
</tr>
</table>
</div>
</body>
</html>



in the top red bar should be the title, and in the bottom bar should be the poster
oddy, the body of the news querys fine


BTW, the
$query_data[title]
$query_data[poster]

are the querys that arent working

Tux-e-do
04-15-2003, 08:55 PM
you should place your array keys in quotes.

like this

$query_data['body']

Gamenati
04-15-2003, 09:01 PM
it still doesent work

Tux-e-do
04-15-2003, 09:40 PM
Yeah I know.

The reason it wont work is because you are trying to access the data array before its filled.

you need to place them in the while loop or put your $query_data = mysql_fetch_array($query) before them

Tux-e-do
04-15-2003, 09:42 PM
Originally posted by Gamenati
it still doesent work

The reason I told you to place your array keys in quotes is because they are defined as constants othrwise, PHP converts these to strings but this may change in the future.