Jump to content

White screen.


lauren_etherington
Go to solution Solved by Barand,

Recommended Posts

Hello,

I am trying to write a bit of code that will open a different page url depending on whether the value in my 'newsimage' table is set to left, right or centre.

 

There is a news page which contains a list of news snippets and when you click 'read more' it should direct to one of three pages depending on where the 'image' should sit. The PHP is in a seperate file to the news page. This is the code that should display the news snippets.

<div id="sectionright">
        	<div class="sectionhead">
            	<h2 class="sect editable" id="h2top">Media</h2>
            </div>
            <div class="padder18"></div>

            <?php
				newsform();
				top10news($s,$t,$u,$w);
			?>

        </div>

This is the code in the seperate PHP file that displays the content.

function top10news($s, $t, $u, $w)
{
    $con = mysqli_connect("ip", "server", "password", "database name");
    if (mysqli_connect_errno($con)) {
        echo "<p class='sect'>Could not connect to DB</p>";
        // echo "<p class='sect'>Could not connect to DB " . mysqli_connect_error() . "</p>";
    } else {
        // echo "<p class='sect'>Connected to DB</p>";
        $q = "SELECT DISTINCT newsitem.niid,newstitle,newssnippet,sitename,newsimage FROM newsitem,newsbusiness WHERE newsitem.niid=newsbusiness.niid AND newsstatus='enabled' ";
        if ("$u" == "Any") {
        } else {
            $q = $q . "AND sitename='$u' ";
        }
        if ("$s" == "Any") {
        } else {
            $parts = explode('-', $s);
            $y = $parts[0];
            $m = $parts[1];
            $q = $q . "AND YEAR(newsdate) = $y AND MONTH(newsdate) = $m ";
        }
        $q = $q . "ORDER BY newsdate DESC LIMIT 0,10";
        // echo "<p class='news'>$s</p>";
        // echo "<p class='news'>$q</p>";
        $result = mysqli_query($con, $q);
        while ($tnrow = mysqli_fetch_array($result)) {
            echo "
				<div class='newssummary'>";

            if ("" . $tnrow['newsimage'] . "" == "none") {
                echo <p class = 'newsmore' > < a href = 'newsitem.php?i=" . $tnrow['niid'] . "' > Read More</a > </p>;

            }else

                $radio = mysqli_query("SELECT imageposition FROM newsimage WHERE imageposition EQUALS newsitem.niid=newsimage.niid");
            $qresult = mysqli_query($con, $radio);

            while (($tnrow = mysqli_fetch_array($qresult)); {
                    if ($radio == 'Centre') {
                        echo "<p class='newsmore'> <a href='newsitem3.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
                    }else if ($radio == 'Right') {
                        echo "<p class='newsmore'> <a href='newsitem2.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
                    }else if ($radio == 'Left') {
                        echo "<p class='newsmore'> <a href='newsitem.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
                    }
                }

                echo "<div class='newspic'><img src='http://www.nortech.org.uk/news/" . $tnrow['newsimage'] . "' alt='" . $tnrow['newstitle'] . "' /></div>";
            }
            echo "
						<p><strong>" . $tnrow['newstitle'] . "</strong></p>
	        			<p class='news'>" . $tnrow['newssnippet'] . "</p>
   				</div>
				<div class='padder1'></div>
    			<div class='rtgreengp'></div>
			";
        }
    }

    mysqli_close($con);
}

My problem is that whenever I load the page it just produces a blank page.

When I look at the source code on the web all that is displayed is "<!doctype html>"

 

However, when I remove the second query from the file and re-upload it, it all works fine, so from what I can gather there is a problem some where in this bit of code:


            }else

                $radio = mysqli_query("SELECT imageposition FROM newsimage WHERE imageposition EQUALS newsitem.niid=newsimage.niid");
            $qresult = mysqli_query($con, $radio);

            while (($tnrow = mysqli_fetch_array($qresult)); {
                    if ($radio == 'Centre') {
                        echo "<p class='newsmore'> <a href='newsitem3.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
                    }else if ($radio == 'Right') {
                        echo "<p class='newsmore'> <a href='newsitem2.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
                    }else if ($radio == 'Left') {
                        echo "<p class='newsmore'> <a href='newsitem.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
                    }
                }

                echo "<div class='newspic'><img src='http://www.nortech.org.uk/news/" . $tnrow['newsimage'] . "' alt='" . $tnrow['newstitle'] . "' /></div>";
            }
            echo "
						<p><strong>" . $tnrow['newstitle'] . "</strong></p>
	        			<p class='news'>" . $tnrow['newssnippet'] . "</p>
   				</div>
				<div class='padder1'></div>
    			<div class='rtgreengp'></div>
			";
        }
    }

    mysqli_close($con);
}

