Adding URL to Results Page in Script

Links for php scripts

Moderators: macek, egami, gesf

mrkhugh
New php-forum User
New php-forum User
Posts: 3
Joined: Mon Mar 25, 2013 3:57 pm

Adding URL to Results Page in Script

Postby mrkhugh » Mon Mar 25, 2013 4:13 pm

Any help with the following will be highly appreaciated.

I created a search.php & results.php (detail) page. The search & results pages does work. A great example is google. You type what you want, it gives you a list of results and then you click on that result.

Here is the problem: I can't click on the result.

This is what shows in my URL: http://www.mywebsite.org/detailpage.php ... ID=Yolanda Adams

Where it shows Yolanda Adams, that is the title of a record in mySQL database.

Here is some of the script from the detail page:

<?php require_once('Connections/Operations.php'); ?><?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$maxRows_DetailRS1 = 30;
$pageNum_DetailRS1 = 0;
if (isset($_GET['pageNum_DetailRS1'])) {
$pageNum_DetailRS1 = $_GET['pageNum_DetailRS1'];
}
$startRow_DetailRS1 = $pageNum_DetailRS1 * $maxRows_DetailRS1;

$colname_DetailRS1 = "-1";
if (isset($_POST['producturl'])) {
$colname_DetailRS1 = $_POST['producturl'];
}
mysql_select_db($database_Operations, $Operations);
$query_DetailRS1 = sprintf("SELECT producttitle, productauthor, producturl, Comments FROM rscdproducts WHERE producturl = %s", GetSQLValueString($colname_DetailRS1, "text"));
$query_limit_DetailRS1 = sprintf("%s LIMIT %d, %d", $query_DetailRS1, $startRow_DetailRS1, $maxRows_DetailRS1);
$DetailRS1 = mysql_query($query_limit_DetailRS1, $Operations) or die(mysql_error());
$row_DetailRS1 = mysql_fetch_assoc($DetailRS1);

if (isset($_GET['totalRows_DetailRS1'])) {
$totalRows_DetailRS1 = $_GET['totalRows_DetailRS1'];
} else {
$all_DetailRS1 = mysql_query($query_DetailRS1);
$totalRows_DetailRS1 = mysql_num_rows($all_DetailRS1);
}
$totalPages_DetailRS1 = ceil($totalRows_DetailRS1/$maxRows_DetailRS1)-1;
?>

<table border="0" align="center">
<tr>
<td><?php echo $row_DetailRS1['producttitle']; ?></td>
</tr>
<tr>
<td><?php echo $row_DetailRS1['productauthor']; ?></td>
</tr>
<tr>
<td><?php echo $row_DetailRS1['producturl']; ?></td>
</tr>
<tr>
<td><?php echo $row_DetailRS1['Comments']; ?></td>
</tr>
</table>

</body>
</html><?php
mysql_free_result($DetailRS1);
?>

mrkhugh
New php-forum User
New php-forum User
Posts: 3
Joined: Mon Mar 25, 2013 3:57 pm

Re: Adding URL to Results Page in Script

Postby mrkhugh » Thu Mar 28, 2013 5:15 am

Let me ask the question this way:

How can I change <?php echo $row_searchresult['producturl']; ?> into a dynamic URL?

The producturl is a database field that contains a URL name such as product/video.php

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: Adding URL to Results Page in Script

Postby seandisanti » Thu Mar 28, 2013 11:04 pm

make sure you're urlencoding your titles, so that you don't include invalid characters like spaces etc. magic_quotes is deprecated and even removed since 5.3 i believe. mysql_ functions are also a poor choice, but i'm trying to avoid slipping into another pdo rant. (but seriously http://jream.com/learning/videos/php-oo ... o-examples check it out).

<?php echo $row_searchresult['producturl']; ?> IS a dynamic url if you mean how do you turn it into a link; that's done by using anchor tags and link text, like...

Code: Select all

<?php
echo '<a href="' $row_searchresult['domain'] . '/' $row_searchresult['producturl'] . '">Click here to download ' $row_searchresult['description'] . '</a>';
 

mrkhugh
New php-forum User
New php-forum User
Posts: 3
Joined: Mon Mar 25, 2013 3:57 pm

Re: Adding URL to Results Page in Script

Postby mrkhugh » Tue Apr 09, 2013 8:40 am

This worked.

<a href=<?php echo $row_searchresult['producturl'];?>><?php echo $row_searchresult['producturl'];?></a>

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: Adding URL to Results Page in Script

Postby seandisanti » Tue Apr 09, 2013 9:53 pm

The line that I wrote would generate text formatted the same way, but have your markup echo'd out instead of embedding php into your markup. It's 6 of one, half dozen of the other, but I typically go with echo'd markup instead of embedded php because of 1) the file extension 2) my php files do a lot more on the programming side than they do on the markup side.


Return to “PHP Scripts”

Who is online

Users browsing this forum: No registered users and 2 guests