Hey,
I'm trying to make a list with all the news i have and when you click on the news everything abotu it would come up.
I know it has to do something with id but not sure how I would make all of them clickable links?
Thanks
View news by clicking it
Moderator: General Moderators
- aerodromoi
- Forum Contributor
- Posts: 230
- Joined: Sun May 07, 2006 5:21 am
Re: View news by clicking it
You'll have to let us in on whether you're using a mysql database or a flatfile and what kind of script you are using.NiGHTFiRE wrote:Hey,
I'm trying to make a list with all the news i have and when you click on the news everything abotu it would come up.
I know it has to do something with id but not sure how I would make all of them clickable links?
Thanks
For example, you could explode a string, telling the script to echo only the first ten words of each entry if the $_GET variable specifying an entry is not set.
aerodromoi
I'm using a mysql database and now i got this code:
I know it's really messy cause i've added stuff later on when i've tryed fixing it.
It doesn't give me ant information at all now. the site: http://wmegn.mine.nu/nyheter/nyheter.php
How would i solve this?
Thanks
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Visa alla nyheter</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
include("connect.php");
$query = "SELECT * FROM nyheter";
$r = mysql_query($query);
echo "<FORM METHOD='post' action='nyheter.php'>";
echo "<SELECT NAME='nyheter'>";
while($rad5 = mysql_fetch_array($r)){
echo "<option value=\"{$rad5[nyhetid]}\">{$rad5[rubrik]}</option>";
}
echo "<INPUT TYPE='submit' name='FaNyheter' value='Få Fram nyheten'";
echo "</SELECT>";
echo "</FORM>";
$sql = "SELECT COUNT(nyhetid) FROM nyheter";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result);
$result2 = mysql_query("SELECT * FROM nyheter WHERE nyhetid='$rad5[nyhetid]'");
$rad3 = mysql_fetch_array($result2);
$antalrader = mysql_result($result, 0);
if($_POST['LaggKommentar']) {
$kommentarsql = "INSERT INTO kommentar (nyhetid, kommentnamn, kommentmsg) VALUES ('$rad5[nyhetid]', '$_POST[kommentnamn]', '$_POST[kommentmsg]')";
$kommentarresultat = mysql_query($kommentarsql) or die(mysql_error());
}
if (mysql_result ($result , 0) <= 0)
{
echo '<b>Finns inga nyheter ännu!</b>';
}
if($_POST['FaNyheter']) {
$result = mysql_query("SELECT * FROM nyheter WHERE nyhetid='$rad5[nyhetid]'");
for ($x = 0; $x < mysql_num_rows($result); $x++)
{
$rad = mysql_fetch_array($result);
echo '<table>';
echo ' <tr>';
echo '<td>';
echo '<b>Författare:</b>';
echo '</td>';
echo '<td>';
echo "$rad[forfattare]";
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td>';
echo '<b>Rubrik:</b>';
echo '</td>';
echo '<td>';
echo "$rad[rubrik]";
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td valign="top">';
echo '<b>Meddelande:</b>';
echo '</td>';
echo '<td>';
echo "$rad[msg]";
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td>';
echo '</td>';
echo '</tr>';
echo '</table>';
}
}
echo '<br>';
echo '<br>';
echo '<br>';
$br2 = "<br>";
//echo 'Lägg till kommentar: ';
//echo "<form method='post' action='nyheter.php'>";
//echo "Namn: <input type='text' name='kommentnamn' size=20>";
//echo "<br>";
//echo "Meddelande: ".$br2."<textarea name='kommentmsg' cols='50' rows='8'></textarea>";
//echo "$br2";
//echo "<input type='submit' name='LaggKommentar' value='Skicka Kommentar'>";
//echo "</form>";
echo '<font size=3>Kommentarer:</font>';
$komment = mysql_query("SELECT * FROM kommentar WHERE nyhetid=$rad5[nyhetid] ORDER BY kommentid DESC");
for ($C = 0; $C < mysql_num_rows($komment); $C++)
{
$rad2 = mysql_fetch_array($komment);
$br = "<br>";
echo '<FONT SIZE=2>';
echo '<table>';
echo ' <tr>';
echo '<td>';
echo '<b>Namn:</b>';
echo '</td>';
echo '<td>';
echo "$rad2[kommentnamn]";
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td>';
echo '<b>Datum:</b>';
echo '</td>';
echo '<td>';
echo "$rad2[tid]";
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td valign="top">';
echo '<b>Meddelande:</b>';
echo '</td>';
echo '<td>';
echo "$rad2[kommentmsg]";
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td>';
echo '</td>';
echo '</tr>';
echo '</table>';
}
?>
</body>
</html>It doesn't give me ant information at all now. the site: http://wmegn.mine.nu/nyheter/nyheter.php
How would i solve this?
Thanks
- aerodromoi
- Forum Contributor
- Posts: 230
- Joined: Sun May 07, 2006 5:21 am
Here's a snippet to show you how to shorten a string. After ten words, "..." is added.
As to your code - it certainly looks a bit messy. Personally, I would strip it down to just one functionality - which would be reading the entries. You can add html tags and the script to post comments later on. One more thought - you don't seem to check your input. I'd recommend using at least htmlentities - but watch out for ENT_QUOTES / magic quotes.
aerodromoi
Code: Select all
<?php
$newsstring = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus auctor lorem eu quam. Phasellus ac turpis. Proin sollicitudin, ligula id bibendum ultrices, magna nisi imperdiet urna, eu feugiat pede elit id neque. Phasellus vulputate tempus erat. Morbi auctor hendrerit sem.";
$newsarray = explode(" ",$newsstring);
$numberofwords = 10;
for ($i=0;$i<$numberofwords;$i++){
if ($i != $numberofwords-1) echo $newsarray[$i]." ";
else{ echo "...<br />\n";}
}
?>aerodromoi