Jump to content

Need to turn result into link..


dawg1

Recommended Posts

I've tried to find an answer in the forum and although there have been posts similar I am unable to covert the answer to fit what I've got (mostly because I know very very little about php - sorry).

What I need is one of the results to be added to the end of a url in order to create a link. Basically I have a storefront (www.storefront.com/) and the result NAME can be added onto the end of our url to create a link to the product page. (www.storefront.com/NAME)

 

<?php
$dbhost = "";
$dbuser = "";
$dbpass = "";
$dbname = "";
//Connect to MySQL Server
mysql_connect($dbhost, $dbuser, $dbpass);
//Select Database
mysql_select_db($dbname) or die(mysql_error());
// Retrieve data from Query String
$price = $_GET['price'];
$taxable = $_GET['taxable'];
$weight = $_GET['weight'];
// Escape User Input to help prevent SQL Injection
$age = mysql_real_escape_string($price);
$sex = mysql_real_escape_string($taxable);
$wpm = mysql_real_escape_string($weight);
//build query
$query = "SELECT * FROM Products WHERE taxable = '$taxable'";
if(is_numeric($price))
$query .= " AND price <= $price";
if(is_numeric($weight))
$query .= " AND weight <= $weight";
//Execute query
$qry_result = mysql_query($query) or die(mysql_error());

//Build Result String
$display_string = "<table>";
$display_string .= "<tr>";
$display_string .= "<th>Name</th>";
$display_string .= "<th>Price</th>";
$display_string .= "<th>Taxable</th>";
$display_string .= "<th>Weight</th>";
$display_string .= "</tr>";

// Insert a new row in the table for each person returned
while($row = mysql_fetch_array($qry_result)){
$display_string .= "<tr>";
$display_string .= "<td>'<a href="www.storefront.com/">' . $row[name] . ' </a>'/td>";
$display_string .= "<td>$row[price]</td>";
$display_string .= "<td>$row[taxable]</td>";
$display_string .= "<td>$row[weight]</td>";
	$display_string .= "</tr>";

}
echo "Query: " . $query . "<br />";
$display_string .= "</table>";
echo $display_string;
?>

 

I know the way it is setup in the code is wrong. Can anyone help me out?

Would really appreciate it.

 

Thanks - and again, sorry for my lack of php knowledge.

Link to comment
Share on other sites

You can also do this using htaccess

To do it you just use normal name var in your code like this:

if ($_GET[name]){
echo "blablabla";
}

 

but add a file name in the www folder that is named .htaccess and put it in the folowing code

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^.*my_name_id_([a-z]+)$ index.php?name=$1 [L] 

 

The htaccess is gona make the following URL format work exacly like if there was a $name directory

<a href="www.storefront.com/my_name_id_$name">

 

You may change the "my_name_id_" part as long as you change that in the .htaccess lol I just wanted to show you how to add a prefix if you need one

 

Link to comment
Share on other sites

You will want to try something like this

 

<a href="www.storefront.com?$Name">

 

so you are adding ?$Name to the end

 

and have the $Name be what ever you assign it

 

Thanks for responding so fast!

I tried your suggestion but when I add the html code for the link no results display. Did I set it up correctly?

 

<?php
$dbhost = "";
$dbuser = "";
$dbpass = "";
$dbname = "";
//Connect to MySQL Server
mysql_connect($dbhost, $dbuser, $dbpass);
//Select Database
mysql_select_db($dbname) or die(mysql_error());

// Retrieve data from Query String
$price = $_GET['price'];
$taxable = $_GET['taxable'];
$weight = $_GET['weight'];
$code = $_GET['code'];


        // Escape User Input to help prevent SQL Injection
$price = mysql_real_escape_string($price);
$taxable = mysql_real_escape_string($taxable);
$weight = mysql_real_escape_string($weight);
$code = mysql_real_escape_string($code);

       //build query
$query = "SELECT * FROM Products WHERE taxable = '$taxable'";
if(is_numeric($price))
$query .= " AND price <= $price";
if(is_numeric($weight))
$query .= " AND weight <= $weight";


       //Execute query
$qry_result = mysql_query($query) or die(mysql_error());

//Build Result String
$display_string = "<table>";
$display_string .= "<tr>";
$display_string .= "<th>Code</th>";
$display_string .= "<th>Price</th>";
$display_string .= "<th>Taxable</th>";
$display_string .= "<th>Weight</th>";
$display_string .= "</tr>";

// Insert a new row in the table for each person returned
while($row = mysql_fetch_array($qry_result)){
$display_string .= "<tr>";
$display_string .= "<td><a href="www.storefront.net?$Code">$row[code]</a></td>";
$display_string .= "<td>$row[price]</td>";
$display_string .= "<td>$row[taxable]</td>";
$display_string .= "<td>$row[weight]</td>";
	$display_string .= "</tr>";

}
echo "Query: " . $query . "<br />";
$display_string .= "</table>";
echo $display_string;
?>

Link to comment
Share on other sites

K, I did that, and made sure the case was correct, but still no luck.  The data displays just fine when I don't try to make it a link.

 

<?php
$dbhost = "";
$dbuser = "";
$dbpass = "";
$dbname = "";
//Connect to MySQL Server
mysql_connect($dbhost, $dbuser, $dbpass);
//Select Database
mysql_select_db($dbname) or die(mysql_error());

// Retrieve data from Query String
$price = $_GET['price'];
$taxable = $_GET['taxable'];
$weight = $_GET['weight'];
$code = $_GET['code'];


        // Escape User Input to help prevent SQL Injection
$price = mysql_real_escape_string($price);
$taxable = mysql_real_escape_string($taxable);
$weight = mysql_real_escape_string($weight);
$code = mysql_real_escape_string($code);

       //build query
$query = "SELECT * FROM Products WHERE taxable = '$taxable'";
if(is_numeric($price))
$query .= " AND price <= $price";
if(is_numeric($weight))
$query .= " AND weight <= $weight";


       //Execute query
$qry_result = mysql_query($query) or die(mysql_error());

//Build Result String
$display_string = "<table>";
$display_string .= "<tr>";
$display_string .= "<th>Code</th>";
$display_string .= "<th>Price</th>";
$display_string .= "<th>Taxable</th>";
$display_string .= "<th>Weight</th>";
$display_string .= "</tr>";

// Insert a new row in the table for each product returned
while($row = mysql_fetch_array($qry_result)){
$display_string .= "<tr>";
$display_string .= "<td><a href="www.dawgwear.net/page/D/PROD/$code">$row[code]</a></td>";
$display_string .= "<td>$row[price]</td>";
$display_string .= "<td>$row[taxable]</td>";
$display_string .= "<td>$row[weight]</td>";
	$display_string .= "</tr>";

}
echo "Query: " . $query . "<br />";
$display_string .= "</table>";
echo $display_string;
?>

 

 

 

I am using javascript on my webpage that displays the results...might there be something there I need to adjust as well?

 

<script language="javascript" type="text/javascript">
<!-- 
//Browser Support Code
function ajaxFunction(){
var ajaxRequest;  // The variable that makes Ajax possible!

try{
	// Opera 8.0+, Firefox, Safari
	ajaxRequest = new XMLHttpRequest();
} catch (e){
	// Internet Explorer Browsers
	try{
		ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try{
			ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e){
			// Something went wrong
			alert("Your browser broke!");
			return false;
		}
	}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
	if(ajaxRequest.readyState == 4){
		var ajaxDisplay = document.getElementById('ajaxDiv');
		ajaxDisplay.innerHTML = ajaxRequest.responseText;
	}
}
var price = document.getElementById('price').value;
var weight = document.getElementById('weight').value;
var taxable = document.getElementById('taxable').value;
var queryString = "?price=" + price + "&weight=" + weight + "&taxable=" + taxable;
ajaxRequest.open("GET", "ajax_example.php" + queryString, true);
ajaxRequest.send(null); 
}

//-->
</script>

 

Link to comment
Share on other sites

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.