0

Hi!

Im creating a search engine for products.
it can search by category, model_no and so on..
when i searched for multimedia, it would return lists of products under multimedia.
every result should be clickable and would display info for each product.
problem is, how can i pass the value of the clicked link to another page, so that it will know what link was clicked? i have codes on how to do it , but it is in javascript. now i need to combine javascript and PHP.my lightbox javascript codes doesnt work inside php as well.

here are my codes:

<html>
<head> <title></title>
<!--link code -->
<SCRIPT>
function getLinkText (link) {
return link.text ? link.text :
link.innerText ? link.innerText :
link.firstChild.nodeType == 3 ? link.firstChild.nodeValue :
'';
}
</SCRIPT>
<!--end of link codes -->


<!--lightbox codes -->
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/scriptaculous.js?load=effects"></script>
<script type="text/javascript" src="js/lightbox.js"></script>


<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<LINK HREF="style.css" TYPE="text/css" REL="stylesheet">
<style type="text/css">
<!--lightbox codes -->
#lightbox{
position: absolute;
left: 0;
width: 100%;
z-index: 100;
text-align: center;
line-height: 0;
}


#lightbox a img{ border: none; }


#outerImageContainer{
position: relative;
background-color: #fff;
width: 250px;
height: 250px;
margin: 0 auto;
}


#imageContainer{
padding: 10px;
}


#loading{
position: absolute;
top: 40%;
left: 0%;
height: 25%;
width: 100%;
text-align: center;
line-height: 0;
}
#hoverNav{
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
z-index: 10;
}
#imageContainer>#hoverNav{ left: 0;}
#hoverNav a{ outline: none;}


#prevLink, #nextLink{
width: 49%;
height: 100%;
background: transparent url(..images/blank.gif) no-repeat; /* Trick IE into showing hover */
display: block;
}
#prevLink { left: 0; float: left;}
#nextLink { right: 0; float: right;}
#prevLink:hover, #prevLink:visited:hover { background: url(..images/prevlabel.gif) left 15% no-repeat; }
#nextLink:hover, #nextLink:visited:hover { background: url(..images/nextlabel.gif) right 15% no-repeat; }



#imageDataContainer{
font: 10px Verdana, Helvetica, sans-serif;
background-color: #fff;
margin: 0 auto;
line-height: 1.4em;
overflow: auto;
width: 100%
}


#imageData{ padding:0 10px; color: #666; }
#imageData #imageDetails{ width: 70%; float: left; text-align: left; }
#imageData #caption{ font-weight: bold; }
#imageData #numberDisplay{ display: block; clear: left; padding-bottom: 1.0em;  }
#imageData #bottomNavClose{ width: 66px; float: right;  padding-bottom: 0.7em;  }


#overlay{
position: absolute;
top: 0;
left: 0;
z-index: 90;
width: 100%;
height: 500px;
background-color: #000;
}


