+ Reply to Thread
Results 1 to 2 of 2

Thread: php / ajax variables

  1. #1
    driveflexfuel is offline x10 Sophmore driveflexfuel is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    159

    php / ajax variables

    I am a little lost when it comes to MySQL and ajax. I have been trying to figure this out for a few hours and I am hoping someone here could give me a hand. I am working with the code below that was given to me by fellow site owner. At the bottom of the code i need $sendlink to = the link pulled from the database. 400 Credits to the person with the solution

    Code:
    <?php
    include 'config.php';
    
    $link = mysql_connect($servername,$user,$pass);
    if (!$link) {
       die('Could not connect: ' . mysql_error());
    }
    mysql_select_db($db);
    
    function setyear()
    {
    global $table;
       $make='';
       $query = "SELECT DISTINCT acura from $table where year=".$_REQUEST['year'];
       $result = mysql_query($query);
       if (!$result) {
          $message  = 'Invalid query: ' . mysql_error() . "\n";
          $message .= 'Whole query: ' . $query;
          die($message);
       }
       while ($row = mysql_fetch_assoc($result)) {
       $make = $make.$row["acura"].'|';
       }
       
       echo $make;die();
    }
    function allyear()
    {
    global $table;
       $year='';
       $query = "SELECT DISTINCT year from $table ORDER BY year";
       $result = mysql_query($query);
       if (!$result) {
          $message  = 'Invalid query: ' . mysql_error() . "\n";
          $message .= 'Whole query: ' . $query;
          die($message);
       }
       while ($row = mysql_fetch_assoc($result)) {
          $year = $year.$row["year"].'|';
       }
       
       echo $year;die();
    }
    function setmake(){
    global $table;
    $model='';
       $query = "SELECT DISTINCT model from $table where year="."'".$_POST['year']."'"."and acura="."'".$_POST['make']."'";
       
       $result = mysql_query($query);
       if (!$result) {
          $message  = 'Invalid query: ' . mysql_error() . "\n";
          $message .= 'Whole query: ' . $query;
          die($message);
       }
       while ($row = mysql_fetch_assoc($result)) {
          $model=$model. $row["model"].'|';
       }
       echo $model;die();
    }
    function setmodel()
    {
    global $table;
    $cylinder='';
       $query = "SELECT  DISTINCT cylinder from $table where year=".
       "'".$_POST['year']."'"." and acura="."'".$_POST['make']."'". " and model="."'".$_POST['model']."'";
       $result = mysql_query($query);
       if (!$result) {
          $message  = 'Invalid query: ' . mysql_error() . "\n";
          $message .= 'Whole query: ' . $query;
          die($message);
       }
       while ($row = mysql_fetch_assoc($result)) {
       $cylinder=$cylinder.$row['cylinder'].'|';
       }
       echo $cylinder;die();
    }
    
    function gourl(){
    global $table;
    $query = "SELECT link from $table where year=".
       "'".$_POST['year']."'"." and acura="."'".$_POST['make']."'". " and model="."'".$_POST['model']."'"
       . " and cylinder="."'".$_POST['engine']."'";;
       $result = mysql_query($query);
       if (!$result) {
          $message  = 'Invalid query: ' . mysql_error() . "\n";
          $message .= 'Whole query: ' . $query;
          die($message);
       }
       $row = mysql_fetch_assoc($result);
       $link = $row['link'];
       return $link;
    }
    if (array_key_exists('option',$_GET)) {
    if ($_GET['option'] == 'setyear') 
    {
       setyear();
    }
    if ($_GET['option'] == 'setmake') 
    {
       setmake();
    }
    if ($_GET['option'] == 'setmodel') 
    {
       setmodel();
    }
    if ($_GET['option'] == 'allyear') 
    {
       allyear();
    }
    }
    
    if (array_key_exists('go',$_POST)) {
       if ($_POST['go']=="SendQuery")
       {
          $year = $_POST['year'];
        $model = $_POST['model'];
        $make = $_POST['make'];
        $engine = $_POST['engine'];
    
        $sendlink = HELP ;
    
          //$data = substr($data,0,strlen(data)-1);
          $link = gourl();
          $link = basename($link);
          $fulldir ="/home/e85and/public_html/TEST/store/";
          include($fulldir.$link);    
          die();
       }
    }
    ?>
    Last edited by driveflexfuel; 11-20-2008 at 08:00 PM.

  2. #2
    e85andyou is offline x10Hosting Member e85andyou is an unknown quantity at this point
    Join Date
    Nov 2007
    Posts
    49

    Re: php / ajax variables

    Your answer would be

    $sendlink = gourl();

+ Reply to Thread

Similar Threads

  1. Ever Been Suspended For Using PHP?
    By dragoneye_xp in forum Off Topic
    Replies: 26
    Last Post: 08-16-2009, 07:17 PM
  2. [PHP] Variables in PHP
    By Bryon in forum Tutorials
    Replies: 15
    Last Post: 01-29-2009, 09:46 AM
  3. PHP and new accounts
    By idani in forum Free Hosting
    Replies: 1
    Last Post: 09-21-2008, 01:49 PM
  4. saving variables with fopen (PHP)
    By thezone1 in forum Scripts & 3rd Party Apps
    Replies: 0
    Last Post: 03-14-2008, 02:30 AM
  5. Replies: 3
    Last Post: 03-10-2008, 12:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers