PHP and Javascript in action


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting PHP and Javascript in action
# 1  
Old 09-22-2008
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

Code:
<head>
	<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" />
</head>
<form>
	<input type="text" name="consumerID" id="consumerID"/>
	<input type="text" name="consumerName"/>
</form>
<script>
	new Autocomplete("consumerName", function() {
		return "index2.php?q=" + this.value;
	});
</script>

Here is my index2.php

Code:
<?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";
	}

	mysql_close();
	
?>

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

Code:
<?php
$q=$_GET["q"];

$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'>
<tr>
<th>ID</th>
<th>Lastname</th>
</tr>";

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

mysql_close($con);
?>

Three of javascript I used are attached. Any hints, indications, other approaches? I'm willing to consider any suggestions. Thank you in advance
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check load and action

Hey everyone can you check this script logic ? it has to restart webservice if found server load is higher than X, also i have put it in crontab to run every one minute #!/bin/bash loadavg=$(uptime | awk -F "." '{ print $1 }' | awk -F ":" '{ print $5 }') if ; then pkill -9 httpd service... (7 Replies)
Discussion started by: nimafire
7 Replies

2. Shell Programming and Scripting

Check date and do action

I would like to write a script to do such thing , if a directory have file that the extension is today (yymmdd), then do a specific action , I will run a cron job to run this script . For example Today is 2nd , if the directory have files which file name are abc.121102 and def.121102 ,... (6 Replies)
Discussion started by: ust3
6 Replies

3. Shell Programming and Scripting

multiple action!

lets explain it easy by showing the initial file and desired file: I've a file such this that contains: initial_file: 31/12/2011 23:46:08 38.6762 43.689 14.16 Ml 3.1 ... (1 Reply)
Discussion started by: oreka18
1 Replies

4. Programming

Looking For the Best Way to Rotate an Image: JavaScript, PHP, HTML etc

Hey All, What I'm looking for is a way to rotate an image by non 90 degree angles (ie 90, 180, 270, 360). I am able to do it in PHP, but there are errors in the image, some pixels end up colored incorrectly and the image ends up resized and I lose transparency. I've done my share of searching on... (1 Reply)
Discussion started by: pmd006
1 Replies

5. Shell Programming and Scripting

Need help with find its action

I am writing a shell script that takes at least 2 arguments. The first is an octal representation of file permissions, the second is a command that is executed on all the files found with that permission. #!/bin/sh find . -perm $1 -exec $2 $3 $4 {} \; invoked: ./script.sh 543 ls -la what... (3 Replies)
Discussion started by: computethis
3 Replies

6. Shell Programming and Scripting

same action in then as in else: explanation?

in /etc/init.d/networking of an ubuntu computer, I found this code: if ifdown -a --exclude=lo; then log_action_end_msg $? else log_action_end_msg $? fi Shouldn't it be replace by ifdown -a --exclude=lo ... (0 Replies)
Discussion started by: raphinou
0 Replies

7. Shell Programming and Scripting

action command

Hi.. When i refered the script /etc/rc.sysinit... i found the "action commands" like But this is not working in my shells.. the following error is coming... Please anybody help Thanks in advance esham (5 Replies)
Discussion started by: esham
5 Replies
Login or Register to Ask a Question