Just tell me please...

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:

Just tell me please...

Post by crazytopu »

just tell me how do u check the value of a radio button or any control structure?

Code: Select all

this way 

if({$_POSTї'R1']})=='V1') $searchvalue=$call_no;

or just this way

if($R1=='V2') $searchvalue=$title;
if($R1=='V3') $searchvalue=$author;
if($R1=='V4') $searchvalue=$category;
if($R1=='V5') $searchvalue=$isbn;
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Post by crazytopu »

I am almost close to the solution just need a bit more help:

Code: Select all

<?php 

$db = mysql_connect("localhost", "root"); 
mysql_select_db("library",$db) or die(mysql_error()); 



if($R1=='V1')&#123;   // R1 my radio button and V1 is its value 


$sql = "Select * FROM book WHERE call_no=('&#123;$_POST&#1111;'call_no']&#125;')";&#125; 

if($R1=='V2')&#123; 

$sql = "Select * FROM book WHERE author1=('&#123;$_POST&#1111;'author']&#125;')"; 
&#125; 

if($R1=='V3')&#123; 

$sql = "Select * FROM book WHERE title=('&#123;$_POST&#1111;'title']&#125;')"; 
&#125; 

if($R1=='V4')&#123; 

$sql = "Select * FROM book WHERE category=('&#123;$_POST&#1111;'category']&#125;')"; 
&#125; 

if($R1=='V5')&#123; 

$sql = "Select * FROM book WHERE isbn=('&#123;$_POST&#1111;'isbn']&#125;')"; 
&#125; 


$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)) 
&#123; 
   echo '<tr>'; 
   for($i=0; $i<10; $i++) 
   &#123; 
      echo '<td>'.$myrow&#1111;$i].'</td>'; 
   &#125; 
   echo '</tr>'; 
&#125; 
?> 

</table>



Just need a bit help...with this code

Code: Select all

if($R1=='V1')
what's wrong with this if statement? should i use isset function?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

First, use $_POST['R1'] instead of just $R1.

Then perhaps the following snippet of code might help you with ideas on how to write CHECKED/SELECTED into form elements.

Code: Select all

<?php
    $x = 2;
?>
<input type="radio" name="foo"<?php echo ($x == 1 ? ' CHECKED' : ''); ?>>1</option>
<input type="radio" name="foo"<?php echo ($x == 2 ? ' CHECKED' : ''); ?>>2</option>
<input type="radio" name="foo"<?php echo ($x == 3 ? ' CHECKED' : ''); ?>>3</option>
Hope it helped.
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Post by crazytopu »

Hi jam,

thanks. It was some help.

Code: Select all

$_POST&#1111;'R1']
Using this i can now search with call_no and isbn which are both int type. But i can't do the searching using the same code for string value searching:

Code: Select all

if($_POST&#1111;'R1'] =='V2')&#123;

$sql = "Select * FROM book WHERE author1=('&#123;$_POST&#1111;'author']&#125;')";&#125;

As far as i know Something about SQL i know that to searcha table with string i must quote it first...like

Code: Select all

Select * from book where author='topu';
So, i did add a quote with this part of code

Code: Select all

author1='('&#123;$_POST&#1111;'author']&#125;')"';&#125;
I wonder what i m doing wrong? i added double quoto (" ")first it gave me parser error and second time i used single quoto (' ')..this time it doest not give me any error but it simply can't retrive any data..it just shows the table structure and the column heading..but no value...

Can u tell me what M i doing wrong?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Code: Select all

$sql = "Select * FROM book WHERE author1 = '&#123;$_POST&#1111;'author']&#125;'";
...should be enough.
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Post by crazytopu »

No, it is still not working...stil i get only the table structure with column heading but no value..
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Have in mind the following:

You have an author: Dr. Foo Bar
I search for: oo

I wouldn't get any hits using your queries. This is because, if you are searching for parts of names (or whatever) you need to use a similiar syntax in the sql like:

Code: Select all

$sql = "Select * FROM book WHERE author1 LIKE '%&#123;$_POST&#1111;'author']&#125;%'";
Note that I changed = to LIKE, and added % as wildcards before and after the author-part.
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Post by crazytopu »

No jam,

I think i know what LIKE does. It actually does a search and matches column values with the string provided with SQL statement. If it gets similar text it will give an output.

But here to test the searching with String..i inserted a row where i give the author name = topu.

And from my searh form i send the exact same value..'topu'

But yet..my php code is unable to retrieve the row i inserted.

But it works fine with isbn and call_no...coz both of them are int type.
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Post by crazytopu »

Ok..i have fixed the problem..it was just a mismatch in my code..thanks jam for ur help
Post Reply