dcsimg
www.webdeveloper.com
Results 1 to 2 of 2

Thread: combined query - php/mysql - need expert to have quick look!

  1. #1
    Join Date
    Apr 2007
    Posts
    2

    combined query - php/mysql - need expert to have quick look!

    Hi, I am trying to query 3 tables from same database.

    I am using a form, where user can select to run the search using 1 or all of the selections.

    I am unable to get result when I run the query through using the following code - I am a noob so have limited knowledge/experience of this

    Anyway, the code I am trying to run:

    <?php
    $link = mysql_connect("localhost","","");
    mysql_select_db("createdb1", $link) or die("Unable to select database");


    function setupQuery($_POST['releaseyear'], $_POST['price'], $_POST['name'],$_POST['type'])
    {


    $query = "SELECT * FROM music"

    if ($_POST['releaseyear'])
    $query .= " AND $_POST['releaseyear'];

    if ($_POST['price'])
    $query .= " AND $_POST['price'];

    if ($_POST['name'])
    $query .= " AND $_POST['name'];


    if ($_POST['type'])
    $query .= " AND $_POST['type'];


    $result = mysql_query($query, $link) or die(mysql_error());

    while($row = mysql_fetch_assoc($result)) {
    echo '<pre>';
    print_r($row);
    echo '</pre>';
    }
    mysql_close($link);
    ?>

    Initially user must select 1 of the options to run the query, not sure if I got the first part of that right. Then user can narrow the select by price, year of release etc. I think I have the logic right but clearly not the coding.

    can anyone help?

    Ta

  2. #2
    Join Date
    Apr 2005
    Location
    Bathurst, NSW, Australia
    Posts
    3,357
    Are you getting any errors?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles