Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: Get price from DB echo different price

  1. #1
    Join Date
    Nov 2011
    Location
    Sweden
    Posts
    36
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Get price from DB echo different price

    I i have in my DB a field named "price" and on my webpage i have a mailform in witch a user can enter a price e.g 1500 or 3000, now depending on what the user posts i want to echo some other price (that is not in DB) on the webpage.

    e.g, a user posts price 1500, i want to echo 100
    or posts 3000 echo 200


    Thank's

    /Patrik.
    Last edited by PatrikIden; 11-23-2011 at 02:51 PM.

  2. #2
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    Would this work for you

    PHP Code:
    <?php
    $price 
    $_POST["price"];
    if(
    $price == "3000"){
    echo 
    "200";
    }
    ?>
    change $_POST["price"]; to the name of the input of your html form.


    From your question, I couldn't work out are you actually using a DB in this problem at all???

  3. #3
    Join Date
    Nov 2011
    Location
    Sweden
    Posts
    36
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by keyboard1333 View Post
    Would this work for you

    PHP Code:
    <?php
    $price 
    $_POST["price"];
    if(
    $price == "3000"){
    echo 
    "200";
    }
    ?>
    change $_POST["price"]; to the name of the input of your html form.


    From your question, I couldn't work out are you actually using a DB in this problem at all???
    Sorry i wasetn clear, yes i'm using DB
    And i need a range 0-1500 = 100
    1501-3000 = 200

    Thanks for your reply.

  4. #4
    Join Date
    Nov 2011
    Location
    Sweden
    Posts
    36
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    So your code isent working for me. This is the code i use to connect to DB:

    Code:
    <?php
    
    $databasename='****'; // Name of the database
    $tablename='jobadd'; // Name of the table
    $mysqladd='****'; // Address to the MySQL Server
    $mysqluser='****'; // Your MySQL UserName
    $mysqlpass='****'; // Your MySQL Password
    
    
    //CONNECT TO MYSQL
    $link=mysql_connect($mysqladd, $mysqluser, $mysqlpass) or die('Could not connect to database: ' . mysql_error());
    
    //CONNECT TO DATABASE
    mysql_select_db($databasename, $link) or die('Could not connect to table: ' . mysql_error());
    
    
    $query="SELECT * FROM jobadd"; 
     
    $result=mysql_query($query); 
     
    $num=mysql_numrows($result); 
     
    mysql_close(); 
     
     
    $i=0; 
    while ($i < $num) : 
    ?>

  5. #5
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    Could you please try to explain your problem a little more...


    What are you using the price field in your database for?

    You could use nested if statements...


    PHP Code:
    <?php 
    $price 
    $_POST["price"]; 

    if(
    $price "0"){ 
    if(
    $price "1500"){

     echo 
    "200";


    }
    ?>
    In my example, $price is the value that the user entered.
    Would the value of $price be retrieved from a database or your html form?

  6. #6
    Join Date
    Nov 2011
    Location
    Sweden
    Posts
    36
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    Thanks for yor reply. Ok so this i hove my site should work.
    I have a menu whare a user can pick a kategori (ex, painter) then this user enters a job discription and a price and pers,info. And when this user submitts this info it is stored in DB, and the "price" field is named "Pris" in DB.
    And now i have a page whare i show the info that the prev, user just entered, so that a company could ansver on that (i gues it's i cind of Ad) request. So depending on what price is put in by the user, a Company would have to pay an answering fee. I will use the following price range:

    0-15000 = 51
    15000-50000 = 81
    50000-200000 = 189
    200000-500000 = 289
    500000-1000000 = 389
    1000000-3000000 = 589
    3000000-1000000 = 989
    1000000-> = 1389

    So in the page whare i show the DB data that user puts in i'm sending some data over to the anvering page and use the "GET" code to get info, so i actualy got your code to work by sending "Pris" over to the ansvering page. But i ame however calling DB connection eaven in the ansvering page, so "post" should work?

    This is the "GET" code i use:

    <?php
    $price = $_GET["Pris"];
    if($price <= "15000"){
    echo "51";
    }
    ?>

    That worked!


    Thank you.
    Last edited by PatrikIden; 11-23-2011 at 10:56 AM.

  7. #7
    Join Date
    Nov 2011
    Location
    Sweden
    Posts
    36
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default [solved]

    Hi finaly i got this working is used this code: I dont know how to set the last piece doe. 10000000-? so i set one hundred one million, i dont think a user will post a project that costs more than that. But if you have any anwer pleas tell. Anyway Thank you for all your help. Maybe you could help me whit some other problems to if you have time (See other posts in PHP section).

    Code:
    <?php 
     
    $price = $_GET["Pris"];  
    
    if($price > "0"){  
    if($price < "15001"){ 
    
     echo "51"; 
    
    }  
    } 
    
    if($price > "15002"){  
    if($price < "50001"){ 
    
     echo "81"; 
    
    }  
    } 
    
    if($price > "50002"){  
    if($price < "200001"){ 
    
     echo "189"; 
    
    }  
    } 
    
    if($price > "200002"){  
    if($price < "500001"){ 
    
     echo "289"; 
    
    }  
    } 
    
    if($price > "500002"){  
    if($price < "1000001"){ 
    
     echo "389"; 
    
    }  
    } 
    
    if($price > "1000002"){  
    if($price < "3000001"){ 
    
     echo "589"; 
    
    }  
    } 
    
    if($price > "3000002"){  
    if($price < "10000001"){ 
    
     echo "989"; 
    
    }  
    } 
    
    if($price > "10000002"){  
    if($price < "100000001"){ 
    
     echo "1389"; 
    
    }  
    } 
    
    ?>

  8. #8
    Join Date
    Nov 2011
    Location
    Sweden
    Posts
    36
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    Ohh no. This whas not a good idea, when i use "GET" it is wisable in the address field and then a Company can just change the price in the address field and then the answering price will be wrong?

    Can you have a look and se if i can use "POST" and not "GET" some howe?

    Thank you.

    /Patrik.

  9. #9
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    On the page that you want to have this code-

    PHP Code:
    <?php 
     
    $price 
    $_GET["Pris"];  

    if(
    $price "0"){  
    if(
    $price "15001"){ 

     echo 
    "51"

    }  


    if(
    $price "15002"){  
    if(
    $price "50001"){ 

     echo 
    "81"

    }  


    if(
    $price "50002"){  
    if(
    $price "200001"){ 

     echo 
    "189"

    }  


    if(
    $price "200002"){  
    if(
    $price "500001"){ 

     echo 
    "289"

    }  


    if(
    $price "500002"){  
    if(
    $price "1000001"){ 

     echo 
    "389"

    }  


    if(
    $price "1000002"){  
    if(
    $price "3000001"){ 

     echo 
    "589"

    }  


    if(
    $price "3000002"){  
    if(
    $price "10000001"){ 

     echo 
    "989"

    }  


    if(
    $price "10000002"){  
    if(
    $price "100000001"){ 

     echo 
    "1389"

    }  


    ?>
    couldn't you just connect to the database on there and save the value you want to compare into $price instead of doing it on another page and then sending it by form?

    Am I understanding what your saying correctly?
    If not please try to explain...

  10. #10
    Join Date
    Nov 2011
    Location
    Sweden
    Posts
    36
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    I'v got the DB values (price) in one page and on that page i also have a answer this ad link, so when clicking that link some values (inc, price) have to go throw to the page whare the answering form is.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •