lauren_etherington Posted November 15, 2013 Share Posted November 15, 2013 (edited) Hello. I am having some trouble and I'm not sure if its my code or logic haha. Basically, my company has commissoned a website for one of our clients and used an outside developer to actually build the site. Now the initial development is complete I have been put in charge of the support and maintenance of the site. However the client has now decided they would like to decide the position of an image on the news pages. To display a news article, they enter the information in a form, which is saved in the database, this is then recalled through a php script when a user clicks 'read more' on the website. I have added a set of radio buttons to the form where the client can select if the image is Right, Left of Centre. When they save the form this information is saved in the database. I then want to create a script that will open the 'newsitem' 'newsitem2' or 'newsitem3' page depending on the value of the radio button. This is the code I am using: function top10news($s, $t, $u, $w) { $con = mysqli_connect("ip", "host", "password", "databasename"); 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") { <p class='newsmore'> <a href='newsitem.php?i=" . $tnrow['niid'] . "'>Read More</a></p> } else { $radio= "SELECT imageposition FROM newsimage"; if ($radio == 'Centre') { <p class='newsmore'> <a href='newsitem3.php?i=" . $tnrow['niid'] . "'>Read More</a></p> } if ($radio == 'Right') { <p class='newsmore'> <a href='newsitem2.php?i=" . $tnrow['niid'] . "'>Read More</a></p> } if ($radio == 'Left') { <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); } The problem I am facing is when I then go to load the news page. Nothing loads on the webpage. but if I remove this bit of code, it works fine: if ("" . $tnrow['newsimage'] . "" == "none") { <p class='newsmore'> <a href='newsitem.php?i=" . $tnrow['niid'] . "'>Read More</a></p> } else { $radio= "SELECT imageposition FROM newsimage"; if ($radio == 'Centre') { <p class='newsmore'> <a href='newsitem3.php?i=" . $tnrow['niid'] . "'>Read More</a></p> } if ($radio == 'Right') { <p class='newsmore'> <a href='newsitem2.php?i=" . $tnrow['niid'] . "'>Read More</a></p> } if ($radio == 'Left') { <p class='newsmore'> <a href='newsitem.php?i=" . $tnrow['niid'] . "'>Read More</a></p> } Can anyone see where I am going wrong? I have spent that long looking at it I just can't see where I am wrong!! Any help would be vastly appreciated! Edited November 15, 2013 by lauren_etherington Quote Link to comment https://forums.phpfreaks.com/topic/283922-needing-code-help/ Share on other sites More sharing options...
lauren_etherington Posted November 15, 2013 Author Share Posted November 15, 2013 (edited) I can't have anymore edits: I have changed the radio query from $radio= "SELECT imageposition FROM newsimage"; to $radio= mysqli_query("SELECT DISTINCT imageposition FROM newsimage")"; And the only error message I seem to get when I debug the file is this: Parse error: syntax error, unexpected '<' in C:\Users\pathway.php on line 32 Edited November 15, 2013 by lauren_etherington Quote Link to comment https://forums.phpfreaks.com/topic/283922-needing-code-help/#findComment-1458370 Share on other sites More sharing options...
Solution Barand Posted November 15, 2013 Solution Share Posted November 15, 2013 Where you have something like (several places) <p class='newsmore'> <a href='newsitem.php?i=" . $tnrow['niid'] . "'>Read More</a></p> you need echo "<p class='newsmore'> <a href='newsitem.php?i=" . $tnrow['niid'] . "'>Read More</a></p>"; There is a major problem with your "radio" query. All you have so far is a string containing the query to be executed. You need to run the query using $result = mysqli_query($con, $radio); then fetch the data returned with mysqli_fetch_assoc Trouble is the query as it is will fetch all rows in the table. Are you storing image positions for each item? If so so you need to specify which item you want using a WHERE clause in the query then Quote Link to comment https://forums.phpfreaks.com/topic/283922-needing-code-help/#findComment-1458383 Share on other sites More sharing options...
lauren_etherington Posted November 15, 2013 Author Share Posted November 15, 2013 (edited) I'm using radio buttons for the image position whereby the client selects the radio button to position the image - the radio button value is then stored in the database on a news image table which links into the actual newsitems table. For the WHERE clause that would be a case of stating where the newsitem id is equal to news image id wouldn't it? That would then return the image position where the news item id is equal to x? Edited November 15, 2013 by lauren_etherington Quote Link to comment https://forums.phpfreaks.com/topic/283922-needing-code-help/#findComment-1458385 Share on other sites More sharing options...
Barand Posted November 15, 2013 Share Posted November 15, 2013 For the WHERE clause that would be a case of stating where the newsitem id is equal to news image id wouldn't it? That would then return the image position where the news item id is equal to x? Yes. Quote Link to comment https://forums.phpfreaks.com/topic/283922-needing-code-help/#findComment-1458393 Share on other sites More sharing options...
lauren_etherington Posted November 15, 2013 Author Share Posted November 15, 2013 Thank you, I've been at a loss all day, think I had been looking at it for too long so I just couldn't see where I had gone wrong! Quote Link to comment https://forums.phpfreaks.com/topic/283922-needing-code-help/#findComment-1458394 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.