lauren_etherington Posted November 21, 2013 Share Posted November 21, 2013 (edited) I have been developing some code that will allow my client to chose whether she wants to put an image left, right or centred on her news page. The code is working brilliantly and allows her to do so (thanks to this forum!) However - the news title is displaying twice on the page. Once as an image and once as text........ I removed 'newsimage' from the sql query however it is still displaying the title as an image even though it is no longer looking for the image? Completely confused as to why it has started doing this. Heres the code: // Show latest 10 news items function top10news($s, $t, $u, $w) { session_start(); $con = mysqli_connect("*****************", "*****************", "*****************", "*****************"); if (mysqli_connect_errno($con)) { echo "<p class='sect'>Could not connect to the database</p>"; } else { $q = "SELECT DISTINCT newsitem.niid,newstitle,newssnippet,sitename,newsimage 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 ['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); } } It seems to display correctly if I upload an image along with an article..... so from what I can see if there is no image uploaded, it is just replacing it with the news title? if that makes any sense....... Any advice out there? Edited November 21, 2013 by lauren_etherington Quote Link to comment https://forums.phpfreaks.com/topic/284129-text-displaying-as-an-image-and-text/ Share on other sites More sharing options...
lauren_etherington Posted November 21, 2013 Author Share Posted November 21, 2013 Edit: I have updated the query slightly so it now reads: $q = "SELECT DISTINCT newsitem.niid,newstitle,newssnippet,sitename,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' "; so the 'newsimage' does not display on the news page but when you click 'read more' it does display alongside the news article. However, it is still displaying the news title as both text and as an image...... help? Quote Link to comment https://forums.phpfreaks.com/topic/284129-text-displaying-as-an-image-and-text/#findComment-1459333 Share on other sites More sharing options...
Solution Ch0cu3r Posted November 21, 2013 Solution Share Posted November 21, 2013 It seems to display correctly if I upload an image along with an article..... so from what I can see if there is no image uploaded, it is just replacing it with the news title? if that makes any sense....... If no image has been uploaded then what you'll see is the alt text ( alt='" . $tnrow['newstitle'] . "'). What want to be doing is only output the html code for the image if the news item has one. You'll want to change echo "<div class='newspic'><img src='http://www.nortech.org.uk/news/" . $tnrow['newsimage'] . "' alt='" . $tnrow['newstitle'] . "' /></div>"; to if(!empty($tnrow['newsimage'])) { echo "<div class='newspic'><img src='http://www.nortech.org.uk/news/" . $tnrow['newsimage'] . "' alt='" . $tnrow['newstitle'] . "' /></div>"; } Quote Link to comment https://forums.phpfreaks.com/topic/284129-text-displaying-as-an-image-and-text/#findComment-1459338 Share on other sites More sharing options...
lauren_etherington Posted November 21, 2013 Author Share Posted November 21, 2013 worked an absolute treat Cheers. Quote Link to comment https://forums.phpfreaks.com/topic/284129-text-displaying-as-an-image-and-text/#findComment-1459340 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.