943,155 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 448
  • PHP RSS
Feb 8th, 2010
0

select from all columns with more than 1 condition

Expand Post »
Hi,
I have to do this query:
select all from a table, say lesson
where 'the variable inserted' is equal to any column in table students and students. verified= yes.

Can anyone help me on this.
I have programmed as the following, however it just displays all
column without doing the query
I need to put another condition; verified should be yes, then the result will be displayed.

help is much appreciated

PHP Syntax (Toggle Plain Text)
  1. <form action="cuba.php" method="get" name="form" class="style1">
  2.  
  3. <div align="center">
  4. <input type="text" name="q" />
  5. <input type="submit" name="Submit" value="Search" />
  6. </div>
  7. </form>
  8.  
  9.  
  10. <?
  11. $con = mysql_connect( "localhost", "root", "rootroot" );
  12. $db="permis";
  13. mysql_select_db( $db );
  14. // Get the search variable from URL
  15. $query = "select * from lesson";
  16.  
  17. $result = mysql_query($query, $con);
  18.  
  19. $fields = mysql_num_fields($result);
  20. while ($row=mysql_fetch_array($result)) {
  21. for ($i=0; $i<$fields; $i++) {
  22. $name=mysql_field_name($result, $i);
  23. // echo "$name = $row[$name]<BR>\n";
  24. }
  25. // echo "<br><br>\n";
  26. // }
  27.  
  28.  
  29.  
  30. $query2 = "select * from ".$name." where $q like '%".$name."%' and lesson.verified= 'yes'"; //search the table column for the search string
  31. $result2 = mysql_query($query2, $con);
  32. echo "$result2 = $row[$result2]<BR>\n";
  33.  
  34.  
  35. }
  36. ?>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster
tulipputih is offline Offline
107 posts
since May 2009
Feb 8th, 2010
0
Re: select from all columns with more than 1 condition
in your $query2 statement you are querying the FIELDNAME NOT A TABLE.

the "$name" is not a table this is a field name.

select * from $name --wrong

select field1, field2 from lesson.

field1 and field2 should be your $name.
Reputation Points: 12
Solved Threads: 32
Posting Whiz in Training
phpbeginners is offline Offline
226 posts
since Jul 2009
Feb 9th, 2010
0
Re: select from all columns with more than 1 condition
in your $query2 statement you are querying the FIELDNAME NOT A TABLE.

the "$name" is not a table this is a field name.

select * from $name --wrong

select field1, field2 from lesson.

field1 and field2 should be your $name.
hi phpbeginner,
many thanks for your suggestion.
but what I intend to do is to select from the fields (all field in table lesson) where the variable passed equal to any name of the fields.

the code before that is to fetch all the fields in table lesson.
it works..but then how to do query on it.

any idea of the correct way to do so?
thank you
Reputation Points: 10
Solved Threads: 0
Junior Poster
tulipputih is offline Offline
107 posts
since May 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Image upload using Ajax
Next Thread in PHP Forum Timeline: help with php operator logic





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC