php mysql dropdown value select -


currently following code displays filters individual publishers ie if select dc see dc titles.

the issue current code cannot display publishers dropdown menu.

<div id="main">   <form method="post" action="">     <div id="search_query" >      <select name="make" size="0">       <option value="all">all publishers</option>       <option value="dc">dc</option>       <option value="marvel">marvel</option>       <option value="image">image</option>     </select>      <input type="submit" name="submit" value="submit">    </div> </form> <div id="main_container">  <?php  $db_con = mysql_connect('127.0.0.1','root','root');  if (!$db_con) {    die('could not connect: ' . mysql_error());  }  mysql_select_db('work', $db_con);  if(isset($_post['submit']))  {    $make = mysql_real_escape_string($_post['make']);    $sql = sprintf("select * products publisher= '$make' ");     $result = mysql_query($sql);     echo "<table width= 970 border=1>    <tr>      <th width='120' scope='col'>title</th>      <th width='170' scope='col'>publisher</th>      <th width='185' scope='col'>price</th>      <th width='126' scope='col'>desc</th>    </tr>";    while($row = mysql_fetch_array($result))    {      echo "<tr>";      echo "<td>".$row['title']."</td>";      echo "<td>". $row['publisher'] . "</td>";      echo "<td>". $row['price'] ."</td>";      echo "<td>". $row['desc'] ."</td>";      echo "</tr>";    }    echo "</table>";  }  else  {   $sql = sprintf("select * products");   $result = mysql_query($sql);    echo "<table width= 970 border=1>   <tr>    <th width='120' scope='col'>title</th>    <th width='170' scope='col'>publisher</th>    <th width='185' scope='col'>price</th>    <th width='126' scope='col'>desc</th>  </tr>";  while($row = mysql_fetch_array($result))  {    echo "<tr>";    echo "<td>".$row['title']. "</td>";    echo "<td>". $row['publisher'] . "</td>";    echo "<td>". $row['price'] ."</td>";    echo "<td>". $row['desc'] ."</td>";    echo "</tr>";  }  echo "</table>"; }   mysql_close($db_con); ?> 

in query, it's searching publisher = $make $make = "all". database table doesn't have record publisher = "make".

i'd suggest add if else condition here:

if (isset($_post['submit'])) {     $make = mysql_real_escape_string($_post['make']);     if ($make != "all") {        $sql = sprintf("select * products publisher= '$make' ");    } else {       $sql = sprintf("select * products");    }     /* other code */ } 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -