gavenf Posted June 9, 2007 Share Posted June 9, 2007 Ok I have a problem. I have a dump file out of mysql that I want to use to create a search page from for my site. I only want to search the company name the position or the country at the moment. So depending on what is searched for in either of those three I want o return a result on a page in a table type format. The sql file is attached as sql.txt [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/54850-mysql-dump-fie-into-php-search-page/ Share on other sites More sharing options...
simcoweb Posted June 11, 2007 Share Posted June 11, 2007 <?php // select all from your database and display in a table // first you have to make sure you're connected to the database which can be done // using a separate file that has that info and include it like this include 'dbinfo.php'; // now that you are connected you can query the database $sql = "SELECT * FROM tablenamegoeshere"; // that * means to summon everything. Now we execute the query and put all the data into a variable $results $results = mysql_query($sql) or die(mysql_error()); // the $results variable now contains all your field data which needs to be separated into the proper columns // now we are going to start our display of the data in a table and rows echo "<table width='100%' border='1'>"; echo "<th>Field One</th><th>Field Two</th><th>Field Three</th>"; // The <th> tag makes a name at the top of each column for the field // now we use a while loop to create as many table rows as needed and as many table cells <td> as needed while ($row = mysql_fetch_array($results)) { echo "<tr><th>".$row['fieldname1']."</td><td>".$row['fieldname2']."></td><td>".$row['fieldname3']."</td></tr>"; } // now we close the table tag echo "</table>\n"; // my example shows just 3 table fields. However, you can use as many as you need with the only problem being // how much space you have width wise. So, if you had 30 fields then obviously you can't have them go all // in one row. You may have to go vertical with those. // now all you need to do is close the script. This is a very simple and plain search and display. You can use // it as a guide on how to do it. If you need more specific data and not everything from the database then use // this method for the search $sql = "SELECT something, something2, something3, etc FROM nameoftable WHERE somefield='someinfo'"; // that would narrow it down. You'd use the same display method if you wish. ?> Link to comment https://forums.phpfreaks.com/topic/54850-mysql-dump-fie-into-php-search-page/#findComment-272494 Share on other sites More sharing options...
gavenf Posted June 12, 2007 Author Share Posted June 12, 2007 Thanks for the code. I will take a look at it today. Link to comment https://forums.phpfreaks.com/topic/54850-mysql-dump-fie-into-php-search-page/#findComment-272774 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.