Deanznet Posted September 28, 2010 Share Posted September 28, 2010 This is what i have.. I basicly need to take the Make and Model And Year Not the TYPE that needs to be left out and combine them into a drop down list. So example below would be like this Yamaha WR450F 2003-2006 Yamaha YZ450F 2003-2005 <table> <tr> <th>Type</th> <th>Make</th> <th>Model</th> <th class='tar'>Year</th> </tr> <tr class='even'> <td>Offroad</td> <td>Yamaha</td> <td>WR450F</td> <td class='tar'>2003-2006</td> </tr> <tr class='odd'> <td>Offroad</td> <td>Yamaha</td> <td>YZ450F</td> <td class='tar'>2003-2005</td> </tr> </table> Link to comment https://forums.phpfreaks.com/topic/214584-grabbing-html-table-and-putting-it-into-drop-down-boxemergency/ Share on other sites More sharing options...
Deanznet Posted September 29, 2010 Author Share Posted September 29, 2010 BUMP Link to comment https://forums.phpfreaks.com/topic/214584-grabbing-html-table-and-putting-it-into-drop-down-boxemergency/#findComment-1117229 Share on other sites More sharing options...
Psycho Posted September 29, 2010 Share Posted September 29, 2010 Um, I don't expect this is what you are looking for, but you didn't do a very good job of explaining your problem: <select> <option value="Yamaha WR450F 2003-2006">Yamaha WR450F 2003-2006</option> <option value="Yamaha WR450F 2003-2006">Yamaha WR450F 2003-2006</option> </select> I assume the values in the table are coming from somehwere, but you don't provide that information. Are you reading it from a database, are you reading a file with the actual HTML above, or what??? Link to comment https://forums.phpfreaks.com/topic/214584-grabbing-html-table-and-putting-it-into-drop-down-boxemergency/#findComment-1117233 Share on other sites More sharing options...
the182guy Posted September 29, 2010 Share Posted September 29, 2010 If you have some raw HTML with all the vehicle data in it and you want to extract it and insert into a dropdown, then something like this should do it <?php$html = file_get_contents('vehicles.html'); // get the raw html// create the DOM object and load the retrieved html$dom = new domDocument;$dom->loadHTML($html);$tables = $dom->getElementsByTagName('table');$rows = $tables->item(0)->getElementsByTagName('tr');$first = true;$dropdownOptions = '';foreach ($rows as $row){// skip the first row because it's the table headerif($first == true){ $first = false; continue;}$cols = $row->getElementsByTagName('td');// build the MAKE MODEL YEAR string$str = $cols->item(1)->nodeValue . ' ' . $cols->item(2)->nodeValue . ' ' . $cols->item(3)->nodeValue;$dropdownOptions .= "<option value=\"$str\">$str</option>";}?><select name="vehicles"><?php echo $dropdownOptions; ?></select> Link to comment https://forums.phpfreaks.com/topic/214584-grabbing-html-table-and-putting-it-into-drop-down-boxemergency/#findComment-1117247 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.