Okay... SPOKE TOO SOON! LOL I got snagged... I tried to make the table look "better" and now I can't get it to work It is only doing the headers... :bemused:

<?php 
$server = "localhost";  
$user = "user";
$password = "password";
$database = "database"; mysql_connect($server, $user, $password) or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); ; $i=0; while ($i < $num) { $name=mysql_result($result,$i,"name"); $meaning=mysql_result($result,$i,"meaning"); $variations=mysql_result($result,$i,"variations"); $gender=mysql_result($result,$i,"gender"); $origin=mysql_result($result,$i,"origin"); $ratings=mysql_result($result,$i,"ratings"); echo " <div align=\"center\"> <center> <table border=\"0\" width=\"100%\" bgcolor=\"#E3D8E9\" cellspacing=\"1\" cellpadding=\"0\"> <tr> ++$i; } ?>

    thats strange, i dont see anything wrong in there.

    try to echo $num before you go into the loop, maybe there was a problem with that and there are no results.. thats about all i can think of from looking at it.

      ok, i see what the problem is. i didnt look hard enough last time.

      you pull the results out of the database using
      $name=mysql_result($result,$i,"name");
      $meaning=mysql_result($result,$i,"meaning");
      $variations=mysql_result($result,$i,"variations");
      $gender=mysql_result($result,$i,"gender");
      $origin=mysql_result($result,$i,"origin");
      $ratings=mysql_result($result,$i,"ratings");

      but in the html code, you are still echo'ing the $_POST variables, now you will want to replace that stuff with $name, $meaning etc....

      it is actually drawing 100 table rows, but they have no information in them because the post variables are empty.

        thank you, im glad ive been able to help.

        you could probably write a little script to go thru that text and format each line and insert it into the database.

        it looks to be tab delimited so if you want a few functions that might get the job done, here is a list:

        [man]file[/man] - reads a file into an array, each line gets an array index
        [man]explode[/man] - splits up a string by a character. you could explode by a tab to get each part of a line into a variable
        [man]list[/man] - useful in combination with explode
        [man]fgetcsv[/man] - an alternative to the explode function
        [man]foreach[/man] - useful to loop thru an array.

        another note: in php, a tab character (since it is not really viewable) is represented by a \t

        heres what the program may do.

        read the text file into the array.

        iterate over each line, parse the line assigning each portion of the line to the appropriate variable ($name, $gender...)
        formulate a mysql insert query
        insert the data.
        move on to the next line
        continue until you reach end of array

        i suppose thats enough homework to keep you busy for at least half day 😉

          Holy cow I am confused! LOL

          I am really not that quick, I just can't stop till I get it right. 😃

            8 days later

            Originally posted by drew010

            SELECT * FROM names WHERE name LIKE 'A%' ORDER BY name ASC;
            //this assumes names start with caps

            or to list all names of one gender in alpha order

            SELECT * FROM names WHERE gender = 'Male' ORDER BY name ASC;
            //assumes gender is stored as Male or Female, not M or F

            Is there anyway I can do like the gender male and unisex? Or female and unisex?

              5 days later

              yes you could do something like that, all it would require is storing the name with a gender unisex instead of male or female. then when you search it can be like
              SELECT * FROM names WHERE gender = 'Male' OR gender = 'Unisex'

                Well I have the database set up now as the gender can be one of three; male, female or unisex.

                I tried something like you posted, although I used AND instead of OR. 🙂

                Thanks Drew!!!!

                  Write a Reply...