Jump to content

Archived

This topic is now archived and is closed to further replies.

Adam_Duski

how to select a number over 20 ?

Recommended Posts

Hi ,, 

 

i have this code 

 

<?php


include "config.php";
mysql_select_db("mov_db", $con);
$select = mysql_query("SELECT ");
echo "<table border=1 >";
echo "<tr>";
echo "<th>NO</th>";
echo "<th>Name</th>";
echo "<th>Price</th>";
echo "</tr>";


while($row=mysql_fetch_array($select)) {
  
echo "<tr>"; 
    echo "<td>" .$row['no'] ."</td>";
    echo "<td>" .$row['name'] ."</td>";
    echo "<td>" .$row['price'] ."</td>";
 echo"</tr>";




}
 echo "</table>";


?>

and i want to display a list of all movies with price over 20 and sorted by price ..

how i can select ?

,,,,

 

in another table i want to display information of all drama movie in "type" field because their is different type, i want just display drama   !! 

Share this post


Link to post
Share on other sites

You'll want to use some valid SQL for this:

 

$select = mysql_query("SELECT "); //this won't work :-(
 
//try this instead
$movies_table = "name_of_your_table";
$query = "select no,name,price from $movies_table where price >20 order by price DESC;";
$select = mysql_query($query);

Share this post


Link to post
Share on other sites

You should show us your database schema!

 

It should be something like:

SELECT movie.name FROM db_name.movie WHERE movie.type='Drama' AND movie.price > 20 ORDER BY movie.price DESC

PS: Sorry @dalecosp :)

Share this post


Link to post
Share on other sites

You'll want to use some valid SQL for this:

 

$select = mysql_query("SELECT "); //this won't work :-(
 
//try this instead
$movies_table = "name_of_your_table";
$query = "select no,name,price from $movies_table where price >20 order by price DESC;";
$select = mysql_query($query);

 

give error 

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\movie\form.php on line 158158

Share this post


Link to post
Share on other sites

You should show us your database schema!

 

It should be something like:

SELECT movie.name FROM db_name.movie WHERE movie.type='Drama' AND movie.price > 20 ORDER BY movie.price DESC

PS: Sorry @dalecosp :)

 

Thanks , but  i want to display a list of all movies with price over 20 and sorted by price in table ,, 

and display information only drama movie in another table .. 

 

i will put the full source 

Share this post


Link to post
Share on other sites


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<title>Movie</title>
<link href="style/style.css" rel="stylesheet" type="text/css" />


</head>


<body>
    <form action="form.php" method="POST">


<div id="container">
<div id="header"><div id="header_left"></div>
<div id="header_main"><b><font face="Arial" style="font-size: 14pt">Movie Details</font></b></div><div id="header_right"></div></div>
    <div id="content">
        <table class="countTable">




           <tr>
                <tr><th colspan="2" id="remain"><span style="font-weight: 400">
           
           </font></td><td>




         <tr><td><font style="font-size: 14pt" color="#0066FF">
          NO     <select name="no">  
                <option ></option>
<?php
  include 'config.php';
  mysql_select_db("mov_db",$con);
  $result=mysql_query("SELECT * from mov");
 while($row=mysql_fetch_array($result))


{  
   echo "<option value=".$row['no'].">".$row['no']."</option>";
}
?>
  </select>
  <br>
         Name <input type="text" name="name">
<br>
<br>
Type <input type="text" name="type">


<br>
<br>
Rating <input type="text" name="rating"> 


<br>
<br>


Stars <input type="text" name="stars"> 


<br>
<br>
QTY <input type="text" name="qty"> 


<br>
<br>
Price <input type="text" name="price"> 


<br>
<br>
<input type="submit" value="Send" class="inp2" name="submit">
<input type="hidden" name="formsend" value="1">
<br>
<br>
<center>
<?php


