Howdy Folks, I need some major help with MySQL and PHP. I have been able to import a file into MySQL using this http://ceo4u.com/data/ Now I just need to figure out how to call it and sort it using PHP. It is one table with 5 fields. `magazine`, `date`, `article`, `category`, `entry_id_num` I have had little success with MySQL in the past. I would sure like to get some help from one of the experts here.
I'am not sure what do you want to do with that file? How do you think.. "figure out how to call it and sort it using PHP" there is lot of procedures of how to deal with data from Mysql.. what exactly do you need to do?
Sorry for being vague. What I want to do is display on a web page the info in the database. First display everything, the have a way to select specifics. such as the magazine, or the category, or both, then list them by date. Does this help?
ok.. so.. you need to find a way to select certain fields from database and display it on the web page.. if this is correct you will need: - write a srcipet that connects PHP to your database - once you have connected to database (DB) you will need to write a certain QUERY that describes what you want to pull from DB - then you will have those data in one array (variable), and you could put it on the website where you want. Now.. you must see some tutorial of HOW TO CONNECT to database. Look at this one: http://www.php-mysql-tutorial.com/ Make sure to look at the chapters: - Connect to MySQL Database and - Get Data From MySQL Database Good luck
Thats a great tutorial site, thanks! I must be doing something wrong, because I get an error while following the instructions in your link. <?php include 'config.php'; include 'opendb.php'; $query = "SELECT * FROM $dbname"; $result = mysql_query($query); [COLOR="Red"]while($row = mysql_fetch_row($result))[/COLOR] { $mag = $row[0]; $date = $row[1]; $title = $row[2]; $cat = $row[3]; echo "Name :$mag <br>" . "Subject : $date<br>" . "Message : $title <br><br>" . "Subject : $cat<br>" ; } include 'closedb.php'; ?> Code (markup): This gives me the following error. Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in . . . line 8 Line 8 is the red line above. Thanks
This line suggests you are trying to select fields from a database and not a table: $query = "SELECT * FROM $dbname"; Code (markup): Can you confirm whether the value within the variable $dbname is a table Brew
I have changed where it said $dbname to the name of the table, but I still get the same error for the same line.
That error message means that the SQL query failed. Do an echo "SELECT * FROM $dbname"; to see what SQL query is being executed and see if it makes sense.
Change this line: $result = mysql_query($query); PHP: to this: if ( !($result = @mysql_query( $query ) ) ) die( mysql_error() ): PHP: Let us know the error that gets displayed. Brew
Well, here is my current code. <?php include 'config.php'; include 'opendb.php'; $query = "SELECT * FROM 'table_name'"; if ( !($result = @mysql_query( $query ) ) ) die( mysql_error() ); while($row = mysql_fetch_row($result)) { $mag = $row[0]; $date = $row[1]; $title = $row[2]; $cat = $row[3]; echo "Name :$mag <br>" . "Subject : $date<br>" . "Message : $title <br><br>" . "Subject : $cat<br>" ; } include 'closedb.php'; ?> PHP: My error is the following: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''table_name'' at line 1 Am I just screwing this all up? <?php include 'config.php'; include 'opendb.php'; $query = "SELECT * FROM 'table_name'"; $result = mysql_query($query); echo "SELECT * FROM 'table_name'"; include 'closedb.php'; ?> PHP: Using the code above I get SELECT * FROM 'table_name' displayed on the screen, hey at least it wasn't an error.
In PHP/MySQL you use `Table_Name`, not 'Table_Name'. `table` - for table names or column names. 'value' - for strings like SELECT * FROM `table` WHERE `column` = 'string'
Would you look at that replacing the " ' " with a " ` " worked! I don't know where they are on the keyboard, but it still worked! Thanks guys! I will let you know if I have any more troubles.