Jump to content

drop down list


Matpatnik

Recommended Posts

Hi guys, I want 2 drop down list which the first one tell which table of the db to get the information to show on the second one.how can I do that?thank you for your help[edited]I tried the tutorial but it doesn't work using the POST. Work fine with GET.

Link to comment
Share on other sites

Using POST, did you remeber to set the content-length and content-type headers?

Link to comment
Share on other sites

How do I set this up?

function showProfile(id,id2) { 	xmlHttp=GetXmlHttpObject();	if (xmlHttp==null) {		 alert ("Browser does not support HTTP Request");		 return;	}	var url="extra/profile.php?q="+id+"&q2="+id2+"&sid="+Math.random();	xmlHttp.onreadystatechange=stateChanged;	xmlHttp.open("POST",url,true);	xmlHttp.send(null);}

hehe I just realized that I was keep sending the information with GET :) I know very little about javascript

Link to comment
Share on other sites

function showProfile(id,id2) {	xmlHttp=GetXmlHttpObject(); //That is, if you have GetXmlHttpObject defined	if (xmlHttp==null) {		 alert ("Browser does not support HTTP Request");		 return;	}	var url="extra/profile.php";	var postvars = "q="+id+"&q2="+id2+"&sid="+Math.random();	xmlHttp.onreadystatechange=stateChanged;	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	xmlHttp.setRequestHeader(Content-Length", postvars.length);	xmlHttp.open("POST",url,true);	xmlHttp.send(postvars);}

Link to comment
Share on other sites

This is the whole page now and profile.php doesn't receive the information.

var xmlHttp;function showProfile(id,id2) {	xmlHttp=GetXmlHttpObject(); //That is, if you have GetXmlHttpObject defined	if (xmlHttp==null) {		alert ("Browser does not support HTTP Request");		return;	}	var url="extra/profile.php";	var postvars = "q="+id+"&q2="+id2+"&sid="+Math.random();	xmlHttp.onreadystatechange=stateChanged;	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	xmlHttp.setRequestHeader("Content-Length", postvars.length);	xmlHttp.open("POST",url,true);	xmlHttp.send(postvars);}function stateChanged() { 	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 		 document.getElementById("txtHint").innerHTML=xmlHttp.responseText;	} }function GetXmlHttpObject() {	var xmlHttp=null;	try {		/*Firefox, Opera 8.0+, Safari*/		xmlHttp=new XMLHttpRequest();	} catch (e) {		/*Internet Explorer*/		try {			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");		} catch (e) {			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");		}	}	return xmlHttp;}

Link to comment
Share on other sites

This is the php page and it is called from $STONE_SECTION and affect $STONE_PROFILE depending on the $_GET['action']Note that it work fine with GET but not with POST

<?php$extra .= '<script src="extra/profile.js"></script>';// show table optionfunction stone_option($table,$id,$extra=false,$post='') {	if ($extra) {		switch ($post) {			case '1':				$table = 'project';			break;			case '2':				$table = 'naturals';			break;			case '3':				$table = 'manufactured';			break;			case '4':				$table = 'tile';			break;			default:				$post = $table;			break;		}	} else {		$post = $table;	}	$option = '';	###----- START selecting profile info -----###	$db = new MySqlDB;	$db->connect();	$db->select_db();	$result = $db->query("SELECT * FROM ". $table ." 						  ORDER BY ". $table ."_id");	while ($row = $db->fetch_array($result)) {		if ($row[$table .'_id'] == $id) {			$selected = ' selected';		} else {			$selected = '';		}		$option .= '<option value="'. $row[$table .'_id'] .'"'. $selected .'>'. $row[$table .'_name'] .'</option>';	}	$db = $db->close();	//------------- END selecting profile info -------------->	return '<select id="game" name="image_'. $post .'" style="width:150px;"'. $extra .'>'. $option .'</select>';}// Get the right information for the templateswitch ($_GET['action']) {	case 'edit':		num_check($_GET['id']);				if ($error) {			hack_admin('Modification of the URL: news.php->view');		}		###----- START selecting images info -----###		$db = new MySqlDB;		$db->connect();		$db->select_db();		$result = $db->query("SELECT * FROM images 							  WHERE images_id = '". $_GET['id'] ."'");		$row = $db->fetch_array($result);		$db = $db->close();		//------------- END selecting images info -------------->				$OFORM = '<form action="'. $_SERVER['PHP_SELF'] .'?section=admin&page=commit&action=edit&type=images" method="post">';		$HIDDEN = '<input type="hidden" name="id" value="'. $_GET['id'] .'">';		$IMAGE_NAME = 'Editing Image #'. $row['images_id'];		$THUMBNAIL = ' Thumbnail';		$IMAGE_THUMB = '<img src="../images/'. $row['images_section'] .'/thumbs/'. $row['images_id'] .'.gif">';		$STONE_REALNAME = '<input type="hidden" name="image_realname" value="'. $row['images_realname'] .'">'. $row['images_realname'];		$STONE_NAME = '<input type="hidden" name="image_name" size="40" value="'. $row['images_name'] .'">'. $row['images_name'];		$STONE_WEIGHT = '<input name="image_weight" type="text" value="'. $row['images_weight'] .'" size="10" maxlength="8">';		$STONE_SECTION = stone_option('section',$row['images_section'],' onchange="showProfile(this.value,'. $row['images_profile'] .')"');		$STONE_PROFILE = stone_option('profile',$row['images_profile'],true,$row['images_section']);		$STONE_KEYWORD = '<textarea name="image_keyword" cols="65" rows="2">'. $row['images_keyword'] .'</textarea>';		$STONE_INFO = '<textarea name="image_info" cols="65" rows="5">'. $row['images_info'] .'</textarea>';		$BTN_ACTION = '<input type="submit" name="SUBMIT" value="Edit">';		$CFORM = '</form>';	break;	case 'view':		num_check($_GET['id']);		$confirm = 'Are you sure that you want delete this picture?\nYou won\\\'t be able to get it back once deleted.';				if ($error) {			hack_admin('Modification of the URL: news.php->view');		}		###----- START selecting images info -----###		$db = new MySqlDB;		$db->connect();		$db->select_db();		$result = $db->query("SELECT * FROM images 							  WHERE images_id = '". $_GET['id'] ."'");		$row = $db->fetch_array($result);		$db = $db->close();		//------------- END selecting images info -------------->				$OFORM = '';		$HIDDEN = '';		$IMAGE_NAME = 'Viewing Image #'. $row['images_id'];		$THUMBNAIL = ' Thumbnail';		$IMAGE_THUMB = '<img src="../images/'. $row['images_section'] .'/thumbs/'. $row['images_id'] .'.gif" />';		$STONE_REALNAME = $row['images_realname'];		$STONE_NAME = $row['images_name'];		$STONE_WEIGHT = $row['images_weight'];		$STONE_SECTION = stone_option('section',$row['images_section']);		$STONE_PROFILE = stone_option('profile',$row['images_profile'],true,$row['images_section']);		$STONE_KEYWORD = $row['images_keyword'];		$STONE_INFO = BBCode($row['images_info']);		$BTN_ACTION = '<a href="'. $_SERVER['PHP_SELF'] .'?section=admin&page=images&action=edit&id='. $_GET['id'] .'"><img src="../images/Admin/edit.gif" border="0" /></a> | '.					  '<a href="'. $_SERVER['PHP_SELF'] .'?section=admin&page=commit&action=delete&type=images&id='. $_GET['id'] .'" onclick="return(window.confirm(\''. $confirm .'\'))";><img src="../images/Admin/delete.gif" border="0" /></a>';		$CFORM = '</form>';	break;	case 'add':		adminRestriction();		$row['images_profile'] == 0;		$OFORM = '<form action="'. $_SERVER['PHP_SELF'] .'?section=admin&page=checkimage" method="post" enctype="multipart/form-data">';		$HIDDEN = '';		$IMAGE_NAME = 'Adding Image';		$THUMBNAIL = '<br /><span class="help">Only gif, jpg, jpeg and png are allow</span>';		$IMAGE_THUMB = '<input name="image_filename" type="file" size="40" id="image_filename"> max size: '. $a_maxsize .' kb';		$STONE_REALNAME = '<input name="image_realname" type="text" size="40" >';		$STONE_NAME = '<input name="image_name" type="text" size="40">';		$STONE_WEIGHT = '<input name="image_weight" type="text" size="10" maxlength="8">';		$STONE_SECTION = stone_option('section',$row['images_section'],' onchange="showProfile(this.value,0)"');		$STONE_PROFILE = '<b>Please, choose a section!</b>';		$STONE_KEYWORD = '<textarea name="image_keyword" cols="65" rows="2"></textarea>';		$STONE_INFO = '<textarea name="image_info" cols="65" rows="5"></textarea>';		$BTN_ACTION = '<input type="submit" name="SUBMIT" value="Add">';		$CFORM = '</form>';	break;	default:		header('Location: http://www.mysite.ca'. $_SERVER['PHP_SELF'] .'?section=admin&page=viewall&type=images');		die();	break;}// start the page$content = $OFORM.	'<table width="100%" border="1" cellspacing="0" cellpadding="3">'.	  $HIDDEN.	  '<tr>'.		'<th colspan="2">'. $IMAGE_NAME .'</th>'.	  '</tr>'.	  '<tr>'.		'<th width="200" valign="top">Image'. $THUMBNAIL .'</th>'.		'<td>'. $IMAGE_THUMB .'</td>'.	  '</tr>'.	  '<tr>'.		'<th width="200" valign="top">Stone Real Name *</th>'.		'<td>'. $STONE_REALNAME .'</td>'.	  '</tr>'.	  '<tr>'.		'<th width="200" valign="top">Stone Name</th>'.		'<td>'. $STONE_NAME .'</td>'.	  '</tr>'.	  '<tr>'.		'<th width="200" valign="top">Stone Company *</th>'.		'<td>'. stone_option('location',$row['images_location']) .'</td>'.	  '</tr>'.	  '<tr>'.		'<th width="200" valign="top">Stone Section</th>'.		'<td>'. $STONE_SECTION .'</td>'.	  '</tr>'.	  '<tr>'.		'<th width="200" valign="top">Stone Profile</th>'.		'<td id="txtHint">'. $STONE_PROFILE .'</td>'.	  '</tr>'.	  '<tr>'.		'<th width="200" valign="top">Stone Composition </th>'.		'<td>'. stone_option('composition',$row['images_composition']) .'</td>'.	  '</tr>'.	  '<tr>'.		'<th width="200" valign="top">Stone Weight</th>'.		'<td>'. $STONE_WEIGHT .' lbs. per square foot</td>'.	  '</tr>'.	  '<tr>'.		'<th width="200" valign="top">Stone Keywords *<br />'.		  '<span class="help">The keywords are made to help the search engine find the right information quickly'.			'<a href="'. $_SERVER['PHP_SELF'] .'?section=admin&page=info#picture">'.		  '<img src="../images/Admin/info.gif" alt="KEYWORDS" width="14" height="15" border="0" /></a>'.		  '</span>'.		'</th>'.		'<td>'. $STONE_KEYWORD .'</td>'.	  '</tr>'.	  '<tr>'.		'<th width="200" valign="top">Stone Description<br />'.		  '<span class="help">If ou would like to format your text you will need to use '.			'<a href="'. $_SERVER['PHP_SELF'] .'?section=admin&page=info#bbcode">bbcode tags'.			'<img src="../images/Admin/info.gif" alt="INFORMATION" width="14" height="15" border="0" /></a>'.		  '</span>'.		'</th>'.		'<td>'. $STONE_INFO .'</td>'.	  '</tr>'.	  '<tr>'.		'<td colspan="2"><div style="float:left;">* Those will stay confidential.</div><div align="center">'. $BTN_ACTION .'</div></td>'.	  '</tr>'.	'</table>'.	$CFORM;?>

Link to comment
Share on other sites

Don't have time to look through it now, but (slightly irrelevant) I think you would benefit from using HEREDOC syntax. Make things on your page a lot less confusing.

Link to comment
Share on other sites

If you build an output string you can use a loop like this to print it all on one line. Not necessarily the most efficient thing, but it will work.

$chunks = explode("\n", $output_string);for($i = 0; $i < count($chunks); $i++){  echo trim($chunks[$i]);}

This would be faster:

echo preg_replace('/\s{2,}/', '', $output_string);

Link to comment
Share on other sites

Here, is the html output. it will be easier to read :)

  <tr>	<th valign="top" width="200">Stone Section</th>	<td><select id="game" name="image_section" style="width: 150px;" onchange="showProfile(this.value,0)">		<option value="1">Project</option><option value="2">Natural Stone</option>		<option value="3">Manufactured Stone</option>		<option value="4">Tile</option>		</select></td>  </tr>  <tr>	<th valign="top" width="200">Stone Profile</th>	<td id="txtHint"><b>Please, choose a section!</b></td>  </tr>

Thank you Justsomeguy, I will probably using preg_replace() later on.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...