lauren_etherington Posted November 18, 2013 Share Posted November 18, 2013 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! Quote Link to comment https://forums.phpfreaks.com/topic/284014-white-screen/ Share on other sites More sharing options...
MDCode Posted November 18, 2013 Share Posted November 18, 2013 (edited) 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 November 18, 2013 by SocialCloud Quote Link to comment https://forums.phpfreaks.com/topic/284014-white-screen/#findComment-1458755 Share on other sites More sharing options...
lauren_etherington Posted November 18, 2013 Author Share Posted November 18, 2013 Thank you for the help but it is still displaying a white screen when the page loads..... Quote Link to comment https://forums.phpfreaks.com/topic/284014-white-screen/#findComment-1458757 Share on other sites More sharing options...
MDCode Posted November 18, 2013 Share Posted November 18, 2013 Updated code? Quote Link to comment https://forums.phpfreaks.com/topic/284014-white-screen/#findComment-1458759 Share on other sites More sharing options...
lauren_etherington Posted November 18, 2013 Author Share Posted November 18, 2013 <?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); } Quote Link to comment https://forums.phpfreaks.com/topic/284014-white-screen/#findComment-1458760 Share on other sites More sharing options...
MDCode Posted November 18, 2013 Share Posted November 18, 2013 (edited) $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 November 18, 2013 by SocialCloud Quote Link to comment https://forums.phpfreaks.com/topic/284014-white-screen/#findComment-1458763 Share on other sites More sharing options...
lauren_etherington Posted November 18, 2013 Author Share Posted November 18, 2013 It was those missing quotes that was causing the white screen. Completely different error now but thankfully it's actually displaying something now!!! Quote Link to comment https://forums.phpfreaks.com/topic/284014-white-screen/#findComment-1458764 Share on other sites More sharing options...
Barand Posted November 18, 2013 Share Posted November 18, 2013 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> "; } } } Quote Link to comment https://forums.phpfreaks.com/topic/284014-white-screen/#findComment-1458768 Share on other sites More sharing options...
lauren_etherington Posted November 18, 2013 Author Share Posted November 18, 2013 (edited) 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 November 18, 2013 by lauren_etherington Quote Link to comment https://forums.phpfreaks.com/topic/284014-white-screen/#findComment-1458771 Share on other sites More sharing options...
Barand Posted November 18, 2013 Share Posted November 18, 2013 I'm looking at your code. Meanwhile, change your password now that you've published it! Quote Link to comment https://forums.phpfreaks.com/topic/284014-white-screen/#findComment-1458778 Share on other sites More sharing options...
lauren_etherington Posted November 18, 2013 Author Share Posted November 18, 2013 Oh dear..... I am in such a stress I completely forgot to erase that :S Thank you for pointing that out! Quote Link to comment https://forums.phpfreaks.com/topic/284014-white-screen/#findComment-1458779 Share on other sites More sharing options...
Barand Posted November 18, 2013 Share Posted November 18, 2013 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); } } Quote Link to comment https://forums.phpfreaks.com/topic/284014-white-screen/#findComment-1458785 Share on other sites More sharing options...
lauren_etherington Posted November 18, 2013 Author Share Posted November 18, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/284014-white-screen/#findComment-1458808 Share on other sites More sharing options...
Barand Posted November 18, 2013 Share Posted November 18, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/284014-white-screen/#findComment-1458815 Share on other sites More sharing options...
lauren_etherington Posted November 18, 2013 Author Share Posted November 18, 2013 I'm not getting anything from the debugger. Thank you for the help though! Quote Link to comment https://forums.phpfreaks.com/topic/284014-white-screen/#findComment-1458817 Share on other sites More sharing options...
Barand Posted November 18, 2013 Share Posted November 18, 2013 Can you provide a dump of the three relevant tables? Quote Link to comment https://forums.phpfreaks.com/topic/284014-white-screen/#findComment-1458818 Share on other sites More sharing options...
lauren_etherington Posted November 18, 2013 Author Share Posted November 18, 2013 Screendumps are attached below Quote Link to comment https://forums.phpfreaks.com/topic/284014-white-screen/#findComment-1458823 Share on other sites More sharing options...
Barand Posted November 18, 2013 Share Posted November 18, 2013 Have you tried loading an image of data into a database so you can test a query. It doesn't work too well Quote Link to comment https://forums.phpfreaks.com/topic/284014-white-screen/#findComment-1458824 Share on other sites More sharing options...
lauren_etherington Posted November 18, 2013 Author Share Posted November 18, 2013 (edited) Sorry. It's been a long day! Edited November 18, 2013 by lauren_etherington Quote Link to comment https://forums.phpfreaks.com/topic/284014-white-screen/#findComment-1458828 Share on other sites More sharing options...
Barand Posted November 18, 2013 Share Posted November 18, 2013 (edited) 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 November 18, 2013 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/284014-white-screen/#findComment-1458830 Share on other sites More sharing options...
Barand Posted November 18, 2013 Share Posted November 18, 2013 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! Quote Link to comment https://forums.phpfreaks.com/topic/284014-white-screen/#findComment-1458841 Share on other sites More sharing options...
Solution Barand Posted November 18, 2013 Solution Share Posted November 18, 2013 (edited) 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 November 18, 2013 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/284014-white-screen/#findComment-1458865 Share on other sites More sharing options...
lauren_etherington Posted November 19, 2013 Author Share Posted November 19, 2013 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!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/284014-white-screen/#findComment-1458941 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.