Go Back   DaemonForums > Miscellaneous > Programming

Programming C, bash, Python, Perl, PHP, Java, you name it.

Thread Tools Display Modes
  #1   (View Single Post)  
Old 23rd September 2008
c0mrade's Avatar
c0mrade c0mrade is offline
Port Guard
Join Date: May 2008
Posts: 41
Default PHP and Javascript in action

Hi all,

I'm not sure in which category should I post in but I'll try in this one. Here is my problem, I'm trying to combine 2 scripts that I found useful to me. First one is this , what I'm trying to accomplish is dynamic user look up from my database. The other script is this one , this script echoes entries from database. I have 2 fields in my database "name" and "id" and Here is idea of putting them together.. When I perform search I get some results which are stored within my database then they appear as a list inside <li> html tag.. and when I click on one of the entries from database from "name" I get "id" of that name in another input and that works just fine .. now the other script is listing results also by id .. and so that is they are not working together .. maybe the code will explain better than me.

here is my index.php

	<script type="text/javascript" src="prototype.js"></script>
	<script type="text/javascript" src="autocomplete.js"></script>
        <script src="selectuser.js"></script>
	<link rel="stylesheet" type="text/css" href="autocomplete.css" />
	<input type="text" name="consumerID" id="consumerID"/>
	<input type="text" name="consumerName"/>
	new Autocomplete("consumerName", function() {
		return "index2.php?q=" + this.value;
Here is my index2.php

	$hostname = "localhost";
	$username = "c0mrade";
	$password = "xxx123xxx";
	$dbname = "xxl";

	mysql_connect( $hostname, $username, $password ) or die ("Unable to connect to database!");
	mysql_select_db( $dbname );

	$q = $_GET["q"];
	$pagesize = 50;

	mysql_query("set names utf8");

	$sql = "select * from users where locate('$q', name) > 0 order by locate('$q', name), name limit $pagesize";
	$results = mysql_query($sql);

	while ($row = mysql_fetch_array( $results )) { 
		$id = $row["id"]; 
		$name = ucwords( strtolower( $row["name"] ) );
		$html_name = preg_replace("/(" . $q . ")/i", "<b>\$1</b>", $name);

		echo "<li onselect=\"this.text.value = '$name'; $('consumerID').value = '$id'; showUser($('consumerID').value) \"><span>$id</span>$name</li>\n";

Here is getuser.php which should echo results based on id


$con = mysql_connect('localhost', 'c0mrade', 'xxx123xxx');
if (!$con)
 die('Could not connect: ' . mysql_error());

mysql_select_db("xxl", $con);

$sql="SELECT * FROM consumers WHERE id = '".$q."'";

$result = mysql_query($sql);

echo "<table border='1'>

while($row = mysql_fetch_array($result))
 echo "<tr>";
 echo "<td>" . $row['id'] . "</td>";
 echo "<td>" . $row['name'] . "</td>";
 echo "</tr>";
echo "</table>";

Three of javascript I used are attached. Any hints, indications, other approaches? I'm willing to consider any suggestions. Thank you in advance
Attached Files
File Type: txt selectuser.js.txt.txt (900 Bytes, 26 views)
File Type: txt prototype.js.txt.txt (97.6 KB, 26 views)
File Type: txt autocomplete.js.txt.txt (14.6 KB, 24 views)
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Opera Widget Javascript Troubles thejosephgrace General software and network 6 3rd August 2008 01:34 PM

All times are GMT. The time now is 05:01 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick