Hello, I'm not very good with PHP, but I need to make a change to almost every page on my site, and I think using a PHP statement would be the fastest way. I was hoping some one here can help me figure this out. My site is a WordPress blog. I want to do the following. I want to add a little bit of more info to each of my posts. I have about 50 different categories, and depending on the category of the post I'm going to add different info. Now, I have saved the info that I want to add in different .txt files. (one .txt file for each category). I already know how to "get" a .txt file and display it in the location that I want. But I only know how to get the same text file each time. The problem that I'm having is, displaying the appropriate .txt file for each category. I was thinking about a "IF" or "Switch" statement, but having more then 50 different categories, I would have to write more then 50 lines of "IF" or "Switch" code...For Example switch (category) { case category1: code; break; case category2: code; break; . . . . default: code; } So, is there a different way of doing this, without using a "IF" or "Switch" statement????? THANK YOU.
does the text file have the info you want to show based on the catagory? If so, you could grab the catagory name through a wordpress command, and call the txt file like so $txtcontent = readfilefunction($catagoryname.".txt"); any time your page loads it whoudl read the catagory name, and call a filename with the same catagory name plus the .txt extension. Is that a solution?
Thanks darkmessiah, I'm going to try your code and see if it works. But how do I specify the location of the .txt file. Currently the location of the .txt is - http://www.mywebsite.com/info/category1.txt
thats going to be tricky.. the file call will be the full path of the server folders. Personally, I would create a mysql table with this info and call the field(catagory) that way. Heck of a lot better than messing around with the filesystem.
darkmessiah Thanks again for your quick reply. Sorry that I keep asking this questions....but I'm really not very good with PHP and SQL. OK, so I would create a table called, lets say, "MoreInfo". The table is going to have two fields, "Category" and "Info". In the "Category" filed I will have all the categories and in the "Info" field all the additional info that goes with the appropriate categories. But then, I'm assuming that I would have to use a different statement, correct?
CREATE TABLE `yourdbname`.`MoreInfo` ( `id` INT( 80 ) NOT NULL AUTO_INCREMENT PRIMARY KEY , `Catagory` TEXT NOT NULL ) ENGINE = MYISAM Code (markup): now your insert a catagory name along with the data you want to display for that catagory. when you need the info for the catagory, you select the catagory name and read in the data it retrieves.. This is not the most elegant way to do this, but it's good enough.
I have created the database, but do I compare the post category with the SQL field "category" and get the "info" field that belong to that category?
sql statemnt to get catagory info from db, there was a slight mistake in,the table, you would need 3 fields.. and ID , Catagor name, and Content you insert something like this "INSERT INTO `MoreInfo` VALUES('', '{$catagoryname}', '{$content}');" "SELECT * FROM `MoreInfo` WHERE `catagory` = '{$wpcatagorname}' LIMIT 1" $row = fetch_row($sqlqueryresult); $contenttobeshownonsite = $row['content'];
Thanks for all the replys, I have created my table "wp_info" with the following fields: ID_info (PK) cat_id fullname_value founded_value Now each post on my site is also assigned to a category, and each category has it's own cat_id. I want to compare the cat_id of each post to the cat_id in the SQL table "wp_info" and display the values of the 2 fields "fullname_value" and "founded_value". I'm just getting confused with the PHP code. I'm not sure how to compare the cat_id from the post with the cat_id in the SQL table and also how to display the fullname_value and founded_value for each category. Any help will be greatly appreciated.
$cat_id = wordpressfuntiontogetcatid(); do a sql SELECT query on wp_info, SELECT from wp_info WHERE cat_id = $cat_id do a fetch row off the returned result from the query. the result from fetched row command will be an array.. you can access each field of the table like so $row['fullname_value'] $row['founded_value']