Jump to content

how to select a number over 20 ?


Go to solution Solved by dalecosp,

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   !! 

Link to comment
https://forums.phpfreaks.com/topic/284563-how-to-select-a-number-over-20/
Share on other sites

  • Solution

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);

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 :)

Edited by jazzman1

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

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 



<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");
}
?>


This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.