Jump to content

Recommended Posts

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

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

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.