<!--end of lightbox codes -->
.style2 {
font-family: Tahoma;
font-size: 11px;
color: #797979;
}
.style5 {
font-family: Tahoma;
color: #797979;
}
.style7 {font-family: Tahoma; font-weight: bold; font-size: 11px;}
.style9 {
font-family: Tahoma;
font-size: 11px;
color: #FF7609;
}
.style10 {color: #FF7609}


</style>


<span class="style2"><font face="Tahoma" size="2" color="#797979">    </span>


<form action="prod.php" method="post" class="style2">


Category: &nbsp;&nbsp;   &nbsp;&nbsp;
<select size="1" name="dropdown">
<option value="model_no">ALL</option>
<option value="Adaptor">Adaptor</option>
<option value="Add on Card">Add on Card</option>
<option value="Bags">Bags</option>
<option value="Cables">Cables</option>
<option value="Cameras">Cameras</option>
<option value="Console">Console</option>
<option value="Enclosures">Enclosures</option>
<option value="KVM">KVM</option>
<option value="KVM Cables">KVM Cables</option>
<option value="Misc">Misc</option>
<option value="Multimedia">Multimedia</option>
<option value="Networking">Networking</option>
<option value="Patch Panels">Patch Panels</option>
<option value="Reader">Reader</option>
<option value="Security">Security</option>
<option value="Tools">Tools</option>
<option value="UPC">UPC</option>
<option value="USB">USB</option>
<option value="USB Adaptor">USB Adaptor</option>
</select><br>
Brand:    &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<select size="1" name="search2">
<option value="">Any</option>
<option value="Avermedia"  >Avermedia</option>
<option value="digitus" >digitus</option>
</select> <br>


Model No: &nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="search" size="7" ><br>
<input type="Submit" value="Search" name="Submit">
<br>
</form>



<basefont face="Tahoma" size=11 color="#797979">



<body LINK="#FFFFFF" ALINK="#FFFFFF" VLINK="#60C5FF">
<center>
<span class="style5">
<div id="text2" style="position:absolute; overflow:hidden; left:226px; top:-10px; ">
<table border="1" cellpadding="5" cellspacing="0" bordercolor="#FF9900" align="center">
</span>


<?php


error_reporting(E_ALL);
if (!isset($_POST)) {
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("dbase") or die(mysql_error());


$query ="Select * from products WHERE category='Multimedia' " or die ("error!") ;
$result=mysql_query($query) or die ("<br><br>Query Failed!");
$num= mysql_numrows($result) or die("<br><br>no REcord Found!");
mysql_close();
echo "<table border=0 cellpadding=5 cellspacing=20 align=center><tr><td><b><font face=Tahoma size=2 color=#797979>$num Results Found</b><br>For Tag: Multimedia </td>";



$i=0;
while ($i<$num){


$a=mysql_result($result,$i,"model_no");


$d=mysql_result($result,$i,"desc2");
$pic = mysql_result($result,$i,"p1");


print ("<tr>");
print ("<td><a href=$pic.jpg rel=lightbox title=$a><img src =$pic.jpg></td></a>");
print ("<td><img src=arrow.gif><font size=2 face=Tahoma color=#FF6600><u><b><a href=prodinfo.php>$a</font></b></a></u><br><br><font size=2 color=#797979 face=Tahoma>$d</td>");
print ("</tr>");
$i++;



}
// form not submitted
?>



<?php


}


else {


// form submitted
// set server access variables


$host = "localhost";
$user = "root";
$pass = "";
$db = "dbase";


$search =mysql_escape_string($_POST);
$search2 =mysql_escape_string($_POST);
$dropdown = mysql_escape_string($_POST);


// Open Connection


$connect = mysql_connect($host, $user, $pass) or die ("Unable to connect to host");


//select database


mysql_select_db($db) or die ("Unable to connect to database");


//Create Query


$query = "select * FROM products WHERE category='$dropdown' or brand='$search2' or model_no='$search' " or die ("There is match found but cannot be shown");



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


$num=mysql_numrows($result)or die ("<font face=Tahoma size=2 color=#797979><br><br>No record Found!");


mysql_close($connect);


echo "<table border=0 cellpadding=5 cellspacing=20 align=center><tr><td><b><font face=Tahoma size=2 color=#797979>$num Results Found</b><br>For Tag: $search $search2 </td>";


$i=0;
while ($i < $num) {


$a=mysql_result($result,$i,"model_no");


$d=mysql_result($result,$i,"desc2");
$pic = mysql_result($result,$i,"p1");
$ID=  mysql_result($result,$i,"ID");


print ("<tr>");
print ("<td><a href=$pic.jpg rel=lightbox title=$a><img src =$pic.jpg></a></td>");
print ("<td><img src=arrow.gif><font size=2 face=Tahoma color=#FF6600><u><b>
<a href=prodinfo.php>
$a</font></b></u></a><br><br><font size=2 color=#797979 face=Tahoma><a href=prodinfo.php ONCLICK= var t=getLinkText(this);>$d</td>");


print ("</tr>");
$i++;


}
}


?>
</table>
</body>
</html>

Edited by happygeek: fixed formatting

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by rikunashoujo
0

Solution:

#1 Catch the clicks

Since you're using prototypejs check out these examples how to handle clicks

http://www.prototypejs.org/api/event

Example:

$('foo').observe('click', respondToClick);

function respondToClick(event) {
  var element = Event.element(event);
  element.addClassName('active');
}

#2 React

You could save the clicked url in a cookie and access it from PHP later.

0

lordspace,
Thank you very much for your response.
that's what im trying to do actually,
im getting the text value of the clicked link and save it in a cookie, and then i'll access it in the php later.but the problem is, i cant insert the <a href="#" on click =blahblah> of javascript inside print ("") of PHP.
is it possible or i just have wrong syntax?

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.