Jump to content

Bill Withers

Members
  • Posts

    27
  • Joined

  • Last visited

Everything posted by Bill Withers

  1. Huh, Well with the .0 add, it seems that FF is working correctly on the server, just acts funny on my localhost <shrug>
  2. Wow, FF really holds onto its need to do what it does. I placed the .0 in for the value like so: $optionsHTML = "<option value='{$randomID}.0' >Random</option>\n" . $optionsHTML; The results are shown from the page source: <form action='' method='post'>COURSE NAME <br><select name="selections[dd_courses]"><option value='21.0' >Random</option> FF shows the actual selection that references ID 21 in the dropdown. IE and chrome show the random option and behaves as expected.. weird. As for the other part, with the intval, I tried putting it in various places I thought it should go, But I havent had any luck. I am reading up and gonna try some more.. Thanks for all your help on this.
  3. Thanks, I have that now in the code and FF still is doing it. I am not sure but being as the string for the random ID has already been evaluated when the page first loads, (you can see it when looking at the source when opening the page for the first time) FF is doing its "special Behavior" as you pointed out earlier. Not a big deal I guess for what I am doing but I can see how that could drive a real coder crazy.. A big thank you for all that you have done. I think the old farts that use it will like it the way it is.
  4. After looking closer at the code I think I can see why upon looking at the source I can deduce what one or more of the random options will say when the submit button is pushed: <option value='{$randomID}'>Random</option> hehe I changed the line to read <option value='{$randomID}' selected=' "selected" '>Random</option> that didn't work so I tried: $selected = 'selected="selected"'; $optionsHTML = "<option value='{$randomID}' '{$selected}'>Random</option>\n" . $optionsHTML; still no go the quotes are killing me...... time to go read up
  5. Ok great! Thanks Psycho I will give your fix a shot.. Glad I wasn't just seeing things
  6. In the script you have here in this thread. the drop down boxes are populated from the tables, but the first choice is random. when you hit submit it presents a random choice from that table if no other selection is made besides random. if looking at the page with FF with the dropdown boxes that say random, and hit the reload page, it presents the dropdowns with random data not the random choice as expected. just thought it was weird is all. Also, if looking at the dropdown page, if you hit show source you can see what the random choice will be when submit is selected by the string value of the ID... hehe, so it has already randomized the data before the drop downs are presented I just found that strange is all. The script works very well and uses almost nothing in resources. Thanks again Psycho.. And you as well ChristianF
  7. Just noticed a strange thing in firefox 12 if I go to the page that this script is on, hitting reload actually acts like you hit the submit button. only it randomizes all within the dropdowns. it does this on localhost win/xamp and on live server /linux/apache/etc chrome - 21.0.1180.79 m latest opera and IE9 all behave as you would expect, just as if you retyped the url I cant get firefox to do this with any other like scripted page I have found. what do you think?
  8. Your Solution works very nice!! and it is very elegant and streamlined. Thank you very much for your time and effort!!!!
  9. I agree that I think it is flawed. and as I stated I hadn't tried your code yet, I just wanted to show you what I had working if there were any other questions about the structure thanks again
  10. Here is what I have, I haven't tried your new code yet Form ----------- <form action= "results.php" method="post"> Populating the Drops ---------------------- $database="op"; mysql_connect ("localhost", "root", "xxx"); @mysql_select_db($database) or die( "Unable to select database"); $result = mysql_query( "SELECT ID, course_name FROM courses" ) or die("SELECT Error: ".mysql_error()); $options="Random"; while ($row=mysql_fetch_array($result)) { $firstvalue=$row["course_name"]; $options.="<OPTION VALUE=\"$firstvalue\">".$firstvalue.'</option>'; } $result = mysql_query( "SELECT tee FROM tee" ) or die("SELECT Error: ".mysql_error()); $options3="Random"; while ($row=mysql_fetch_array($result)) { $firstvalue=$row["tee"]; $options3.="<OPTION VALUE=\"$firstvalue\">".$firstvalue.'</option>'; } Results page ------------------- var output from the submission. The user selected Random for courses and White for tee -------------------------------------- array(12) { ["COURSES"]=> string(0) "" ["TEE"]=> string(5) "White" what to show the user ------------------------------ if ($_POST['COURSES'] === "") { $query = "SELECT course_name FROM courses ORDER BY RAND()LIMIT 1"; $result = mysql_query($query) or trigger_error(mysql_error()." ".$query); $row = mysql_fetch_assoc($result); $course = $row["course_name"]; echo $course; } else { echo ($_POST['COURSES']); } ?> </td> <td> <?php if ($_POST['TEE'] === "") { $query = "SELECT tee FROM tee ORDER BY RAND()LIMIT 1"; $result = mysql_query($query) or trigger_error(mysql_error()." ".$query); $row = mysql_fetch_assoc($result); $tee = $row["tee"]; echo $tee; } else { echo ($_POST['TEE']); } ?>
  11. Oops, We posted at the same time. Thanks again Psycho! I will try this out as it is waaay more rational looking than what I have.
  12. Okay, Again thanks for all the help. I got it to do what I wanted 1. populated the drop downs with data from the DB with an extra value of "Random" 2. when the options are submitted, Depending on whether the user selects a db value or the "random" value, The user is presented with the choice they picked or a random choice via a if else statement on the results page. Before I go live with it I was wanting to know if there are any security holes as far as injection exploits I should address. Should I continue on with those questions in this thread or make another? as there is a lot of sloppy code to look at Thanks
  13. Thanks again Psycho, I can see what you were going for there. Of course this will end in a empty set but the streamlined process is duly noted and appreciated. As to the original question, is it possible in php to do what I would like the original layout to do? Thanks again
  14. That's all well and good. Maybe its the elitist tone of your obtuse answers here, I don't know. in any case. good day to you sir.
  15. What are you, Like twelve? Seriously, you are going to troll my thread over a mistype? I guess I can understand what the F in your name stands for. Thanks all for the PHP enlightenment at this fine establishment
  16. sorry the relevant errors are at line 16 -- while($row = mysql_fetch_assoc($result)) and line 22 --$randomID = $optionsIDs[array_rand($optionsIDs)];
  17. Hey Psycho, Thanks for replying sorry for the delay. I have played a bit with this but keep getting unrefined variable and unrefined index with the following. maybe I am just missing something small <?php mysql_connect ("localhost", "root", "xxx"); $dataResult="op1"; @mysql_select_db($dataResult) or die( "Unable to select database"); //Function to create the options list. //The $dataResult is expected to be a DB //Result set with fields named 'id' and 'name' function createOptions($dataResult) { $optionsIDs = array(); $optionsHTML = ''; //Process result set into options while($row = mysql_fetch_assoc($result)) { $optionsIDs[] = $row['id']; $optionsHTML .= "<option value='{$row['id']}'>{$row['name']}</option>\n"; } //Get a random ID from the records $randomID = $optionsIDs[array_rand($optionsIDs)]; $optionsHTML = "<option value='{$randomID}'>Random</option>\n" . $optionsHTML; return $optionsHTML; } $query = "SELECT id, name FROM places"; $result = mysql_query($query); $placesOptions = createOptions($result); $query = "SELECT id, name FROM color"; $result = mysql_query($query); $colorOptions = createOptions($result); ?> Places: <select name="places"> <?php echo $placesOptions; ?> </select> Colors: <select name="color"> <?php echo $colorOptions; ?> </select>
  18. Woooosh That was the sound of that going right over my head.. Very interesting though if I understand you. so make the word random in the selection box loaded and ready to go when displayed? so if that is chosen its all set to echo out a variable? am I getting your drift? Sorry I am very very rusty
  19. Hello, I am trying to get a php script to do some things and I need some help. First- is this even possible in PHP alone Second - if it is I sure could use some syntax help. PHP 5.2.17 Mysql 5.1.57 populate 12 drop down boxes // I have given 3 examples here =------------------------------------ A form submit page with 12 mysql populated select drop down boxes Each category has its own table. each table has a id auto increment and name field with each tables first entry as random and the rest of the names to follow. ie Table.Places = $query1 ----------- ID name ---------- 1. Random 2. burnside 3. davenport 4. mumford 5. kenny 6. freer etc Table.color = $query2 ------------ ID name ---------- 1. Random 2. Blue 3. Red 4. Orange Table.state = $query3 -------------- ID name -------------- 1. Random 2. On 3. Off //----------------------------------------------------------------------------------------------------------- //The way I get the drop down populated is: and this part works ok //------------------------------------------------------------------------------------------------------------ $result = mysql_query( "SELECT name FROM places" ) or die("SELECT Error: ".mysql_error()); $options="Select"; while ($row=mysql_fetch_array($result)) { $querry1=$row["name"]; $options.="<OPTION VALUE=\"$query1\">".$query1.'</option>'; //--------------------------------------------------- Next the user selects Random or item in each Drop Down box and hits send. if the selection is Random then the result is a random item displayed if one of the other names are picked then that name is displayed. I want to keep the selections dynamic from the DB so I don't want to hard code in a variable for each name so maybe the choices are: +--------+ +---------+ +--------+ | Random| | Blue | | On | +--------+ +---------+ +--------+ when the page is submitted to tabulate.php ------------------------------------------------------------------------------------ // I know that the syntax is wrong here, This is where i could use some help. //I have put a error check to see if I am passing anything to tabulate.php like this //<?php //var_dump($_POST); //echo '<hr />'; //?> //But I get nothing returned. ----------------------------------------------------------------- If $query1 == [Random] then $query1 = "SELECT name FROM courses ORDER BY RAND()LIMIT 1"; $result = mysql_query($query) or trigger_error(mysql_error()." ".$query1); $row = mysql_fetch_assoc($result); $name = $row["name"]; Echo $name Else Echo $query1 if value Random is selected from $query2 ETC.. etc... Many, Many thanks in advance Bill
  20. Thanks for answering, I guess nothing, It's just less efficient (load time wise) than using txt files that I am doing now.
  21. Thanks here is the dump SET FOREIGN_KEY_CHECKS=0; SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; CREATE TABLE am ( ID smallint(6) NOT NULL AUTO_INCREMENT, am varchar(50) COLLATE latin1_general_ci NOT NULL, PRIMARY KEY (ID) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; CREATE TABLE courses ( ID smallint(6) NOT NULL AUTO_INCREMENT, Course_name varchar(50) COLLATE latin1_general_ci NOT NULL, PRIMARY KEY (ID) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; CREATE TABLE fs ( ID smallint(6) NOT NULL AUTO_INCREMENT, fs varchar(50) COLLATE latin1_general_ci NOT NULL, PRIMARY KEY (ID) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; CREATE TABLE gh ( ID smallint(6) NOT NULL AUTO_INCREMENT, gh varchar(50) COLLATE latin1_general_ci NOT NULL, PRIMARY KEY (ID) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; CREATE TABLE gs ( ID smallint(6) NOT NULL AUTO_INCREMENT, gs varchar(50) COLLATE latin1_general_ci NOT NULL, PRIMARY KEY (ID) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; CREATE TABLE pg ( ID smallint(6) NOT NULL AUTO_INCREMENT, pg varchar(50) COLLATE latin1_general_ci NOT NULL, PRIMARY KEY (ID) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; CREATE TABLE pin ( ID smallint(6) NOT NULL AUTO_INCREMENT, pin varchar(50) COLLATE latin1_general_ci NOT NULL, PRIMARY KEY (ID) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; CREATE TABLE pre ( ID smallint(6) NOT NULL AUTO_INCREMENT, pre varchar(50) COLLATE latin1_general_ci NOT NULL, PRIMARY KEY (ID) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; CREATE TABLE rl ( ID smallint(6) NOT NULL AUTO_INCREMENT, rl varchar(50) COLLATE latin1_general_ci NOT NULL, PRIMARY KEY (ID) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; CREATE TABLE st ( ID smallint(6) NOT NULL AUTO_INCREMENT, st varchar(50) COLLATE latin1_general_ci NOT NULL, PRIMARY KEY (ID) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; CREATE TABLE tee ( ID smallint(6) NOT NULL AUTO_INCREMENT, tee varchar(50) COLLATE latin1_general_ci NOT NULL, PRIMARY KEY (ID) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; CREATE TABLE wind ( ID smallint(6) NOT NULL AUTO_INCREMENT, wind varchar(50) COLLATE latin1_general_ci NOT NULL, PRIMARY KEY (ID) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; SET FOREIGN_KEY_CHECKS=1;
  22. Thanks for replying, it had been a very long time since I messed with ,MySQL query's and table creation. I read as much as I could about creating a database just to pull random data, I found a few sites to look at but they only started me on the path that this mess is in now. I tried to wrap my mind around the Join statements and after about 11 hours I gave up. I will supply any info you need to get me on the right track. I tried to add the other data into the courses table but because of column id which is key, when I added the data, it got placed below the last course data, then the next below that etc... so at the start of pin data there are 24 blank rows in its column and the output would include these null 24 items so that didnt work I then created the twelve other tables and here I am. What info would you require? Thanks again
  23. Yep, this isnt a very good DB structure for pulling random data. 1 id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE pin ALL NULL NULL NULL NULL 4 100.00 Using temporary; Using filesort 1 SIMPLE tee ALL NULL NULL NULL NULL 4 100.00 Using join buffer 1 SIMPLE wind ALL NULL NULL NULL NULL 4 100.00 Using join buffer 1 SIMPLE fs ALL NULL NULL NULL NULL 4 100.00 Using join buffer 1 SIMPLE gs ALL NULL NULL NULL NULL 4 100.00 Using join buffer 1 SIMPLE courses ALL NULL NULL NULL NULL 23 100.00 Using join buffer I tried to build a table that used all data in different columns but it kept returning null data sometimes. I read that building a table with a ID1 (ID)2 etc was the best way to go but I am not sure. Any ideas on this?
  24. Well as I thought, I must have the tables set wrong. I have about 12 calls the the db for randomized data. if I use the select like this: $query = "SELECT course_name, pin, tee, wind, fs, gs FROM courses, pin, tee, wind, fs, gs ORDER BY RAND()LIMIT 1"; And fill it up with my requests, It chokes after adding more than 8 table query's. But if I split it up like I will show below, It works, but is only slightly faster than just using text files. There has to be a better more efficient way of doing this but I could use a few pointers in the right direction Thanks in advance heres the rest of the ugliness $query = "SELECT course_name, pin, tee, wind, fs, gs FROM courses, pin, tee, wind, fs, gs ORDER BY RAND()LIMIT 1"; $result = mysql_query($query) or trigger_error(mysql_error()." ".$query); $row = mysql_fetch_assoc($result); $course = $row["course_name"]; $pin = $row["pin"]; $wind = $row["wind"]; $tee = $row["tee"]; $fs = $row["fs"]; $gs = $row["gs"]; $query = "SELECT gh FROM gh ORDER BY RAND()LIMIT 1"; $result = mysql_query($query) or trigger_error(mysql_error()." ".$query); $row = mysql_fetch_assoc($result); $gh = $row["gh"]; $query = "SELECT rl FROM rl ORDER BY RAND()LIMIT 1"; $result = mysql_query($query) or trigger_error(mysql_error()." ".$query); $row = mysql_fetch_assoc($result); $rl = $row["rl"]; $query = "SELECT st FROM st ORDER BY RAND()LIMIT 1"; $result = mysql_query($query) or trigger_error(mysql_error()." ".$query); $row = mysql_fetch_assoc($result); $st = $row["st"]; $query = "SELECT am FROM am ORDER BY RAND()LIMIT 1"; $result = mysql_query($query) or trigger_error(mysql_error()." ".$query); $row = mysql_fetch_assoc($result); $am = $row["am"]; $query = "SELECT pg FROM pg ORDER BY RAND()LIMIT 1"; $result = mysql_query($query) or trigger_error(mysql_error()." ".$query); $row = mysql_fetch_assoc($result); $pg = $row["pg"]; $query = "SELECT pre FROM pre ORDER BY RAND()LIMIT 1"; $result = mysql_query($query) or trigger_error(mysql_error()." ".$query); $row = mysql_fetch_assoc($result); $pre = $row["pre"]; ?> And here is how the results are displayed: <table border="0" width="100%" cellpadding="3" cellspacing="3"> <tr> <td><b>Courses</b></td> <td><b>Tee Box</b></td> <td><b>Wind Speed</b></td> <td><b>Pin Location</b></td> <td><b>Fairway Speed</b></td> <td><b>Green Speed</b></td> <td><b>Green Hardness</b></td> <td><b>Rough Length</b></td> <td><b>Swing Type</b></td> <td><b>Aiming Mode</b></td> <td><b>Putting Grid</b></td> <td><b>Previews</b></td> </tr> <td><?php echo $course; ?></td> <td><?php echo $tee; ?></td> <td><?php echo $wind; ?></td> <td><?php echo $pin; ?></td> <td><?php echo $fs; ?></td> <td><?php echo $gs; ?></td> <td><?php echo $gh; ?></td> <td><?php echo $rl; ?></td> <td><?php echo $st; ?></td> <td><?php echo $am; ?></td> <td><?php echo $pg; ?></td> <td><?php echo $pre; ?></td>
×
×
  • 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.