5 Replies - 7737 Views - Last Post: 29 September 2008 - 08:37 AM Rate Topic: -----

#1 baxter111  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 77
  • Joined: 30-June 08

dropdownlist using MySQL Data

Posted 29 September 2008 - 06:34 AM

Hi

I am currently designing an internal web application for my company and i am trying to navigate to a different page once the select value in the dropdown list has changed.

I have managed to populate this using MySQL but all i need now is when a user changes the dropdown list i need it to chage to a different page.

Hope this makes sense, here is the code i have currently wrote

<?php 
$database="time_diary"; 
mysql_connect ("localhost", "myusername", "mypass"); 
@mysql_select_db($database) or die( "Unable to select database"); 
$query="SELECT userid, user_name FROM tuser";

$result = mysql_query ($query);
echo "<select name=category value=''></option>";
// printing the list box select command

while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "<option value=$nt[userid]>$nt[user_name]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box 
?>



Thanks,

Baxter111

Is This A Good Question/Topic? 1

Replies To: dropdownlist using MySQL Data

#2 pemcconnell  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 54
  • View blog
  • Posts: 472
  • Joined: 05-August 08

Re: dropdownlist using MySQL Data

Posted 29 September 2008 - 07:16 AM

You need to use Javascript for that matey.

'Av a gander at this:

<script language="javascript" type="text/javascript">
function bunnyHop(userid){
	window.location = "templatepage.php?id="+userid;
	return true;
}
</script>

<select name="category" onchange="java script:bunnyHop(this.value)">
<?php
$database="time_diary";
mysql_connect ("localhost", "myusername", "mypass");
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT userid, user_name FROM tuser";

$result = mysql_query ($query);
// printing the list box select command

while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "\t<option value=\"".$nt['userid']."\">".$nt['user_name']."</option>\n";
/* Option values are added by looping through the array */
}
?>
</select>



Basically, it takes the value of the selected drop down option and passes it to a javascript function which i called bunnyHop, because imagination points where running low today :), which then appends that value (will be a userId at the mo) to a url, which is templatepage.php?id=x (where x is the value that is passed)

This, combined with the javascript window.location will redirect your user to a brand spanking new page.

Hope that helps :)
Was This Post Helpful? 0
  • +
  • -

#3 baxter111  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 77
  • Joined: 30-June 08

Re: dropdownlist using MySQL Data

Posted 29 September 2008 - 08:12 AM

View Postpemcconnell, on 29 Sep, 2008 - 07:16 AM, said:

You need to use Javascript for that matey.

'Av a gander at this:

<script language="javascript" type="text/javascript">
function bunnyHop(userid){
	window.location = "templatepage.php?id="+userid;
	return true;
}
</script>

<select name="category" onchange="java script:bunnyHop(this.value)">
<?php
$database="time_diary";
mysql_connect ("localhost", "myusername", "mypass");
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT userid, user_name FROM tuser";

$result = mysql_query ($query);
// printing the list box select command

while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "\t<option value=\"".$nt['userid']."\">".$nt['user_name']."</option>\n";
/* Option values are added by looping through the array */
}
?>
</select>



Basically, it takes the value of the selected drop down option and passes it to a javascript function which i called bunnyHop, because imagination points where running low today :), which then appends that value (will be a userId at the mo) to a url, which is templatepage.php?id=x (where x is the value that is passed)

This, combined with the javascript window.location will redirect your user to a brand spanking new page.

Hope that helps :)



Thanks for this, i have now added this into the page but when i run it i get the following error on the page:

Webpage Script Errors

Message: Expected ';'
Line: 10
Char: 6
Code: 0
URI: /diary/login_success.php

Here is the code:


<? 
session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");
}
?>
<html> 
<head><title>Select an employees Diary</title></head> 
<body> 
<script language="javascript" type="text/javascript">
function bunnyHop(userid){
	window.location = "test.htm";
}
</script>

<select name="category" onchange="java script:bunnyHop(this.value)">
<?php
$database="time_diary";
mysql_connect ("localhost", "myusername", "mypassword");
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT userid, user_name FROM tuser";

$result = mysql_query ($query);
// printing the list box select command

while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "\t<option value=\"".$nt['userid']."\">".$nt['user_name']."</option>\n";
/* Option values are added by looping through the array */
}
?>
</select>
</body>
</html>



Any ideas?

Thanks,

Baxter111
Was This Post Helpful? 0
  • +
  • -

#4 pemcconnell  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 54
  • View blog
  • Posts: 472
  • Joined: 05-August 08

Re: dropdownlist using MySQL Data

Posted 29 September 2008 - 08:21 AM

Try this:

<?
session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");
}
?>
<html>
<head><title>Select an employees Diary</title></head>
<body>
<script language="javascript" type="text/javascript">
function bunnyHop(userid){
	window.location = "test.htm";
}
</script>

<select name="category" onchange="bunnyHop(this.value);">
<?php
$database="time_diary";
mysql_connect ("localhost", "myusername", "mypassword");
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT userid, user_name FROM tuser";

$result = mysql_query ($query);
// printing the list box select command

while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "\t<option value=\"".$nt['userid']."\">".$nt['user_name']."</option>\n";
/* Option values are added by looping through the array */
}
?>
</select>
</body>
</html>



For some reason (probibly when i entereed the code into the post) there was a space in java script (should have been javascript)
Was This Post Helpful? 1
  • +
  • -

#5 baxter111  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 77
  • Joined: 30-June 08

Re: dropdownlist using MySQL Data

Posted 29 September 2008 - 08:30 AM

View Postpemcconnell, on 29 Sep, 2008 - 08:21 AM, said:

Try this:

<?
session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");
}
?>
<html>
<head><title>Select an employees Diary</title></head>
<body>
<script language="javascript" type="text/javascript">
function bunnyHop(userid){
	window.location = "test.htm";
}
</script>

<select name="category" onchange="bunnyHop(this.value);">
<?php
$database="time_diary";
mysql_connect ("localhost", "myusername", "mypassword");
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT userid, user_name FROM tuser";

$result = mysql_query ($query);
// printing the list box select command

while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "\t<option value=\"".$nt['userid']."\">".$nt['user_name']."</option>\n";
/* Option values are added by looping through the array */
}
?>
</select>
</body>
</html>



For some reason (probibly when i entereed the code into the post) there was a space in java script (should have been javascript)



Nice 1 mate, worked a treat.

Can't believe i didnt see this myself.

Thanks,

Baxter111
Was This Post Helpful? 0
  • +
  • -

#6 pemcconnell  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 54
  • View blog
  • Posts: 472
  • Joined: 05-August 08

Re: dropdownlist using MySQL Data

Posted 29 September 2008 - 08:37 AM

No probs, glad i could help :)
Was This Post Helpful? 1

Page 1 of 1