0

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!';
                    }   

}

?>
2
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by slap01
0

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!';
	}   

}

?>
0

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

0

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?

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.