This bit of code:

<div class="left">
			<h3>Fresh News:</h3>
			<?php fresh_news();?>
			<div class="left_box">
				<img class="image" alt="Big Image" src ="images/bigimage.gif" >
				<h2><?php print"$newtitle";?></h2>
				<p><?php print"$newdesc";?></p>
				<p>Added: <?php print"$newdate";?></p>
			</div>

Produces this error:

Warning: mysql_result(): Unable to jump to row 1 on MySQL result index 5 in /home/trecollc/public_html/test/functions.php on line 17

Warning: mysql_result(): Unable to jump to row 1 on MySQL result index 5 in /home/trecollc/public_html/test/functions.php on line 18

Warning: mysql_result(): Unable to jump to row 1 on MySQL result index 5 in /home/trecollc/public_html/test/functions.php on line 19

This is the freshnews function:

function fresh_news() {
$query = "SELECT * FROM news";
$result = mysql_query($query);
$i = mysql_numrows($result);
$newdate  = mysql_result($result,$i,"date");
$newtitle = mysql_result($result,$i,"title");
$newdesc  = mysql_result($result,$i,"description");
}

Why do i get this error? There is definately a record as i use mysql_numrows but for some reason it wont display it

TIA
RT

    For starters, mysql_numrows() is deprecated and should be replaced with mysql_num_rows(). Next, what you have is an out of bounds error. If mysql_num_rows() returns 1, that means you have one row in the result set. But this is row number 0, not row number 1, hence mysql_result($result,$i,"date") leads to an out of bounds error.

    The solution I propose is to use [man]mysql_fetch_assoc/man, then assign:

    function fresh_news() {
    	$query = "SELECT * FROM news";
    	$result = mysql_query($query);
    	$row = mysql_fetch_assoc($result);
    	$newdate  = $row["date"];
    	$newtitle = $row["title"];
    	$newdesc  = $row["description"];
    }

    That said, you have another problem - these variables are declared local to the function. One way out would be to return the $row array.

      Ok, now further down my page

      This:

      <div class="right">
      			<h3>Latest Completed Projects:</h3>
      			<div class="right_articles">
      <p><img class="image" title="Image" alt="Image" src="<?php completed_proj(4)?>"><b><?php completed_proj(1);?></b></p>
      <p><?php completed_proj(2);?></p>
      <p><a href="<?php completed_proj(3);?>">Visit Website</a></p>
      <p>This was a <?php completed_proj(5);?> project</p>
      			</div>
      

      Produces this:

      Warning: mysql_result(): type not found in MySQL result index 12 in /home/trecollc/public_html/test/functions.php on line 25
      
      
      Warning: mysql_result(): type not found in MySQL result index 13 in /home/trecollc/public_html/test/functions.php on line 25
      An upcoming events calendar using MySQL. 1st beta version released
      
      Visit Website
      
      This was a
      Warning: mysql_result(): type not found in MySQL result index 15 in /home/trecollc/public_html/test/functions.php on line 25
      project
      

      using this:

      
      function completed_proj($w) {
      $query = "SELECT * FROM projects";
      $result = mysql_query($query);
      $n = mysql_num_rows($result);
      $i = ($n-1);
      $t = mysql_result($result,$i,"title");
      $d = mysql_result($result,$i,"description");
      $u = mysql_result($result,$i,"url");
      $i = mysql_result($result,$i,"img");
      $t = mysql_result($result,$i,"type");
      IF ($w == "1"){print "$t";}
      IF ($w == "2"){print "$d";}
      IF ($w == "3"){print "$u";}
      IF ($w == "4"){print "$i";}
      IF ($w == "5"){print "$t";}
      }
      

      TIA
      RT

        Seriously, you need to write code that is more maintainable. Using magic numbers is a bad way to go about it, as is indiscriminately using single character variable names.

        One thing you can do is:

        function completed_proj($field) {
        	$query = "SELECT $field FROM projects";
        	$result = mysql_query($query);
        	print mysql_result($field, 0);
        }

        If you insist on magic numbers, write:

        function completed_proj($w) {
        	static $fields = array("title", "description", "url", "img", "type");
        	if ($w > 0 && $w <= count($fields)) {
        		$query = "SELECT $fields[$w] FROM projects";
        		$result = mysql_query($query);
        		print mysql_result($field, 0);
        	}
        }

          thank you,

          Trying to loose habits whilst still young

            Write a Reply...