Jump to content

[SOLVED] help in retriving records from db


ROCKINDANO

Recommended Posts

Hello,

 

I am working on a project, of a listing of all events. the problem is when i insert the tenth record onto the table, the news_id link doesn't point to the tenth record. it points to the first record in the table. any help please

 

this is my code for the page that list all events (events.php)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>events</title>
</head>
<body class="newsrelease">
<div id="cmain_wrapper">
<?php include ('header.php');?>
  </div>
    <div class="padding">
      <div id="cmain_content">
<p style="padding-bottom:0"><font style="font-family: Arial, Helvetica, sans-serif; color:#0066CC; font-size:18px">City Headlines</font></p>
        <?php
			if(!($db = @ mysql_connect('localhost', 'username', 'pass')))
			{
				echo 'Error: Could not connect to our database sorry for any inconvience.<br /> Please try at a later time.';
				exit;
			}
			//select which database you want to edit
			mysql_select_db("dbhere"); 

			$news_id = $_GET["news_id"];

			if(!isset($news_id))
					{						
						$query = "SELECT * FROM news ORDER BY news_id DESC";
						$result = mysql_query($query);

						//goes through all records in database and retrieves the need ones.
						while($r=mysql_fetch_array($result))
						{	
					   //the format is $variable = $r["nameofmysqlcolumn"];
					   		$news_id=$r["news_id"];
					   
					   //displays all info only first three
					   		print "<p><b style='color:#9F0000'>".$title=$r["title"]."</b><br />";
					   		print $description=$r["description"];
					  		print "&#38;#8230; <br /><a href='newsevents.php?news_id={$news_id['news_id']}'>read more »</a></p>";
							print $news_id;
						}//end while loop

				  }//end if
					else{
			$news_id = $_GET["news_id"];

			$query="SELECT * FROM news WHERE news_id='$news_id'";
			$result = mysql_query($query); 

			//putting all fiels into array to display them.
			          print "<table width='200' border='0'>
					  <tr><td><form method='get' action='newsevents.php'><input type='submit' value='News Archives' />
					  </form></td></tr></table><br /><br />";

			while($r=mysql_fetch_array($result))
			{
			   //the format is $variable = $r["nameofmysqlcolumn"];
			   //modify these to match your mysql table columns
			   $title=$r["title"];			   
			   $fulldesc=$r["fulldesc"];
			   $news_id=$r["news_id"];
			   
			   
			   print  "<p style=\"padding-bottom: 0\"><b style='color:#9F0000'>".$title."</b><br />";
			   print $fulldesc."</p>";
			   print $news_id;
		   
			}
			}
?>
     <br /><br /> </div>
      <div id="cleft_bar">
	<?php include ('links.php');?>
      </div>
    </div>
<?php include('footer.php');?></div>
</body>
</html>

 

thanks in advance

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.