Jump to content

kungfu71186

Members
  • Posts

    14
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

kungfu71186's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Ok i am trying to make a form. The form will have some options. Now based on the options selected it will load a list into a select box. My question is what is the best way to do this. How could i update the list right away, would i need to get into ajax for this? From what i understand i will need to submit and then from there i can do what i want in php. But would i need to get into ajax so i wouldnt have to refresh the page or anything. What you think the best thing is? When i update the list would it better to put it in a select box or just list them in a table and have them link with the post functions inside them or something. Like "[stuff in here is a select box] What games do you like? [Select, Action, Adventure, MMO] So say i select MMO, it will then load action games from a database. Would it be better to just list in another select box like Games: [Lineage 2, WoW, Runescape] or list them in a table Lineage 2 WoW Runescape But they would be links basically that has the post url. And when you click it you would then get another list with more information about it and what not. Is it possible when i select the MMO option that it will update the new list right away? And if someone knows of an example or can put me in the right direction to do this in a efficient that be great. Thanks.
  2. [quote author=HeyRay2 link=topic=101419.msg401380#msg401380 date=1153510676] If you want PHP to get new values based on what you select in the first box, you'll have to submit the form with the value of that box and run a new query for the new values. If you want JavaScript to populate the new values, you will need to run a query in advance for each set of values the combo box can hold. [/quote] i cant just query new values? I have a button to update it and it calls on a function but i dont want it to reload the page everytime. There are about 50,000 combinations. But right now i have about 50 tables or more and there will be more to come. So thats a lot of querys if i do it before and shove them into an array or something and they have to be seperated out so i know what values to pull. Is it possible to submit the form without having it reload or anything?
  3. WHILE ($row  = mysql_fetch_array($result)) then try using tihs to get your values.
  4. $url = 'http://intranet/engineering/drawings/' . $PARTNUMBER '.pdf'; i think it should be $url = 'http://intranet/engineering/drawings/' . $PARTNUMBER . '.pdf'; or it may not matter. but you can try.
  5. Not sure where to put this as its javascript and php related. So if it needs to be moved im sorry for the inconvience. Anyway. I have a script that will make a select combo box. But i need to update it from values from different select boxes i have. Basically a form. So depending what is selected ill need to build a query to get a new combo box. Although the values will go into the same select box every time. It will clear out the select box first then add the new items in there. My question is how do i populate the select box i already have or how can i go about coverting a server side variable from php and putting it so javascript can read it then just use javascript to populate the box. call on this to make a new one [code]$ComboBox = new Combo_Box($name,$table_name,$order_by,$asc_desc,$style,$id_value,$idname);[/code] [code]<?php require_once("./combo_box.conf.php"); class Combo_Box { function Combo_Box($cb_name,$table_name,$order_by="",$asc="",$css_class="",$id="",$idname) { if (sizeof($table_name) > '0'){ $i='0'; foreach ($table_name AS $tablename) { if($i == "0") {   $sql .= "SELECT indexi,code FROM ".$tablename; } else { $sql .= " UNION SELECT indexi,code FROM ".$tablename; } $i++; } } else { echo "Specify a database"; } if ($table_name) { if($id) { $disable = " disabled "; } if ($order_by) { $order_by = " ORDER BY ".$order_by." ".$asc; } $sql .= $order_by; $result = mysql_query($sql) or die("Error with query (".$sql."): ".mysql_error()); $show_Combo_Box = "" ."<SELECT name=\"".$cb_name."\" id=\"".$idname."\" class=\"".$css_class."\" ".$disable."> \n" ."<OPTION value=\"0\">Select</OPTION>\n"; WHILE ($row  = mysql_fetch_array($result)) { $selection = ""; if($id){ if($row['indexi'] == $id){ $selection = " selected "; } } $show_Combo_Box .= "" ."<OPTION value=\"".$row['indexi']."\" ".$selection.">" .$row['indexi']." (".$row['code'].") " ."</OPTION> \n"; } // End WHILE $show_Combo_Box .= "" ."</SELECT>\n"; mysql_free_result($result); echo $show_Combo_Box; } // End if ($table_name) } // End function Combo_Box } // End class Combo_Box ?>[/code] as you can see it makes a new select box from the databases from an array. Then it just echos it and makes the select box. My question is how can i go about clearing which i can do that populating it. [code]<script type="text/javascript"> function clearbox() { items = document.getElementById('items'); while (items.options.length > 0) {     items.options[0] = null; } populate(); } </SCRIPT>[/code] I called on this to clear it which works fine. Now to re-populate i cant figure out. I was thinking if it was possible to maybe modify the code i have to make a new select box. Change it so it does the document.id("items") is what the box is called for me. and then loop through like above except somehow start adding options to it. Or is there some easier way. Thanks in advanced.
  6. you need to query the data. this is an example, it was to populate a select box but ill pull some parts out so maybe you can get an idea. [code]<?php $result = mysql_query($sql) or die("Error with query (".$sql."): ".mysql_error()); $show_Combo_Box = "" ."<SELECT name=\"".$cb_name."\" id=\"".$idname."\" class=\"".$css_class."\" ".$disable."> \n" ."<OPTION value=\"0\">Select</OPTION>\n"; WHILE ($row  = mysql_fetch_array($result)) { $selection = ""; if($id){ if($row['indexi'] == $id){ $selection = " selected "; } } $show_Combo_Box .= "" ."<OPTION value=\"".$row['indexi']."\" ".$selection.">" .$row['indexi']." (".$row['code'].") " ."</OPTION> \n"; } // End WHILE $show_Combo_Box .= "" ."</SELECT>\n"; mysql_free_result($result); echo $show_Combo_Box; ?>[/code] but basically pay attention to the part where it says mysql_query. $sql is the query that i made before. So it gets a database(s) then does an orderby etc... You can always put the query directly in there. Im still new to mysql and php so there may be a better, but this is the only way i know how. mysql_query("SELECT column FROM table ORDER BY table ASC")  you know something like that. But before you do anything you need to "load" up your database. require_once("./combo_box.conf.php"); i called on that which has this in it $db['host'] = "localhost"; //mysql host/server $db['user'] = "user"; // mysql username $db['pass'] = "pass"; //mysql password $db['name'] = "database"; //mysql database name if (!mysql_connect($db['host'], $db['user'], $db['pass'])){ displayErrorPage("Cannot connect to ".$db['host']."!"); exit; } @mysql_select_db($db['name']) or die (mysql_error()); Hope that helps you get started. That $row[indexi] is a column i have as well as the code. You can also use 0 or 1 to get the first column.
  7. its not from table1, its from table1 and table2 whatever is in the table_name array. I have to add more than two tables together and then sort them.
  8. Ok i have seem to have got it and i worked it down to 1 query now. Is this better to do one query with a bunch of unions? This is what i have now: [code] <?php class Combo_Box { function Combo_Box($cb_name,$table_name,$order_by="",$asc="",$css_class="",$id="") { if (sizeof($table_name) > '0'){ $i='0'; foreach ($table_name AS $tablename) { if($i == "0") {   $sql .= "SELECT column1,column2 FROM ".$tablename; } else { $sql .= " UNION SELECT column1,column2 FROM ".$tablename; } $i++; } } else { echo "Specify a database"; } if ($table_name) { if($id) { $disable = " disabled "; } if ($order_by) { $order_by = " ORDER BY ".$order_by." ".$asc; } $sql .= $order_by; $result = mysql_query($sql) or die("Error with query (".$sql."): ".mysql_error()); $show_Combo_Box = "" ."<SELECT name=\"".$cb_name."\" class=\"".$css_class."\" ".$disable."> \n" ."<OPTION value=\"0\">Select</OPTION>\n"; WHILE ($row  = mysql_fetch_array($result)) { $selection = ""; if($id){ if($row['indexi'] == $id){ $selection = " selected "; } } $show_Combo_Box .= "" ."<OPTION value=\"".$row['column1']."\" ".$selection.">" .$row['column1']." (".$row['column2'].") " ."</OPTION> \n"; } // End WHILE $show_Combo_Box .= "" ."</SELECT>\n"; mysql_free_result($result); echo $show_Combo_Box; } // End if ($table_name) } // End function Combo_Box } // End class Combo_Box ?> [/code] Is this a good way to do it or is there a better way?
  9. ok need some help again. working fine to get multiple tables and what not. How can i go about getting multiple columns now. example. first,second,third table1 1,2,4 3,5,5 2,6,8 table2 7,3,7 3,7,8 3,6,3 you have your array tables = array('table1','table2') then it goes through for the foreach and queries them and adds them to the select box. so.. 1 3 2 7 3 3 if you use $sql = "SELECT * FROM ".$tablename.$order_by; with the * it will grab the first column you can use something like $sql = "SELECT second FROM ".$tablename.$order_by; and it will grab the second column like 2 5 6 3 7 6 Now how can i get two columns so it will be something like 1 (2) 3 (5) 2 (6) 7 (3) 3 (7) 3 (6) where the inside the () is the second column i need to get, so in the select box it shows the first column then the second right next to it. So those would be your choices as shown above. Hope thats understandable. Thanks.
  10. [quote author=redarrow link=topic=100629.msg397546#msg397546 date=1152938159] Does it work i like that code tell us cheers. [/quote] had to get some sleep to try it out as i still couldnt get it :p But finally got it, table_name was defined before thats your array. [code] <?php echo "<SELECT name=\"itemtype\"> \n" ."<OPTION value=\"0\"></OPTION>\n"; foreach ($table_name1 AS $tablename) { $sql = "SELECT * FROM ".$tablename.$order_by; $result = mysql_query($sql);   WHILE (list($tablename) = mysql_fetch_array($result))   {     $show_Combo_Box .= "" ."<OPTION value=\"".$tablename."\" ".$selection.">" .$tablename ."</OPTION> \n";   } } $show_Combo_Box .= "" ."</SELECT>\n"; mysql_free_result($result); echo $show_Combo_Box; ?>[/code] [code] $name = "tablecombine"; // Name of Combo Box $table_name = array('table1','table2');         // Name of mysql table $order_by = ""; // Ordering (optional) $asc_desc = "asc"; // Ascending/Descending (optional) $style = ""; // Css Style Sheets (optional) $id_value = ""; // Post 'id' to be selected (optional) [/code] [code] $ComboBox = new Combo_Box($name,$table_name,$order_by,$asc_desc,$style,$id_value); [/code] Here it is as a function in case someone wants to use this. [code] class Combo_Box { function Combo_Box($cb_name,$table_name,$order_by="",$asc="",$css_class="",$id="") {     if($id) { $disable = " disabled "; } echo "<SELECT name=\"".$cb_name."\" class=\"".$css_class."\" ".$disable."> \n" ."<OPTION value=\"0\"></OPTION>\n"; foreach ($table_name AS $tablename) {       if ($tablename) { if ($order_by) { $order_by = " ORDER BY ".$order_by." ".$asc; } $sql = "SELECT * FROM ".$tablename.$order_by; $result = mysql_query($sql); WHILE (list($tablename)= mysql_fetch_array($result)) { $selection = ""; if($id){ if($tablename == $id){ $selection = " selected "; } } $show_Combo_Box .= "" ."<OPTION value=\"".$tablename."\" ".$selection.">" .$tablename ."</OPTION> \n"; } // End WHILE } // End if ($table_name) } // foreach $show_Combo_Box .= "" ."</SELECT>\n"; mysql_free_result($result); echo $show_Combo_Box; } // End function Combo_Box } // End class Combo_Box [/code] I found this function from another site, just modified it to use an array as akit pointed me in the right direction. credits: http://www.phpclasses.org/browse/package/1894.html
  11. I dont think join will work, join kind of combines the columns together unless there is a way to join rows. Note: in my case im just taking row[0] as thats all i need is the first column of all entries. EX: Table1: Name, Address, Date 1,ten,0 2,two,0 3,five,0 Table2: Name, Address, Date 4,0,0 5,0,0 6,0,0 now in the select box it will have the following options 1 2 3 4 5 6 by combining the two tables together.
  12. Basically what im doing is trying to load information from multiple tables. So say i have table1 with some stuff and table2 with some stuff. How do i go about adding table1 and table2 stuff into one combo box. I found this function on the net [code]function Combo_Box($cb_name,$table_name,$order_by="",$asc="",$css_class="",$id="") { if ($table_name) { if($id) { $disable = " disabled "; } if ($order_by) { $order_by = " ORDER BY ".$order_by." ".$asc; } $sql = "SELECT * FROM ".$table_name.$order_by; $result = mysql_query($sql); $show_Combo_Box = "" ."<SELECT name=\"".$cb_name."\" class=\"".$css_class."\" ".$disable."> \n" ."<OPTION value=\"0\"></OPTION>\n"; WHILE ($row = mysql_fetch_array($result)) { $selection = ""; if($id){ if($row[0] == $id){ $selection = " selected "; } } $show_Combo_Box .= "" ."<OPTION value=\"".$row[0]."\" ".$selection.">" .$row[0] ."</OPTION> \n"; } // End WHILE $show_Combo_Box .= "" ."</SELECT>\n"; mysql_free_result($result); echo $show_Combo_Box; } // End if ($table_name)[/code] But it only accepts 1 table. How can i change to accept more than 1 table? I was thinking if its possible to just do something like. $table_name = "table1 AND table2" or making $table_name an array then how can i loop through it until the end of the array? Im having a hard time trying to get that to work. Any suggestions on how to do this thanks.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.