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>

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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