[PHP-DB] PHP MySQL news display probs

2003-07-15 Thread phpuser
Dear All,

I have created a simple news system and am having a problem in that all the code 
compiles so I think it is correct and the news headlines display but when you point to 
the link to read the article (for example http://localhost/news/user/story.php?id=2) 
nothing displays, it returns that there is nothing in the database and prints out the 
arm of the else statement, no records.

I am convinced that I need to enable something somewhere in the php.ini file but may 
be wrong. Any help would be really really appreciated.

This is the code which displays the news headlines which displays them OK:

html
head
basefont face=Verdana
/head

body

!-- standard page header begins --
pnbsp;p

table width=100% cellspacing=0 cellpadding=5
tr
td/td
/tr
tr
td bgcolor=Navyfont size=-1 color=WhitebReuters Inc : Press 
Releases/b/font/td
/tr
/table
!-- standard page header ends --

ul
?
// includes
include(../conf.php);
include(../functions.php);

// open database connection
$connection = mysql_connect($host, $user, $pass) or die (Unable to connect!);

// select database
mysql_select_db($db) or die (Unable to select database!);

// generate and execute query
$query = SELECT id, slug, timestamp FROM news ORDER BY timestamp DESC LIMIT 0, 5;
$result = mysql_query($query) or die (Error in query: $query.  . mysql_error());

// if records present
if (mysql_num_rows($result)  0)
{
// iterate through resultset
// print article titles
while($row = mysql_fetch_object($result))
{
?
lifont size=-1ba href=story.php?id=? echo $row-id; ?? 
echo $row-slug; ?/a/b/font
br
font size=-2? echo formatDate($row-timestamp); ?/font
p
?
}
}
// if no records present
// display message
else
{
?
font size=-1No press releases currently available/font
?
}

// close database connection
mysql_close($connection);
?
/ul

!-- standard page footer begins --
p
table width=100% cellspacing=0 cellpadding=5
tr
td align=centerfont size=-2Everything here is copyright copy; 
/tr
/table
!-- standard page footer ends --


/body
/html

This is the code to Display the corresponding article, its driving me nuts!

/ story.php - display contents of selected press release
?
html
head
basefont face=Verdana
/head

body

!-- standard page header begins --
pnbsp;p

table width=100% cellspacing=0 cellpadding=5
tr
td/td
/tr
tr
td bgcolor=Navyfont size=-1 color=WhitebReuters Inc : Press 
Releases/b/font/td
/tr
/table
!-- standard page header ends --

?
// includes
include(../conf.php);
include(../functions.php);

// open database connection
$connection = mysql_connect($host, $user, $pass) or die (Unable to connect!);

// select database
mysql_select_db($db) or die (Unable to select database!);

// generate and execute query
$query = SELECT slug, content, contact, timestamp FROM news WHERE id = '$id';
$result = mysql_query($query) or die (Error in query: $query.  . mysql_error());

// get resultset as object
$row = mysql_fetch_object($result);

// print details
if ($row)
{
?
p
b? echo $row-slug; ?/b
p
font size=-1? echo nl2br($row-content); ?/font
p
font size=-2This press release was published on ? echo 
formatDate($row-timestamp); ?. For more information, please contact ? echo 
$row-contact; ?/font
?
}
else
{
?
p
font size=-1That press release could not be located in our database./font
?
}

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

!-- standard page footer begins --
p
table width=100% cellspacing=0 cellpadding=5
tr
td align=centerfont size=-2Everything here is copyright copy; /tr
/table
!-- standard page footer ends --

/body
/html

Thanks Again
PHPUSER


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] PHP MySQL news display probs

2003-07-15 Thread CPT John W. Holmes
 I have created a simple news system and am having a
 problem in that all the code compiles so I think it is
 correct and the news headlines display but when you
 point to the link to read the article (for example
 http://localhost/news/user/story.php?id=2) nothing
 displays, it returns that there is nothing in the database
 and prints out the arm of the else statement, no records.

So what's the value of $id on the story.php page? What's the value of
$_GET['id']? Print out your query before you execute it to make sure it
looks right. Do some debugging and read about register globals (if my
assumption is correct).

---John Holmes...



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] PHP MySQL news display probs

