PDA

View Full Version : I need a PHP Guru to take a look at this - part 2


Dimava
Sat 8th Jun '02, 5:12pm
<?php
// Important! You have to include it before your html code
include_once "/home/virtual/site3/fst/var/www/html/poll/poll_cookie.php";
?>

<html>
<head>
<title>NXNews</title>
</head>

<?php include("templates/header.htm"); ?>
<?php

require("admins/config.php");
$link = mysql_pconnect( "localhost", $user, $pass );
mysql_select_db( $db, $link );


include("templates/news/newslist_start.php");

if ( $article == "" ) {
include("templates/news/newslist.php");

$result = mysql_query("SELECT * FROM news ORDER BY date DESC, id DESC");
while ( $row = mysql_fetch_array($result) AND list ( $id, $name, $date ) = $row) {
$newdate2 = chunk_split($date, 2, '.');
$newdate = substr($newdate2, 0, strlen($newdate2)-1);
include("templates/news/newslist_item.php");
}
include("templates/news/newslist_end.php");
}

if ( $article != "") {
$result = mysql_query("SELECT description,username,name,date,source,image FROM news WHERE id=$article");
if(!@mysql_num_rows($result)){

include("templates/news/error.php");
}
else {

//$row = mysql_fetch_array($result) AND list ( $id,$title,$date,$username,$description,$source,$i mage ) = $row;
list($description,$username,$title,$olddate,$sourc e,$image) = mysql_fetch_row($result);
$newdate2 = chunk_split($olddate, 2, '.');
$date = substr($newdate2, 0, strlen($newdate2)-1);

include("templates/news/news.php");
}
}


mysql_close($link);
include("templates/footer.htm");

?>
</body>
</html>


error:
Warning: Supplied argument is not a valid MySQL result resource in /home/virtual/site3/fst/var/www/html/articles.php on line 25

Sorry firefly, your code didn't seem to work

-Dimava

Raz Meister
Tue 18th Jun '02, 8:09am
Try changingwhile ( $row = mysql_fetch_array($result) AND list ( $id, $name, $date ) = $row) {
$newdate2 = chunk_split($date, 2, '.');
towhile ( $row = mysql_fetch_array($result)) {
list ( $id, $name, $date ) = $row
$newdate2 = chunk_split($date, 2, '.');
Also make sure that no other script you are including is making queries to the database. Other wise you will need to supply each mysql statment with the relavent link.

But I have to say that is a VERY ineffienct script! Think about making it more database oriented and reduce the amount of files you are 'include'ing.

scoutt
Wed 19th Jun '02, 7:05pm
this is the error, you can't have 2 DESC

$result = mysql_query("SELECT * FROM news ORDER BY date DESC, id DESC");

Dimava
Wed 19th Jun '02, 7:21pm
yes you can, i got it to work

scoutt
Wed 19th Jun '02, 10:00pm
surprising, do it this way though.

$result = mysql_query("SELECT * FROM news ORDER BY date, id DESC");