driveflexfuel
New Member
- Messages
- 159
- Reaction score
- 0
- Points
- 0
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: