0

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

<form action="cuba.php" method="get" name="form" class="style1">

  <div align="center">
    <input type="text" name="q" />
    <input type="submit" name="Submit" value="Search" />
  </div>
</form>


<?
$con = mysql_connect( "localhost", "root", "rootroot" );
$db="permis";
mysql_select_db( $db );
// Get the search variable from URL
$query = "select * from lesson";

        $result = mysql_query($query, $con);

        $fields = mysql_num_fields($result);
while ($row=mysql_fetch_array($result)) {
                for ($i=0; $i<$fields; $i++)  {
                        $name=mysql_field_name($result, $i);
                       // echo "$name = $row[$name]<BR>\n";
                }
               // echo "<br><br>\n";
       // }



$query2 = "select * from ".$name."  where $q like '%".$name."%' and lesson.verified= 'yes'"; //search the table column for the search string
$result2 = mysql_query($query2, $con);
echo "$result2 = $row[$result2]<BR>\n";
	

}
?>
2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by tulipputih
0

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.

0

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

This topic has been dead for over six months. 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.