I just can't see why it isn't working....

Whenever I run the debugger I am only receiving this error message "Parse error: syntax error, unexpected '<' in C:\pathway\filename.php on line 32" which isn't really useful because when I look at line 32 there are no added '<'

 

Advice would be much appreciated before I start tearing my hair out lol!

 

 

 

Link to comment
Share on other sites

In your while loop your conditionals are referring to $radio, the name of your query result. I believe you wish to use $tnrow instead.

 

Edit: You are using mysql_query on $radio with $radio already using mysql_query. Change $qresult to $radio in your while loop or unquery $radio.

Edited by SocialCloud
Link to comment
Share on other sites


<?php
// Show latest 10 news items
function top10news($s, $t, $u, $w)
{
$con = mysqli_connect("connection to database");
if (mysqli_connect_errno($con)) {
echo "<p class='sect'>Could not connect to DB</p>";

} else {
// echo "<p class='sect'>Connected to DB</p>";
$q = "SELECT DISTINCT newsitem.niid,newstitle,newssnippet,sitename,newsimage FROM newsitem,newsbusiness WHERE newsitem.niid=newsbusiness.niid AND newsstatus='enabled' ";
if ("$u" == "Any") {
} else {
$q = $q . "AND sitename='$u' ";
}
if ("$s" == "Any") {
} else {
$parts = explode('-', $s);
$y = $parts[0];
$m = $parts[1];
$q = $q . "AND YEAR(newsdate) = $y AND MONTH(newsdate) = $m ";
}
$q = $q . "ORDER BY newsdate DESC LIMIT 0,10";

$result = mysqli_query($con, $q);
while ($tnrow = mysqli_fetch_array($result)) {
echo "
<div class='newssummary'>";

if ("" . $tnrow['newsimage'] . "" == "none") {
echo <p class = 'newsmore' > < a href = 'newsitem.php?i=" . $tnrow['niid'] . "' > Read More</a > </p>;

}else

$radio = mysqli_query("SELECT imageposition FROM newsimage WHERE imageposition EQUALS newsitem.niid=newsimage.niid");
$radio = mysqli_query($con, $radio);

while (($tnrow = mysqli_fetch_array($radio)); {
if ($tnrow == 'Centre') {
echo "<p class='newsmore'> <a href='newsitem3.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
}else if ($tnrow == 'Right') {
echo "<p class='newsmore'> <a href='newsitem2.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
}else if ($tnrow == 'Left') {
echo "<p class='newsmore'> <a href='newsitem.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
}
}

echo "<div class='newspic'><img src='http://www.nortech.org.uk/news/" . $tnrow['newsimage'] . "' alt='" . $tnrow['newstitle'] . "' /></div>";
}
echo "
<p><strong>" . $tnrow['newstitle'] . "</strong></p>
<p class='news'>" . $tnrow['newssnippet'] . "</p>
</div>
<div class='padder1'></div>
<div class='rtgreengp'></div>
";
}
}

mysqli_close($con);
}
Link to comment
Share on other sites

                $radio = mysqli_query("SELECT imageposition FROM newsimage WHERE imageposition EQUALS newsitem.niid=newsimage.niid");
            $radio = mysqli_query($con, $radio);
You're still double querying here. One without the connection variable.

            while (($tnrow = mysqli_fetch_array($radio)); {
                    if ($tnrow == 'Centre') {
                        echo "<p class='newsmore'> <a href='newsitem3.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
                    }else if ($tnrow == 'Right') {
                        echo "<p class='newsmore'> <a href='newsitem2.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
                    }else if ($tnrow == 'Left') {
                        echo "<p class='newsmore'> <a href='newsitem.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
                    }
                }
$tnrow will hold an array. You can't match an array to a string, you have to use which row of $tnrow

 

As for your unexpected < error, your echo isn't using any quotes on that line

Edited by SocialCloud
Link to comment
Share on other sites

So many errors! Your query to get the image position had syntax errors. I have incorporated it as a join in your main query. You should not run queries inside loops.

 

I think this may be closer to what you want

function top10news($s, $t, $u, $w)
{
    $con = mysqli_connect("connection to database");
    if (mysqli_connect_errno($con)) {
        echo "<p class='sect'>Could not connect to DB</p>";
     
    } else {
        $q = "SELECT DISTINCT newsitem.niid,newstitle,newssnippet,sitename,newsimage,imageposition 
        FROM newsitem
            INNER JOIN newsbusiness ON newsitem.niid=newsbusiness.niid
            LEFT JOIN newsimage ON newsitem.niid=newsimage.niid
        WHERE newsstatus='enabled' ";
        if ("$u" == "Any") {
        } else {
            $q = $q . "AND sitename='$u' ";
        }
        if ("$s" == "Any") {
        } else {
            $parts = explode('-', $s);
            $y = $parts[0];
            $m = $parts[1];
            $q = $q . "AND YEAR(newsdate) = $y AND MONTH(newsdate) = $m ";
        }
        $q = $q . "ORDER BY newsdate DESC LIMIT 0,10";
       
        $result = mysqli_query($con, $q);
        while ($tnrow = mysqli_fetch_array($result)) {
            echo "
                <div class='newssummary'>";

            if ("" . $tnrow['newsimage'] . "" == "none") {
                echo "<p class = 'newsmore' > < a href = 'newsitem.php?i=" . $tnrow['niid'] . "' > Read More</a > </p>";

            }else {

                    if ($tnrow['imageposition'] == 'Centre') {
                        echo "<p class='newsmore'> <a href='newsitem3.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
                    }else if ($tnrow['imageposition'] == 'Right') {
                        echo "<p class='newsmore'> <a href='newsitem2.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
                    }else if ($tnrow['imageposition'] == 'Left') {
                        echo "<p class='newsmore'> <a href='newsitem.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
                    }

                echo "<div class='newspic'><img src='http://www.nortech.org.uk/news/" . $tnrow['newsimage'] . "' alt='" . $tnrow['newstitle'] . "' /></div>";
            }
            echo "
                        <p><strong>" . $tnrow['newstitle'] . "</strong></p>
                        <p class='news'>" . $tnrow['newssnippet'] . "</p>
                          </div>
                     <div class='padder1'></div>
                     <div class='rtgreengp'></div>
                     ";
        }
    }
}
Link to comment
Share on other sites

 

So many errors! Your query to get the image position had syntax errors. I have incorporated it as a join in your main query. You should not run queries inside loops.

 

I think this may be closer to what you want

function top10news($s, $t, $u, $w)
{
    $con = mysqli_connect("connection to database");
    if (mysqli_connect_errno($con)) {
        echo "<p class='sect'>Could not connect to DB</p>";
     
    } else {
        $q = "SELECT DISTINCT newsitem.niid,newstitle,newssnippet,sitename,newsimage,imageposition 
        FROM newsitem
            INNER JOIN newsbusiness ON newsitem.niid=newsbusiness.niid
            LEFT JOIN newsimage ON newsitem.niid=newsimage.niid
        WHERE newsstatus='enabled' ";
        if ("$u" == "Any") {
        } else {
            $q = $q . "AND sitename='$u' ";
        }
        if ("$s" == "Any") {
        } else {
            $parts = explode('-', $s);
            $y = $parts[0];
            $m = $parts[1];
            $q = $q . "AND YEAR(newsdate) = $y AND MONTH(newsdate) = $m ";
        }
        $q = $q . "ORDER BY newsdate DESC LIMIT 0,10";
       
        $result = mysqli_query($con, $q);
        while ($tnrow = mysqli_fetch_array($result)) {
            echo "
                <div class='newssummary'>";

            if ("" . $tnrow['newsimage'] . "" == "none") {
                echo "<p class = 'newsmore' > < a href = 'newsitem.php?i=" . $tnrow['niid'] . "' > Read More</a > </p>";

            }else {

                    if ($tnrow['imageposition'] == 'Centre') {
                        echo "<p class='newsmore'> <a href='newsitem3.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
                    }else if ($tnrow['imageposition'] == 'Right') {
                        echo "<p class='newsmore'> <a href='newsitem2.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
                    }else if ($tnrow['imageposition'] == 'Left') {
                        echo "<p class='newsmore'> <a href='newsitem.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
                    }

                echo "<div class='newspic'><img src='http://www.nortech.org.uk/news/" . $tnrow['newsimage'] . "' alt='" . $tnrow['newstitle'] . "' /></div>";
            }
            echo "
                        <p><strong>" . $tnrow['newstitle'] . "</strong></p>
                        <p class='news'>" . $tnrow['newssnippet'] . "</p>
                          </div>
                     <div class='padder1'></div>
                     <div class='rtgreengp'></div>
                     ";
        }
    }
}

I've modified my own code with your suggestions and while there is a vast improvement the page still isn't displaying quite right and it is no longer displaying the newest 10 news items. At least it's displaying something though and that is progress! thanks lol.

 

This is the updated code:

{
	session_start();
    $con = mysqli_connect("79.170.44.78", "web78-nor586t31", "tech1758N56", "web78-nor586t31");
    if (mysqli_connect_errno($con)) {
        echo "<p class='sect'>Could not connect to DB</p>";
      
    } else {
     
        $q = "SELECT DISTINCT newsitem.niid,newstitle,newssnippet,sitename,newsimage FROM newsitem,newsbusiness
        	  INNER JOIN newsbusiness ON newsitem.niid=newsbusiness.niid
              LEFT JOIN newsimage ON newsitem.niid=newsimage.niid
        	  WHERE newsitem.niid=newsbusiness.niid AND newsstatus='enabled' ";
        if ("$u" == "Any") {
        } else {
            $q = $q . "AND sitename='$u' ";
        }
        if ("$s" == "Any") {
        } else {
            $parts = explode('-', $s);
            $y = $parts[0];
            $m = $parts[1];
            $q = $q . "AND YEAR(newsdate) = $y AND MONTH(newsdate) = $m ";
        }
        $q = $q . "ORDER BY newsdate DESC LIMIT 0,10";
   
        $result = mysqli_query($con, $q);
        while ($tnrow = mysqli_fetch_array($result)) {
            echo "
				<div class='newssummary'>";

            if ("" . $tnrow ['newsimage'] . "" == "none") {
                echo "<p class = 'newsmore' > < a href = 'newsitem.php?i=" . $tnrow['niid'] . "' > Read More</a > </p>";

            }else

                if ($tnrow ['imageposition'] == 'Centre') {
                        echo "<p class='newsmore'> <a href='newsitem3.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
                    }else if ($tnrow ['imageposition'] == 'Right') {
                        echo "<p class='newsmore'> <a href='newsitem2.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
                    }else if ($tnrow ['imageposition'] == 'Left') {
                        echo "<p class='newsmore'> <a href='newsitem.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
                    }
                }

                echo "<div class='newspic'><img src='http://www.nortech.org.uk/news/" . $tnrow['newsimage'] . "' alt='" . $tnrow['newstitle'] . "' /></div>";
            }
            echo "
						<p><strong>" . $tnrow['newstitle'] . "</strong></p>
	        			<p class='news'>" . $tnrow['newssnippet'] . "</p>
	   			  	 </div>
					 <div class='padder1'></div>
	    			 <div class='rtgreengp'></div>
				";
        }
   
    mysqli_close($con);

When I run the debugger it seems to think that $con is not defined and producing this warning.

Warning: mysqli_close() expects parameter 1 to be mysqli, null given in C:\Users\lauren.etherington\Documents\Projects\test\Group\public_html\news\news_fns.php on line 59

 

Could this be the reason I'm having this new problem?

Edited by lauren_etherington
Link to comment
Share on other sites

Found some misplaced {}s

 

Try

function top10news($s, $t, $u, $w)
{
    session_start();
    $con = mysqli_connect("**********", "*************", "***************", "************");
    if (mysqli_connect_errno($con)) {
        echo "<p class='sect'>Could not connect to DB</p>";
    } else {
        $q = "SELECT DISTINCT newsitem.niid,newstitle,newssnippet,sitename,newsimage FROM newsitem,newsbusiness
        INNER JOIN newsbusiness ON newsitem.niid=newsbusiness.niid
        LEFT JOIN newsimage ON newsitem.niid=newsimage.niid
        WHERE newsitem.niid=newsbusiness.niid AND newsstatus='enabled' ";
        if ($u != "Any") {
            $q = $q . "AND sitename='$u' ";
        }
        if ($s =! "Any") {
            $parts = explode('-', $s);
            $y = $parts[0];
            $m = $parts[1];
            $q = $q . "AND YEAR(newsdate) = $y AND MONTH(newsdate) = $m ";
        }
        $q = $q . "ORDER BY newsdate DESC LIMIT 0,10";
        $result = mysqli_query($con, $q);
        while ($tnrow = mysqli_fetch_array($result)) {
            echo "
            <div class='newssummary'>";
             
            if ("" . $tnrow ['newsimage'] . "" == "none") {
                echo "<p class = 'newsmore' > < a href = 'newsitem.php?i=" . $tnrow['niid'] . "' > Read More</a > </p>";
            }
            else if ($tnrow ['imageposition'] == 'Centre') {
                echo "<p class='newsmore'> <a href='newsitem3.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
            }
            else if ($tnrow ['imageposition'] == 'Right') {
                echo "<p class='newsmore'> <a href='newsitem2.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
            }
            else if ($tnrow ['imageposition'] == 'Left') {
                echo "<p class='newsmore'> <a href='newsitem.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
            }
             
            echo "<div class='newspic'><img src='http://www.nortech.org.uk/news/" . $tnrow['newsimage'] . "' alt='" . $tnrow['newstitle'] . "' /></div>";
            echo "
            <p><strong>" . $tnrow['newstitle'] . "</strong></p>
            <p class='news'>" . $tnrow['newssnippet'] . "</p>
            </div>
            <div class='padder1'></div>
            <div class='rtgreengp'></div>
            ";
        }
    
        mysqli_close($con);
    }
}
Link to comment
Share on other sites

Cheers, I've gone through and sorted the {} out so all the formatting is now working. It just not displaying. Its a small piece of php code in the html file.

 <?php
	newsform();
	top10news($s,$t,$u,$w);
?>

it should display the php function - Just wondering  if anything is missing in the PHP  that would stop it from displaying? since the 'newsform()' function displays fine.......

{
	$con = mysqli_connect("**********************************");
    if (mysqli_connect_errno($con)) {
        echo "<p class='sect'>Could not connect to DB</p>";

    } else {

        $q = "SELECT DISTINCT newsitem.niid,newstitle,newssnippet,sitename,newsimage FROM newsitem,newsbusiness
        	  INNER JOIN newsbusiness ON newsitem.niid=newsbusiness.niid
              LEFT JOIN newsimage ON newsitem.niid=newsimage.niid
        	  WHERE newsitem.niid=newsbusiness.niid AND newsstatus='enabled' ";

        if ("$u" == "Any") {

        } else {

            $q = $q . "AND sitename='$u' ";

        }

        if ("$s" == "Any") {

        } else {

            $parts = explode('-', $s);
            $y = $parts[0];
            $m = $parts[1];
            $q = $q . "AND YEAR(newsdate) = $y AND MONTH(newsdate) = $m ";

        }

        $q = $q . "ORDER BY newsdate DESC LIMIT 0,10";

        $result = mysqli_query($con, $q);

        while ($tnrow = mysqli_fetch_array($result)) {

            echo "

				<div class='newssummary'>";


            if ("" . $tnrow ['newsimage']  AND  $tnrow ['imageposition'] . ""== "none") {

                echo "<p class = 'newsmore' > < a href = 'newsitem.php?i=" . $tnrow['niid'] . "' > Read More</a > </p>";

         }
			
			else if ($tnrow ['imageposition'] == 'Centre') {

                        echo "<p class='newsmore'> <a href='newsitem3.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";

      	 }
			else if ($tnrow ['imageposition'] == 'Right') {

                        echo "<p class='newsmore'> <a href='newsitem2.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";

         }
			else if ($tnrow ['imageposition'] == 'Left') {

                        echo "<p class='newsmore'> <a href='newsitem.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";

        }
			


                echo "<div class='newspic'><img src='http://www.nortech.org.uk/news/" . $tnrow['newsimage'] . "' alt='" . $tnrow['newstitle'] . "' /></div>";
            
           		echo "
						<p><strong>" . $tnrow['newstitle'] . "</strong></p>
	        			<p class='news'>" . $tnrow['newssnippet'] . "</p>
	   			  	    </div>
					    <div class='padder1'></div>
	    			    <div class='rtgreengp'></div>";

        }

    
    }
	
	mysqli_close($con);
}

From what I can see there are now no missing ;'s or {}'s  and quotation marks seem to be all in place.

Link to comment
Share on other sites

You have moved the mysqli_close() back outside the else{..} block after I put it inside for you.

 

If the connection fails then now you will get an error that $con is not a mysqli resource again.

 

I cannot see anything obvious, other you are not checking if the query ran OK, but I cannot test it as I cannot see any of your data or the values of your variables. Any debugging, therefore, will have to be done by you.

Link to comment
Share on other sites

A table dump should look like this example

DROP TABLE IF EXISTS `clubvisit`;
CREATE TABLE `clubvisit` (
  `day_id` int(11) NOT NULL AUTO_INCREMENT,
  `dues` int(11) DEFAULT NULL,
  `last_visit` datetime DEFAULT NULL,
  `points` int(11) DEFAULT NULL,
  PRIMARY KEY (`day_id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;

--
-- Dumping data for table `clubvisit`
--

INSERT INTO `clubvisit` VALUES 
(1,900,'2012-12-01 20:00:00',6),
(2,700,'2012-12-04 17:00:00',7),
(3,600,'2012-12-07 10:00:00',4),
(4,600,'2012-12-09 21:00:00',6),
(5,600,'2012-12-10 15:00:00',6),
(6,600,'2012-12-14 17:00:00',6),
(7,500,'2012-12-10 20:00:00',5),
(8,500,'2012-12-14 19:30:00',5);

so it can be executed to create the table and load the data.

 

Whatever gui front end you are using for your database admin (PHPMyAdmin, MySQL Workbench etc) should have a facility to create table dumps

Edited by Barand
Link to comment
Share on other sites

Why did you change my query from

$q = "SELECT DISTINCT newsitem.niid,newstitle,newssnippet,sitename,newsimage,imageposition
FROM newsitem
INNER JOIN newsbusiness ON newsitem.niid=newsbusiness.niid
LEFT JOIN newsimage ON newsitem.niid=newsimage.niid
WHERE newsstatus='enabled' ";

back to

$q = "SELECT DISTINCT newsitem.niid,newstitle,newssnippet,sitename,newsimage FROM newsitem,newsbusiness
     INNER JOIN newsbusiness ON newsitem.niid=newsbusiness.niid
LEFT JOIN newsimage ON newsitem.niid=newsimage.niid
     WHERE newsitem.niid=newsbusiness.niid AND newsstatus='enabled' ";

What is the point of me giving you the code then you rewriting it wrongly?

 

I give up!

Link to comment
Share on other sites

  • Solution

This version worked with the test data that I set up.

 

The ONLY THING you should need to change are the mysql_connect() credentials.

function top10news($s, $t, $u, $w)
{
    session_start();
    $con = mysqli_connect("**********", "*************", "***************", "************");

    if (mysqli_connect_errno($con)) {
        echo "<p class='sect'>Could not connect to DB</p>";
    } else {
        $q = "SELECT DISTINCT newsitem.niid,newstitle,newssnippet,sitename,newsimage,imageposition 
        FROM newsitem
        INNER JOIN newsbusiness ON newsitem.niid=newsbusiness.niid
        LEFT JOIN newsimage ON newsitem.niid=newsimage.niid
        WHERE newsitem.niid=newsbusiness.niid AND newsstatus='enabled' ";
        if ($u != "Any") {
            $q = $q . "AND sitename='$u' ";
        }
        if ($s != "Any") {
            $parts = explode('-', $s);
            $y = $parts[0];
            $m = $parts[1];
            $q = $q . "AND YEAR(newsdate) = $y AND MONTH(newsdate) = $m ";
        }
        $q = $q . "ORDER BY newsdate DESC LIMIT 0,10";

        $result = mysqli_query($con, $q);
        while ($tnrow = mysqli_fetch_array($result)) {
            echo "
            <div class='newssummary'>";
             
            if ("" . $tnrow ['newsimage'] . "" == "none") {
                echo "<p class = 'newsmore' > <a href = 'newsitem.php?i=" . $tnrow['niid'] . "' > Read More</a > </p>";
            }
            else if ($tnrow ['imageposition'] == 'Centre') {
                echo "<p class='newsmore'> <a href='newsitem3.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
            }
            else if ($tnrow ['imageposition'] == 'Right') {
                echo "<p class='newsmore'> <a href='newsitem2.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
            }
            else if ($tnrow ['imageposition'] == 'Left') {
                echo "<p class='newsmore'> <a href='newsitem.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
            }
             
            echo "<div class='newspic'><img src='http://www.nortech.org.uk/news/" . $tnrow['newsimage'] . "' alt='" . $tnrow['newstitle'] . "' /></div>";
            echo "
            <p><strong>" . $tnrow['newstitle'] . "</strong></p>
            <p class='news'>" . $tnrow['newssnippet'] . "</p>
            </div>
            <div class='padder1'></div>
            <div class='rtgreengp'></div>
            ";
        }
    
        mysqli_close($con);
    }
}


Edited by Barand
Link to comment
Share on other sites

 

This version worked with the test data that I set up.

 

The ONLY THING you should need to change are the mysql_connect() credentials.

function top10news($s, $t, $u, $w)
{
    session_start();
    $con = mysqli_connect("**********", "*************", "***************", "************");

    if (mysqli_connect_errno($con)) {
        echo "<p class='sect'>Could not connect to DB</p>";
    } else {
        $q = "SELECT DISTINCT newsitem.niid,newstitle,newssnippet,sitename,newsimage,imageposition 
        FROM newsitem
        INNER JOIN newsbusiness ON newsitem.niid=newsbusiness.niid
        LEFT JOIN newsimage ON newsitem.niid=newsimage.niid
        WHERE newsitem.niid=newsbusiness.niid AND newsstatus='enabled' ";
        if ($u != "Any") {
            $q = $q . "AND sitename='$u' ";
        }
        if ($s != "Any") {
            $parts = explode('-', $s);
            $y = $parts[0];
            $m = $parts[1];
            $q = $q . "AND YEAR(newsdate) = $y AND MONTH(newsdate) = $m ";
        }
        $q = $q . "ORDER BY newsdate DESC LIMIT 0,10";

        $result = mysqli_query($con, $q);
        while ($tnrow = mysqli_fetch_array($result)) {
            echo "
            <div class='newssummary'>";
             
            if ("" . $tnrow ['newsimage'] . "" == "none") {
                echo "<p class = 'newsmore' > <a href = 'newsitem.php?i=" . $tnrow['niid'] . "' > Read More</a > </p>";
            }
            else if ($tnrow ['imageposition'] == 'Centre') {
                echo "<p class='newsmore'> <a href='newsitem3.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
            }
            else if ($tnrow ['imageposition'] == 'Right') {
                echo "<p class='newsmore'> <a href='newsitem2.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
            }
            else if ($tnrow ['imageposition'] == 'Left') {
                echo "<p class='newsmore'> <a href='newsitem.php?i=" . $tnrow['niid'] . "'>Read More</a></p>";
            }
             
            echo "<div class='newspic'><img src='http://www.nortech.org.uk/news/" . $tnrow['newsimage'] . "' alt='" . $tnrow['newstitle'] . "' /></div>";
            echo "
            <p><strong>" . $tnrow['newstitle'] . "</strong></p>
            <p class='news'>" . $tnrow['newssnippet'] . "</p>
            </div>
            <div class='padder1'></div>
            <div class='rtgreengp'></div>
            ";
        }
    
        mysqli_close($con);
    }
}


You are actually a star.

 

Thank you!!!!!

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.