2003-07-15 Thread jeffrey_n_Dyke

you'll need to use $_GET['id'] or you'll need to set register_globals = On.

I would use the first method, and replace

$query = SELECT slug, content, contact, timestamp FROM news WHERE id
= '$id';
with --
$query = SELECT slug, content, contact, timestamp FROM news WHERE id = '.
$_GET['id'].';

i bet it will work straight away.

hth
Jeff


   
 
  [EMAIL PROTECTED]
 
  on.co.uk To:   [EMAIL PROTECTED] 
  
   cc: 
 
  07/15/2003 10:44 Subject:  [PHP-DB] PHP MySQL news 
display probs  
  AM   
 
   
 
   
 




Dear All,

I have created a simple news system and am having a problem in that all the
code compiles so I think it is correct and the news headlines display but
when you point to the link to read the article (for example
http://localhost/news/user/story.php?id=2) nothing displays, it returns
that there is nothing in the database and prints out the arm of the else
statement, no records.

I am convinced that I need to enable something somewhere in the php.ini
file but may be wrong. Any help would be really really appreciated.

This is the code which displays the news headlines which displays them OK:

html
head
basefont face=Verdana
/head

body

!-- standard page header begins --
pnbsp;p

table width=100% cellspacing=0 cellpadding=5
tr
 td/td
/tr
tr
 td bgcolor=Navyfont size=-1 color=WhitebReuters Inc : Press
Releases/b/font/td
/tr
/table
!-- standard page header ends --

ul
?
// includes
include(../conf.php);
include(../functions.php);

// open database connection
$connection = mysql_connect($host, $user, $pass) or die (Unable to
connect!);

// select database
mysql_select_db($db) or die (Unable to select database!);

// generate and execute query
$query = SELECT id, slug, timestamp FROM news ORDER BY timestamp DESC
LIMIT 0, 5;
$result = mysql_query($query) or die (Error in query: $query.  .
mysql_error());

// if records present
if (mysql_num_rows($result)  0)
{
 // iterate through resultset
 // print article titles
 while($row = mysql_fetch_object($result))
 {
 ?
  lifont size=-1ba href=story.php?id=? echo $row-id; ??
  echo $row-slug; ?/a/b/font
  br
  font size=-2? echo formatDate($row-timestamp); ?/font
  p
 ?
 }
}
// if no records present
// display message
else
{
?
 font size=-1No press releases currently available/font
?
}

// close database connection
mysql_close($connection);
?
/ul

!-- standard page footer begins --
p
table width=100% cellspacing=0 cellpadding=5
tr
 td align=centerfont size=-2Everything here is copyright copy;
/tr
/table
!-- standard page footer ends --


/body
/html

This is the code to Display the corresponding article, its driving me nuts!

/ story.php - display contents of selected press release
?
html
head
basefont face=Verdana
/head

body

!-- standard page header begins --
pnbsp;p

table width=100% cellspacing=0 cellpadding=5
tr
 td/td
/tr
tr
 td bgcolor=Navyfont size=-1 color=WhitebReuters Inc : Press
Releases/b/font/td
/tr
/table
!-- standard page header ends --

?
// includes
include(../conf.php);
include(../functions.php);

// open database connection
$connection = mysql_connect($host, $user, $pass) or die (Unable to
connect!);

// select database
mysql_select_db($db) or die (Unable to select database!);

// generate and execute query
$query = SELECT slug, content, contact, timestamp FROM news WHERE id
= '$id';
$result = mysql_query($query) or die (Error in query: $query.  .
mysql_error());

// get resultset as object
$row = mysql_fetch_object($result);

// print details
if ($row)
{
?
 p
 b? echo $row-slug; ?/b
 p
 font size=-1? echo nl2br($row-content); ?/font
 p
 font size=-2This press release was published on ? echo formatDate
 ($row-timestamp); ?. For more information, please contact ? echo
 $row-contact; ?/font
?
}
else
{
?
 p
 font size=-1That press release could not be located in our
 database./font
?
}

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

!-- standard page footer begins --
p
table width=100% cellspacing=0 cellpadding=5
tr
 td align=centerfont size=-2Everything here is copyright copy;
/tr
/table
!-- standard page footer