include "config.php";
mysql_select_db("mov_db", $con);
$select = mysql_query("SELECT * FROM mov ORDER BY no ASC");
echo "<table border=1 >";
echo "<tr>";
echo "<th>NO</th>";
echo "<th>Name</th>";
echo "<th> Type</th>";
echo "<th> Rating </th>";
echo "<th>Stars</th>";
echo "<th>QTY</th>";
echo "<th>Price</th>";
echo "<th>Update</th>";
echo "<th>Delete</th>";
echo "</tr>";


while($row=mysql_fetch_array($select)) {
  
echo "<tr>"; 
    echo "<td>" .$row['no'] ."</td>";
    echo "<td>" .$row['name'] ."</td>";
    echo "<td>" .$row['type'] ."</td>";
    echo "<td>" .$row['rating'] ."</td>";
    echo "<td>" .$row['stars'] ."</td>";
    echo "<td>" .$row['qty'] ."</td>";
    echo "<td>" .$row['price'] ."</td>";
    echo "<td>"."<input type='submit' value='Update' class='inp' name='update'>". "</td>";
    echo "<td>"."<a href='form.php?id=$row[no]'> Delete </a>". "</td>";
 echo"</tr>";




}
 echo "</table>";


if(isset($_GET["id"]))
{
mysql_query("DELETE FROM mov WHERE no=".$_GET["id"]);
}


if(isset($_POST['update']))
{


include "config.php";


mysql_select_db("mov_db",$con);
mysql_query("UPDATE mov SET name='$_POST[name]', type='$_POST[type]' , rating='$_POST[rating]' , stars='$_POST[stars]' , qty='$_POST[qty]' , price='$_POST[price]' WHERE no=$_POST[no]");
}
?> 
<?php
include "config.php";
mysql_select_db("mov_db", $con);
$select = mysql_query("SELECT no FROM mov ORDER BY no WHERE mov ASC limit 0,1");
echo "<br>";
echo "<table border=1 >";
echo "<tr>";
echo "<th>Total</th>";


echo"</tr>";


echo"<tr>";


$result = mysql_query("SELECT count(1) FROM mov");
$row = mysql_fetch_array($result);
echo "<td>";
$total = $row[0];
echo "Total Films: " . $total;
echo "</td>";
echo "</tr>";
 echo "</table>";


?>


<br>


<?php


include "config.php";
mysql_select_db("mov_db", $con);
$movies_table = "mov";
$query = "SELECT no,name,price from $movies_table where price >20 order by no DESC;";
echo "<table border=1 >";
echo "<tr>";
echo "<th>NO</th>";
echo "<th>Name</th>";
echo "<th>Price</th>";
echo "</tr>";


while($row=mysql_fetch_array($select)) {
  
echo "<tr>"; 
    echo "<td>" .$row['no'] ."</td>";
    echo "<td>" .$row['name'] ."</td>";
    echo "<td>" .$row['price'] ."</td>";
 echo"</tr>";




}
 echo "</table>";


?>


<br>


<br>
</font></td><td>
</center>
<br>
<br>


  <tr><th colspan="2" id="remain"><span style="font-weight: 400">
      
           <tr><td><font face="Tahoma" style="font-size: 10pt" color="#0066FF">
           <a href="https://wwww.facebook.com/Ahmed.Pirumeri">Ahmed K.Mustafa</a>
           </font></td><td>
      <font face="Tahoma" style="font-size: 10pt"></font></td></tr>
       </table>
    </div>
</div>
</form>
</body>
</html>


<?php 
if(isset($_POST['formsend']))
{
if(isset($_POST['submit']))
{
if($_POST["name"]!=""){


include 'config.php';
mysql_select_db("mov_db",$con);


$insert="INSERT INTO mov 
        values ('$_POST[no]','$_POST[name]','$_POST[type]','$_POST[rating]','$_POST[stars]','$_POST[qty]','$_POST[price]')";
mysql_query($insert,$con);
}
}
header("Location: form.php");
}
?>


Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.