Jump to content

shawn10642

Members
  • Posts

    35
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

shawn10642's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Great question, it may be a one time grab...if that makes sence, but it's wierd i can echo $_POST['city_code']...?!?!?
  2. Basically whats happening, there's one dropdown form with a submit button on the side. echo "<option value='{$row['city_code']}'>{$row['city_name']}</option>"; code above city_code is the value/$_POST, and city_name is the visible value in the dropdown form echo "<form method='POST' action =''>"; echo "<input type='submit' name='weaCode' value='Submit'/>"; echo "</form>"; Code about, posts the selection as $_POST $city there a switch put it as $_POST $cityd for my other script can process the city_code Rundown MYSql --->city_name ---->city_code = form selection--->city_name--->city_code---->$city---->$cityd ---->to weather script What i need aswell is MYSql --->city_name ---->city_code = form selection--->city_name---> Echo Hope i makes sence what exactly are you trying to ask?
  3. Nope still not working i also tried putting echo $row['city_name']; before the While close tag } how would i go POST the city_name when pushing submit, if it's even possible?
  4. i've tried echo $_POST["city_name"]; echo $_POST["city_code"]; echo $_POST["$res"]; echo $_POST["$row"]; echo $row['city_name']; echo $row['city_code']; echo $res['city_name']; echo $res['city_code'];
  5. Nope wish it was that easy already tried that.
  6. so the scrpit works now :) one more thing if echo $_POST["cityd"]; posts city code how do i echo the city itself? // form echo "<form method='POST' action =''>"; echo "<select name='cityd'>"; while($row = mysql_fetch_array($res)) { echo "<option value='{$row['city_code']}'>{$row['city_name']}</option>"; } echo "</select>"; echo "<input type='submit' name='weaCode' value='Submit'/>"; echo "</form>"; echo $_POST["cityd"]; ?>
  7. unless there's an easier way of doing so, i need it to atleast auto populate the form based on the mysql below and to post the city_code -- -------------------------------------------------------- -- -- Table structure for table `cities` -- CREATE TABLE `countries` ( `id` int(6) NOT NULL auto_increment, `city_name` varchar(250) NOT NULL default '', `city_code` varchar(12) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=243 ; -- -- Dumping data for table `cities` -- INSERT INTO `countries` VALUES (1, 'Vancouver', 'BC-50');
  8. The script is in ajax, but what i need it to do is post the 'code' so my other script can pick it up and process the city code
  9. original sql -- -------------------------------------------------------- -- -- Table structure for table `countries` -- CREATE TABLE `countries` ( `id` int(6) NOT NULL auto_increment, `value` varchar(250) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=243 ; -- -- Dumping data for table `countries` -- INSERT INTO `countries` VALUES (1, 'Vancouver'); New Sql -- -------------------------------------------------------- -- -- Table structure for table `countries` -- CREATE TABLE `countries` ( `id` int(6) NOT NULL auto_increment, `value` varchar(250) NOT NULL default '', `code` varchar(12) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=243 ; -- -- Dumping data for table `countries` -- INSERT INTO `countries` VALUES (1, 'Vancouver', 'BC-50'); PHP code for the job <?php // PHP5 Implementation - uses MySQLi. // mysqli('localhost', 'yourUsername', 'yourPassword', 'yourDatabase'); $db = new mysqli('localhost', 'root' ,'password', 'weather'); if(!$db) { // Show error if we cannot connect. echo 'ERROR: Could not connect to the database.'; } else { // Is there a posted query string? if(isset($_POST['queryString'])) { $queryString = $db->real_escape_string($_POST['queryString']); // Is the string length greater than 0? if(strlen($queryString) >0) { // Run the query: We use LIKE '$queryString%' // The percentage sign is a wild-card, in my example of countries it works like this... // $queryString = 'Uni'; // Returned data = 'United States, United Kindom'; // YOU NEED TO ALTER THE QUERY TO MATCH YOUR DATABASE. // eg: SELECT yourColumnName FROM yourTable WHERE yourColumnName LIKE '$queryString%' LIMIT 10 $query = $db->query("SELECT your_column FROM your_db_table WHERE your_column LIKE '$queryString%' LIMIT 10"); if($query) { // While there are results loop through them - fetching an Object (i like PHP5 btw!). while ($result = $query ->fetch_object()) { // Format the results, im using <li> for the list, you can change it. // The onClick function fills the textbox with the result. // YOU MUST CHANGE: $result->value to $result->your_colum echo '<li onClick="fill(\''.$result->value.'\');">'.$result->value.'</li>'; } } else { echo 'ERROR: There was a problem with the query.'; } } else { // Dont do anything. } // There is a queryString. } else { echo 'There should be no direct access to this script!'; } } ?> What the original code does 1) you start typing your city (eg. Van) 2) when you type the first letter (eg. V), it looks into mysql and auto fills a dropdown menu with all possible cities What i need it to do 1) you start typing your city (eg. Van) 2) when you type the first letter (eg. V), it looks into mysql and auto fills a dropdown menu with all possible cities 3) when you find your city you click it or press enter, and it POST's the city code as well now how do i munipulate the script to do that... another thing, when i put the extra sql entry in "code", the auto fill stopped working, why? Thanks
  10. <?php // Connect to database server $hd = mysql_connect("localhost", "root", "1064111") or die ("Unable to connect"); // Select database mysql_select_db ("weather", $hd) or die ("Unable to select database"); // Select info $res = mysql_query("SELECT * FROM cities", $hd) or die ("Unable to run query"); $res = mysql_query("SELECT * FROM cities", $hd) echo "<form action='' method='POST'>"; echo "<select>"; while($row = mysql_fetch_array($res)) { echo "<option value='{$row['city_code']}'>{$row['city_name']}</option>"; } echo "</select>"; echo "<input type='submit' name='submitForm' value="Submit"/>"; echo "</form>echo "</form>"; echo "</form>"; the other code above, had doubles.
  11. <?php // Connect to database server $hd = mysql_connect("localhost", "root", "1064111") or die ("Unable to connect"); // Select database mysql_select_db ("weather", $hd) or die ("Unable to select database"); // Select info $res = mysql_query("SELECT * FROM cities", $hd) or die ("Unable to run query"); $res = mysql_query("SELECT * FROM cities", $hd) echo "<form action='' method='POST'>"; echo "<select>"; while($row = mysql_fetch_array($res)) { echo "<option value='{$row['city_code']}'>{$row['city_name']}</option>"; } echo "</select>"; echo "<input type='submit' name='submitForm' value="Submit"/>"; echo "</form>echo "</form>";echo "</form>"; <?php // Connect to database server $hd = mysql_connect("localhost", "root", "1064111") or die ("Unable to connect"); // Select database mysql_select_db ("weather", $hd) or die ("Unable to select database"); // Select info $res = mysql_query("SELECT * FROM cities", $hd) or die ("Unable to run query"); $res = mysql_query("SELECT * FROM cities", $hd) echo "<form action='' method='POST'>"; echo "<select>"; while($row = mysql_fetch_array($res)) { echo "<option value='{$row['city_code']}'>{$row['city_name']}</option>"; } echo "</select>"; echo "<input type='submit' name='submitForm' value="Submit"/>"; echo "</form>"; i knoe there's something wrong, but flustered right now :'(
  12. unfortunantly this doesn't work.
  13. echo "<option value='{$row['city_code']}'>{$row['city_name']}</option>";}echo "</select> so this work to auto populate the form, but how do i POST the city_code. thanks again, sorry i'm being a total noob right now
×
×
  • 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.