Search-showing information........help pls

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Search-showing information........help pls

Post by crazytopu »

I have a file named query.php that look likes as follows:

Code: Select all

<?php
<html>
<head><title></title></head>


<body>


<?php
if (isset($_POST['Search'])) { 

http://localhost/search.php

}



<form method="post" action="search.php"> 

<table border="0" width="75%"> 

<td width="15%">
      <p align="right">Call No:</p>
    </td> 
    <td width="57%"><input type="text" name="call_no" size="20"></td> 

</td> 
    <td width="57%"> 

 <input type="submit" value="Search" name="Search">

</body>
</html>


?>

The other file that i have created to process the query is search.php which is looks like:

Code: Select all

<?php


<?php 

$db = mysql_connect("localhost", "root"); 
mysql_select_db("library",$db) or die(mysql_error()); 
$sql = "Select FROM book WHERE call_no=('{$_POST['call_no']}')";

$result = mysql_query($sql); 

?> 


<table border=2> 
  <tr> 
    <td>call_no</td> 
    <td>title</td> 
    <td>author1</td> 
    <td>author2</td> 
    <td>publisher</td> 
    <td>isbn</td> 
    <td>price</td> 
    <td>no_of_page</td> 
    <td>edition</td> 
    <td>category</td> 
  </tr> 
<?php 
while ($myrow = mysql_fetch_row($result)) 
{ 
   echo '<tr>'; 
   for($i=0; $i<10; $i++) 
   { 
      echo '<td>'.$myrow[$i].'</td>'; 
   } 
   echo '</tr>'; 
} 
?> 

</table> 


?>


Can i call a php file like this from the if block?:

Code: Select all

<?php
http://localhost/search.php


?>
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Code: Select all

<?php
if (isset($_POST['Search'])) {

http://localhost/search.php

}
I'm wondering why you're not getting a parse error doing that =\

-Nay
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Post by crazytopu »

Yes ofcourse it does give me a parse error. I got the following error:

Code: Select all

<?php

Parse error: parse error, unexpected ':' in g:\program files\apache group\apache\htdocs\query.php on line 11



?>
And i got stucked in fixing the error. Can you simply tell me what to do in this kinds of case?

Do you think it's a good way to leave the display part onto another php file [here on search.php]? What if i use the same file to display the data [query.php]?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Try using something similiar to:

Code: Select all

if (isset($_POST['Search'])) {
    include 'search.php';
}
...to insert the search script.
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Post by crazytopu »

:lol: i didnot have to include the call.

Code: Select all

<?php
<form method="post" action="search.php"> 

?>
this code is doing the work just fine. I excluded search.php call.


It's all good as far as I am doing the search by only callno. But what if someone wants to search by isbn or author?

So, i added more functionality:

i let the users to select one of the 5 radio buttons namely call_no, author, isbn, category,title.

I place 5 text box, one against each radio button to take the value that the user enters after he made the selection.

Then he hits the search button...my code first checks which radio button is selected, and then takes the value from the corresponding text box and send it to my php file that will process back the result and display it to the users.

so, depending on the selection my sql statement will change:

when the selected radio button is call_no it would be:

Code: Select all

<?php
$sql = "Select * FROM book WHERE call_no=('{$_POST['call_no']}')"; 

?>
when the selected radio button is author it would be:

Code: Select all

<?php
$sql = "Select * FROM book WHERE call_no=('{$_POST['author']}')"; 

?>

and so on........................


Now, i m not sure how to let my code to check which radio button is selected.

the following code i have copied from my html page:

Code: Select all

<?php

 <td width="15%">
      <p align="right"><input type="radio" value="V1" checked name="R1"></p>
    </td> 
    <td width="6%">Call No</td> 
    <td width="51%"><input type="text" name="T1" size="20"></td> 
    <td width="57%"><a href="http://localhost/insertbook.php"><font color="#0000FF">Insert
      Entry</font></a></td> 
  </tr> 
  <tr> 
    <td width="15%"> 


    <p align="right"><input type="radio" name="R1" value="V2"> 


    </td> 
    <td width="15%"> 

 Author 

?>

Here, the first radio button is selected by default, so it has an extra property

Code: Select all

<?php checked name="R1" ?>
I wonder if i should let the code to check "checked name" value...

Am i thinking the right way?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

crazytopu wrote::lol: i didnot have to include the call.

Code: Select all

<?php

<form method="post" action="search.php"> 

?>
Oh, missed that.

Topic is continued further in another thread:
viewtopic.php?t=16317
Post Reply