PHP - Storing Some Values From A Php-array Into Mysaql-db Fails
i want to store some data that i have gained from a request at the planetfile of openstreetmap: so i have set up a database on my opensuse 13.1
i have created a db called test on the mysql-server on my opensuse: CREATE TABLE `pois` ( `id` bigint(20) unsigned NOT NULL, `lat` float(10,7) NOT NULL, `lon` float(10,7) NOT NULL, PRIMARY KEY (`id`) ) CREATE TABLE `pois_tag` ( `poisid` int(11) NOT NULL DEFAULT '0', `tagname` varchar(45) NOT NULL DEFAULT '', `tagvalue` varchar(255) DEFAULT NULL, PRIMARY KEY (`poisid`,`tagname`) ) Where each tagname/value pair is stored as a row in a separate table with the pois id Processing would be like this <?php $db = new mysqli(localhost,root,rimbaud,'test'); // use your credentials $xmlstr = <<<XML <data> <node id="2064639440" lat="49.4873181" lon="8.4710548"> <tag k="amenity" v="restaurant"/> <tag k="cuisine" v="turkish"/> <tag k="email" v="info@lynso.de"/> <tag k="name" v="Kilim - Café und Bar Restaurant"/> <tag k="opening_hours" v="Su-Th 17:00-1:00; Fr, Sa 17:00-3:00"/> <tag k="operator" v="Cengiz Kaya"/> <tag k="phone" v="06 21 - 43 755 371"/> <tag k="website" v="http://www.kilim-mannheim.de/"/> </node> <node id="2126473801" lat="49.4851170" lon="8.4756295"> <tag k="amenity" v="restaurant"/> <tag k="cuisine" v="italian"/> <tag k="email" v="mannheim1@vapiano.de"/> <tag k="fax" v="+49 621 1259 779"/> <tag k="name" v="Vapiano"/> <tag k="opening_hours" v="Su-Th 10:00-24:00; Fr-Sa 10:00-01:00"/> <tag k="operator" v="Vapiano"/> <tag k="phone" v="+49 621 1259 777"/> <tag k="website" v="http://www.vapiano.de/newsroom/?store=29"/> <tag k="wheelchair" v="yes"/> </node> <node id="667927886" lat="49.4909673" lon="8.4764904"> <tag k="addr:city" v="Mannheim"/> <tag k="addr:country" v="DE"/> <tag k="addr:housenumber" v="5"/> <tag k="addr:postcode" v="68161"/> <tag k="addr:street" v="Collinistraße"/> <tag k="amenity" v="restaurant"/> <tag k="name" v="Churrascaria Brasil Tropical"/> <tag k="phone" v="+496211225596"/> <tag k="wheelchair" v="limited"/> </node> <node id="689928440" lat="49.4798794" lon="8.4853418"> <tag k="amenity" v="restaurant"/> <tag k="cuisine" v="greek"/> <tag k="email" v="epirus70@hotmail.de"/> <tag k="fax" v="0621/4407 762"/> <tag k="name" v="Epirus"/> <tag k="opening_hours" v="Mo-Sa 12:00-15:00,18:00-24:00"/> <tag k="phone" v="0621/4407 761"/> <tag k="smoking" v="separated"/> <tag k="website" v="http://epirus-ma.blogspot.com/"/> <tag k="wheelchair" v="no"/> </node> <node id="689928445" lat="49.4799409" lon="8.4851357"> <tag k="amenity" v="restaurant"/> <tag k="cuisine" v="italian"/> <tag k="email" v="gianlucascurti@ristorante-augusta.de"/> <tag k="name" v="Ristorante Augusta"/> <tag k="opening_hours" v="Mo-Fr 12:00-14:00,18:00-23:00;Su 12:00-14:00,18:00-23:00"/> <tag k="phone" v="0621 449872"/> <tag k="website" v="ristorante-augusta.com/"/> <tag k="wheelchair" v="no"/> </node> </data> XML; $fields = array('id','name','lat','lon'); $xml = simplexml_load_string($xmlstr); // // PROCESS XML RECORDS // $poisdata = array(); $tagdata = array(); foreach ($xml->node as $node) { $nodedata = array_fill_keys($fields,''); $nodedata['id'] = intval($node['id']); $nodedata['lat'] = isset($node['lat']) ? floatval($node['lat']) : 0; $nodedata['lon'] = isset($node['lon']) ? floatval($node['lon']) : 0; $poisdata[] = vsprintf("(%d, %10.7f, %10.7f)", $nodedata); foreach ($node->tag as $tag) { $k = (string)$tag['k']; $v = (string)$tag['v']; $tagdata[] = sprintf("(%d, '%s', '%s')" , $nodedata['id'] , $db->real_escape_string($k) , $db->real_escape_string($v)); } } // // STORE THE DATA // $sql = "REPLACE INTO pois ('id','lat','lon') VALUES\n" . join(",\n", $poisdata); $db->query($sql); $sql = "REPLACE INTO pois_tag (poisid, tagname, tagvalue) VALUES\n" . join(",\n", $tagdata); $db->query($sql); // // DISPLAY THE DATA // $currentTags = array(); $sql = "SELECT DISTINCT tagname FROM pois_tag ORDER BY tagname = 'name' DESC, tagname"; $res = $db->query($sql); while (list($tn) = $res->fetch_row()) { $currentTags[] = $tn; } $thead = "<tr><th>id</th><th>lat</th><th>lon</th><th>" . join('</th><th>', $currentTags) . "</th></tr>\n"; $currid = $currlat = $currlon = 0; $sql = "SELECT p.id, lat, lon, tagname, tagvalue FROM pois p LEFT JOIN pois_tag t ON t.poisid = p.id ORDER BY p.id"; $res = $db->query($sql); $tdata = ''; while (list($id, $lat, $lon, $t, $v) = $res->fetch_row()) { if ($currid != $id) { if ($currid) { $tdata .= "<tr><td>$currid</td><td>$currlat</td><td>$currlon</td><td>" . join('</td><td>', $poisrow) . "</td></tr>\n"; } $currid = $id; $currlat = $lat; $currlon = $lon; $poisrow = array_fill_keys($currentTags,''); } $poisrow[$t] = $v; } $tdata .= "<tr><td>$currid</td><td>$currlat</td><td>$currlon</td><td>" . join('</td><td>', $poisrow) . "</td></tr>\n"; ?> <html> <head> <meta name="generator" content="PhpED 12.0 (Build 12010, 64bit)"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Tags</title> <meta name="author" content="Barand"> <meta name="creation-date" content="06/04/2014"> <style type="text/css"> body, td, th { font-family: arial, sans-serif; font-size: 10pt; } table { border-collapse: collapse; } th { background-color: #369; color: white; padding: 5px 2px; } td { background-color: #EEE; padding: 2px; } </style> </head> <body> <table border='1'> <?php echo $thead, $tdata; ?> </table> </body> </html> leeeds to the following errors.... PHP Fatal error: Call to a member function fetch_row() on a non-object in /home/martin/php/osm_200.php on line 121 martin@linux-70ce:~/php> php osm_200.php PHP Notice: Use of undefined constant localhost - assumed 'localhost' in /home/martin/php/osm_200.php on line 3 PHP Notice: Use of undefined constant root - assumed 'root' in /home/martin/php/osm_200.php on line 3 PHP Notice: Use of undefined constant rimbaud - assumed 'rimbaud' in /home/martin/php/osm_200.php on line 3 PHP Fatal error: Call to a member function fetch_row() on a non-object in /home/martin/php/osm_200.php on line 121 martin@linux-70ce:~/php> so what goes wrong here...? Similar TutorialsHey guys, What would you recommend to store db values for later? the only thing I can come up with is doing it this way: $result = mysql_query("SELECT * FROM users WHERE name='$user'"); while($row = mysql_fetch_array($result)) { } { and then using the $row['dbvariable'] later is that the best way? Hi all, I need to create a table which holds a list of values, for EG 1 PHP 2 MySQL 3 HTML 4 JS The reason im doing this is so when a user visits X page on my site, they are presented with a list of possible options which they can tick, for instance if you were asked what languages your fluent with you would tick HTML and JS (or w/e applies to you) What would be the best way of constructing the table? Thanks Hi guys, Im currently doing a project for college and i have experienced some problems with saving my php drop down values to my database. im am getting no error but my values are not being stored to my db.If anyone could help me or point me in the correct direction then id be grateful. Ive attached my code. This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=311333.0 This is more of a database architect question.
I am building a CMS for website development. I am ready to use it for the first time on one of my clients. Now, my issue is is how to set up some or one of my table(s) for some areas that my client wants to be able to change in the admin section.
In their website on the front page, I put together this nice block slider. Its 6 blocks with text, a background image and nice effects. At first it was always going to be static, which was no issue at all, but later they came to me and asked if they could be able to change words in the boxes themselves in the admin section..
Of course this can be easily done by creating a table that is associated with this home page block thing and each row in the table will correspond to one of the blocks on the home page.
But I believe there might be an easier way to store this type of data without having to create another table for every feature the client wants to edit, for example they also want to be able to edit a slider on another page.
The WordPress database then came into my mind and how they store most of their data as JSON. So I was then thinking of creating a table named 'modules' for examples with three columns (id, title, data). Then inside the data column store the editable fields as a JSON string object.
For example a row could like like :
1, "Front Page Box Slider", {"slider-home" : [ {"data" : "value", "img_1", "value1"}, {"data" : "value", "img_2", "value2"} ]}
I've been doing a bit of research on this and people have just been saying, never do this if you do want your data to be searched through, which I don't.
Can anyone tell me why or why not I should do this, or maybe a better solution to my problem?
Thank you
Edited by carlosmoreeira, 17 September 2014 - 07:37 PM. Hello! I am designing a user registration form which has some radio buttons for people to select. I am confused as to how I should store the value selected by the user into the database. Here is my code, just in case. <li id="li_2" > <label class="description" for="element_2">I am a </label> <span> <input id="element_2_1" name="element_2" class="element radio" type="radio" value="1" /> <label class="choice" for="element_2_1">Student</label> <input id="element_2_2" name="element_2" class="element radio" type="radio" value="2" /> <label class="choice" for="element_2_2">Staff</label> <input id="element_2_3" name="element_2" class="element radio" type="radio" value="3" /> <label class="choice" for="element_2_3">Member</label> <input id="element_2_4" name="element_2" class="element radio" type="radio" value="4" /> <label class="choice" for="element_2_4">Other</label> </span> </li> i have a dictionary - THIS IS obviously a python dictionary an this has approx 8 000 lines with records [/CODE] $ python printer.py {'url': 'http://www.site1_com' 'cname': 'butcher', 'name': 'cheng', 'email': 'mail1@hotmail.com'} {'url': 'http://www.site2_com' 'cname': 'dilbert', 'name': 'James', 'email': 'mail2@hotmail.com'} [code=auto:0]i have a mysql-db up and runing in my opensuse there i have created a db with the fields url cname name i use the import MySQLdb i studied this documentation he http://stackoverflow...abase-in-python but i think this goes a bit over my head. - well how can i get the data ( in other words the dictionary) into the database? love to hear from you greetings Hi there, I am working on a PHP web form and I have a very simple situation I guess, I have a variable named: $MyVal When I do print_r($MyVal); To see whats inside, I get: SimpleXMLElement Object ( [0] => 8.23 ) Now I am assigning this variable into a session variable so that I can do calculations with it. So I assign: $_SESSION['MySesVal'] = $MyVal; But after assigning to session variable, when I do my calculations: $finalValue = $_SESSION['MySesVal'] * 4; I get 0. So is it because the actual $MyVal variable has some XML stuff as: SimpleXMLElement Object ( [0] => 8.23 ) So what is the right way to properly assign $MyVal variable to a session variable to do calculations. Please reply. All comments and feedbacks are always welcome. Thank you! helllo dear php-commmunity new to Ruby - i need some advices - i plan to do some requests in osm-files. (openstreetmap) Question - how can i store the results on a Database - eg mysql or - (if you prefer postgresql) - note: my favorite db - at least at the moment is mysql here the code require 'open-uri' require "net/http" require 'rexml/document' def query_overpass(object_type, left,bottom,right,top, key, value) base_url = "http://www.overpass-api.de/api/xapi?" query_string = "#{object_type}[bbox=#{left},#{bottom},#{right},#{top}][#{key}=#{value}]" url = "#{base_url}#{URI.encode(query_string)}" resp = Net::HTTP.get_response(URI.parse(url)) data = resp.body return data end overpass_result = REXML::Document.new(query_overpass("node", 7.1,51.2,7.2,51.3,"amenity","restaurant|pub|ice_cream|food_court|fast_food|cafe|biergarten|bar|bakery|steak|pasta|pizza|sushi|asia|nightclub")) overpass_result.elements.each('osm/node') {|x| if !x.elements["tag[@k='name']"].nil? print x.elements["tag[@k='name']"].attributes["v"] end print " | " if !x.elements["tag[@k='addr:postcode']"].nil? print x.elements["tag[@k='addr:postcode']"].attributes["v"] print ", " end if !x.elements["tag[@k='addr:city']"].nil? print x.elements["tag[@k='addr:city']"].attributes["v"] print ", " end if !x.elements["tag[@k='addr:street']"].nil? print x.elements["tag[@k='addr:street']"].attributes["v"] print ", " end if !x.elements["tag[@k='addr:housenumber']"].nil? print x.elements["tag[@k='addr:housenumber']"].attributes["v"] end print " | " print x.attributes["lat"] print " | " print x.attributes["lon"] print " | " if !x.elements["tag[@k='website']"].nil? print x.elements["tag[@k='website']"].attributes["v"] end print " | " if !x.elements["tag[@k='amenity']"].nil? print x.elements["tag[@k='amenity']"].attributes["v"] print " | " end puts } look forward to hear from you again - i would love to store it on a mysql - database - if possible. If you would prefer postgresql - then i would takte this one.... ;-) look forward to hear from you again - i would love to store it on a mysql - database - if possible. If you would prefer postgresql - then i would takte this one.... ;-) well - i guess that the answer to this will be the same no matter what language we are using. If the db is a sql database we need to design the database schema and create the tables in the database. The first step in accessing a db in our code is to get a connection to it. If ruby is our choice of language, a search for "ruby sql connector" will give us lots of options to read about. Well - we also can do it in PHP. What do you think!? Next, based on the schema we have designed, we need to create queries suitable for storing the data. We will likely need to consider our transactional model. Again, searching "ruby sql transactional model" will give us plenty of food for thought. Finally, we may want or need to close the connection to the database. I created a simple search box which will query my table and match the input value to one of my columns. two of these columns store comma separated values. if i query a column other than a column which stores my csv i can see my search results. if i query a column which stores my csv i will not see results unless the search value matches the first value within the column. how would i be able to get say the second or third or forth value. here is the code i am using to query the table any help would be appreciated thanks. Code: [Select] $q = $this->db->query("SELECT * FROM table WHERE col1 LIKE 'searchvalue'". " OR col2 LIKE 'searchvalue'". " OR col3 LIKE 'searchvalue'". " OR col4 LIKE 'searchvalue'". " OR FIND_IN_SET('searchvalue', col5) > 0 ". " OR FIND_IN_SET('searchvalue', col6) > 0"); Hello again, guys! I have a couple of questions that I hope anyone can answer. I am making a form that is storing the information in a database, and in this form I also want images to be uploaded. I want to make a function that allows the user to upload as many images as they would like to have in their ad on my website, and I also need something that can handle the upload process, and see how many images the user is trying to upload. Any easy solutions for this? I also have another question: As you can see on the example image underneath this text, I have a form with multiple inputs where the user is suppose to choose how many inputs they want to fill in themself. How should I store this information in the database, and how can I make a script that detects how many of the forms the user actually filled? I hope you guys understood what I was trying to say, and I thank you all anyways. Underneath you can see an image of my forms. Example image: Cheers, Marius Hey, I have this code below which seems to completely fail sending my laptop cpu fan on a frenzy. All I am wanting to do is find whether the id in the url is located inside the array below else state its not in an error saying its not a valid id (for people who change the url shown below). At the moment it doesnt like the else statement if the isset clause it not true. (I have also tried, array_key_exists) All I can think is that it get stuck looking for an id that doesnt exist inside the array but keeps searching though I dont know much about arrays etc. Besides this when a id is inside the array the script works like I want it to. Any ideas would be much appreciated as this is hold me back at the moment Code: [Select] //url: http://localhost/website/shop.php?id=10197 // Array is built from table prior to this as it will grow in size $_SESSION['storesProducts'] = Array ( [10197] => 0 [10198] => 0 [10199] => 1 [10200] => 1 [10201] => 1 [10202] => 1 [10205] => 0 [10206] => 1 [10207] => 1 ) if(isset($_SESSION['storesProducts'][$id])){ $storesProducts = $_SESSION['storesProducts'][$id]; if($storesProducts == 0){ $list = $this->displayCategories($id); }else{ $createProducts = new constructProducts(); $products = $createProducts->pagination($id); } }else{ $list = "ITS NOT HERE"; } $output = new outputShop(); $output->display($list, $products); Hello all, I'm currently working on a project and it is the first time I have had to store/retrieve an array with PHP and MySQL. Basically its a website that has a list of discounts/coupons on it. People can register and submit their discounts and such. I am storing an array for who is eligible for the discount, as well as which categories the discount falls under. I did some googling and there seems to be tons of thoughts on the best way to do this. Some say to use implode/explode, some say to serialize/unserialize, I was just wondering if there is a common, concrete way to do this? I will need to be able to search the array for its contents. So if children are eligible for the discount, I need to be able to store that in a database, retrieve it later, and search it for only "Children" so I can display the discounts available only to children. If someone could please advise the best way to do this and post some examples, it would be greatly appreciated. I learn best with examples that are explained properly. Script:
<?php // For example, the entries in the table. $entry1 = "text1"; $entry2 = "text2"; $entry3 = "text3"; // For example, the ID numbers in the table. $value1 = "140"; $value2 = "141"; $value3 = "142"; echo "<form method='POST' action='" . $_SERVER['PHP_SELF'] . "'>"; echo "<input type='checkbox' name='hashtag_modify_checkbox[]' value='" . $value1 . "' />"; echo "Modify"; echo "<input type='text' name='hashtag_name[]' value='" . $entry1 . "' />"; echo "<input type='checkbox' name='hashtag_modify_checkbox[]' value='" . $value2 . "' />"; echo "Modify"; echo "<input type='text' name='hashtag_name[]' value='" . $entry2 . "' />"; echo "<input type='checkbox' name='hashtag_modify_checkbox[]' value='" . $value3 . "' />"; echo "Modify"; echo "<input type='text' name='hashtag_name[]' value='" . $entry3 . "' />"; echo "<input type='submit' name='submit' />"; echo "</form>"; // Here, only store those hashtag names where the "modify" checkbox is checked. ?>This is used for the admin panel. It is a form where the input fields hold the text ("hashtags") already inside of them. Basically, one would have to check the "modify checkbox" to modify a hashtag, then only the modified hashtags should get stored into an array. How to have those hashtags stored in the array with the checked checkbox as the factor? The suggestions are much appreciated. Edited by glassfish, 23 October 2014 - 10:06 AM. I've got an array like this: $firstquarter = array('January', 'February', 'March'); Then I'm adding it to a MySQL DB as follows: $insert = "INSERT INTO sometable (months) VALUES ('$firstquarter') "; $insertresult = mysql_query($insert) or die ('Error in Insert query: ' . mysql_error()); When I use PHPMyAdmin I see a this value stored in the DB: 'Array' Can I retrieve the values, by index, from this database field?? Hi, just a very simple question: I have an array as follows: $langList = array('English', 'French', 'German', 'Dutch'); What's the easiest way to store this array in an external file, so that multiple php scripts can access its contents? And what is then the php line I need to retrieve the array from the external file? Thanks! Hi all I have a question about how to store parsed data into a multidimensional arrays -- I can store items into an array, but multidimensional arrays mystify me a bit. Any help would be greatly appreciated. I'm storing the images in a table, grouped according to their table and their descriptions, so that later when I call the images, I can display them accordingly. I'm using the Simple HTML DOM Parser. So say I have two tables, one with three images, and another with one. I'd like the resulting to array to look like: Code: [Select] Array ( [0] => Array ( [0] => image1.jpg [1] => 1st Variation Description ) [1] => Array ( [0] => image2.jpg [1] => image3.jpg [2] => image4.jpg [3] => 2nd Variation Description ) ) This is what I have so far: Code: [Select] $html = str_get_html($vartables); $varinfo = array(); foreach($html->find('table') as $table){ $varinfo[] = $table->innertext; } print_r($varinfo); Which yields: Code: [Select] Array ( [0] => <tr> <td width=150> Description1 </td> <td><a href="image1.jpg"> <img src="image1" height=100 border=1></a> </td> </tr> [1] => <tr> <td width=150> Description2 </td> <td><a href="image2.jpg"> <img src="image2.jpg" height=200 border=1></a> </td> <td><a href="image3.jpg"> <img src="image3.jpg" height=200 border=1></a> </td> <td><a href="image4.jpg"> <img src="image4.jpg" height=200 border=1></a> </td> </tr> ) I'd like to strip out the html and keep the .jpg's and descriptions together in a multidimensional array...unfortunately my newbness is getting the better of me there, I'm researching but running into a roadblock. Thanks in advance for any help. I have a Form that has 10 questions. When the User completes the Form, each Response needs to be a separate record. (My database has a many-to-many relationship with a "member" and "question" table joined by a "answer" table in the middle. And each Form field will go into its own unique record to make the many-to-many work.) At the top of my Form I have... if ($_SERVER['REQUEST_METHOD']=='POST'){ // Form was Submitted (Post). // Initialize Errors Array. $errors = array(); // Trim all form data. $trimmed = array_map('trim', $_POST); // ************************ // Validate Form Data. * // ************************ // Validate Answer1. if (strlen($trimmed['answer01']) >= 2 && strlen($trimmed['answer01']) <= 1024){ // Valid Answer1. $answerArray[0] = $trimmed['answer01']; }else{ // Invalid Answer1. $errors['question01'] = 'Answer must be 2-1024 characters.'; }//End of VALIDATE ANSWER1 // Validate Answer2. // : // : // Validate Answer10. And down farther in my code, I have each Field in my Form set up like this... Code: [Select] <!-- Question 1 --> <label for="question01">1.) Why did you decide to start your own business?</label> <textarea id="question1" name="answer01" cols="60" rows="8"><?php if (isset($answerArray[0])){echo htmlentities($answerArray[0], ENT_QUOTES);} ?></textarea> <?php if (!empty($errors['question01'])){ echo '<span class="error">' . $errors['question01'] . '</span>'; } ?> So if my Form works like I am thinking, all 10 Form Fields would end up here... Code: [Select] $answerArray[0] $answerArray[1] $answerArray[2] $answerArray[3] $answerArray[4] $answerArray[5] $answerArray[6] $answerArray[7] $answerArray[8] $answerArray[9] First of all, does that sound correct? If that part is correct, then how do I take the $answerArray[] and INSERT each value into a different record in my "answer" table?? Hope that makes sense?! Thanks, Debbie Hi all, I'm a first time poster here and I would really appreciate some guidance with my latest php challenge! I've spent the entire day googling and reading and to be honest I think I'm really over my head and need the assistance of someone experienced to advise the best way to go! I have a multi dimensional array that looks like (see below); the array is created by CodeIgniter's database library (the rows returned from a select query) but I think this is a generic PHP question as opposed to having anything to do with CI because it related to working with arrays. I'm wondering how I might go about searching the array below for the key problem_id and a value equal to a variable which I would provide. Then, when it finds an array with a the matching key and variable, it outputs the other values in that part of the array too. For example, using the sample data below. How would you recommend that I search the array for all the arrays that have the key problem_id and the value 3 and then have it output the value of the key problem_update_date and the value of the key problem_update_text. Then keep searching to find the next occurrence? Thanks in advance, as above, I've been searching really hard for the answer and believe i'm over my head! Output of print_r($updates); CI_DB_mysql_result Object ( [conn_id] => Resource id #30 [result_id] => Resource id #35 [result_array] => Array ( ) [result_object] => Array ( ) [current_row] => 0 [num_rows] => 5 [row_data] => ) Output of print_r($updates->result_array()); Array ( [0] => Array ( [problem_update_id] => 1 [problem_id] => 3 [problem_update_date] => 2010-10-01 [problem_update_text] => Some details about a paricular issue [problem_update_active] => 1 ) [1] => Array ( [problem_update_id] => 4 [problem_id] => 3 [problem_update_date] => 2010-10-01 [problem_update_text] => Another update about the problem with an ID of 3 [problem_update_active] => 1 ) [2] => Array ( [problem_update_id] => 5 [problem_id] => 4 [problem_update_date] => 2010-10-12 [problem_update_text] => An update about the problem with an ID of four [problem_update_active] => 1 ) [3] => Array ( [problem_update_id] => 6 [problem_id] => 4 [problem_update_date] => 2010-10-12 [problem_update_text] => An update about the problem with an ID of 6 [problem_update_active] => 1 ) [4] => Array ( [problem_update_id] => 7 [problem_id] => 3 [problem_update_date] => 2010-10-12 [problem_update_text] => Some new update about the problem with the ID of 3 [problem_update_active] => 1 ) ) Hey guys, I'm new here so hello... but I'll get right to the point: I have a table named POSTS, where I store user posts. In this table, I have a row named "Popularity". Now I would like the value of "Popularity" to be a function of the number of Likes, Dislikes, Views and Date posted, all of which are stored in respective tables (linked by Primary and Secondary keys). I was wondering if it actually is possible to have the value of "Popularity" adjust automatically when a change in "Likes", "Dislikes" or "Views" occurs. And if not, what alternatives I have. The ultimate reason I need to have this value stored in a table and up to date is that I wish to sort posts by "Popularity". Many thanks !!! |