im working on something that will display the title and the author, but i have seperate table for the title and author, my code displays the title but not the author, what should i do? heres my code

<html>
<body>
<form method=post action="find.php"> 

<h2>Search For:</h2> 
<p> 
Academic Year : <input type=text name=search size=9 maxlength=9> 
<p> 
<input type=submit name=submit value=List>
<input type=reset name=clear value=cancel> 
</form>
</body>
</html>

<?php

 if(isset($_POST['submit']))

{

include 'conn.php';

$search=$_POST['search'];
$sy=explode('-',$search);


$result = mysql_query ("SELECT * FROM `tbl_upload` WHERE (`year` >= $sy[0] AND `year` <= $sy[1])");


                echo '<h2>Result</h2>';

                if ($row = mysql_fetch_array($result)) 
                    { 
                        do{

                              echo "<b>Title:</b>"; 
                              echo '<a href="">'.$row["title"].'</a>'; 
                              echo "<br>";

                            $result2 = mysql_query ("SELECT * FROM `tbl_author`");
                            if ($row2 = mysql_fetch_array($result2)) 
                                
                                        
                                        echo "<b>Author:</b>"; 
                                          echo $row2["author"]; 
                                          echo "<p>";
                                

                           }
                    while($row = mysql_fetch_array($result)); 
                    } 
                else 
                    {
                        echo 'Sorry, no records were found!';
                    }   

}

?>

Recommended Answers

All 5 Replies

Try below code.
But why r u fetching all data from tbl_author table?
There should be some mapping between tbl_upload and tbl_author.

<html>
<body>
<form method=post action="find.php">
	<h2>Search For:</h2>
	<p> Academic Year :
		<input type=text name=search size=9 maxlength=9>
	<p>
		<input type=submit name=submit value=List>
		<input type=reset name=clear value=cancel>
</form>
</body>
</html>
<?php

if(isset($_POST['submit']))
{
	include 'conn.php';
	
	$search=$_POST['search'];
	$sy=explode('-',$search);
	
	
	$result = mysql_query ("SELECT * FROM `tbl_upload` WHERE (`year` >= $sy[0] AND `year` <= $sy[1])");
	echo '<h2>Result</h2>';
	if (mysql_num_rows($result) > 0) 
	{ 
		while($row = mysql_fetch_array($result))
		{
	
			  echo "<b>Title:</b>"; 
			  echo '<a href="">'.$row["title"].'</a>'; 
			  echo "<br>";
	
			  $result2 = mysql_query ("SELECT * FROM `tbl_author`");
			  if ($row2 = mysql_fetch_array($result2)) 
			  {
			  		echo "<b>Author:</b>"; 
					echo $row2["author"]; 
					echo "<p>";
			  }
		}						
	} 
	else 
	{
		echo 'Sorry, no records were found!';
	}   

}

?>

mapping? how is that?

i mean my fields in tbl_upload is id,title,date,image and in my tbl_author is just id and author. just try your code but it also did the same, no author is displayed

mapping means relation.
e.g.
tbl_upload => id,title,date,image, author_id
tbl_author => id, author

Here author_id from tbl_upload is foreign key from tbl_author's id.

Even above code should display authors.
check SELECT * FROM `tbl_author` query with phpmyadmin. Is table have any records?

i check it and it has records of author, but cant really display the authors name

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.