Jump to content

needing code help!


lauren_etherington
Go to solution Solved by Barand,

Recommended Posts

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 by lauren_etherington
Link to comment
Share on other sites

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 by lauren_etherington
Link to comment
Share on other sites

  • Solution

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

Link to comment
Share on other sites

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 by lauren_etherington
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.