Jump to content

Grabbing Html Table and putting it into Drop down Box!Emergency!


Deanznet

Recommended Posts

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>

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???

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>

 

Archived

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

×
×
  • 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.