mrlankee Posted October 24, 2014 Share Posted October 24, 2014 Hi What is the best recommended way to "sort through" and "place certain data" into a sql table? For example, I create a input form.php Company Name: The Blah Company Product/Industry Dedicated Servers HTML Source Code <div class="allservers"> <div class="serverType" id="server1"> <div class="myFeaturesBox"> <ul class="tabination"> <li><a href="#" class="activeTab" data-tab='feature'>FEATURED</a></li> <li><a href="#" data-tab='single'>SINGLE PROCESSOR</a></li> <li><a href="#" data-tab='dual'>DUAL PROCESSOR</a></li> <div class="clear"></div> </ul> <div class="feature myTab activeTabs"> <table class="table"> <tr> <th></th> <th>Processor</th> <th>RAM</th> <th>Hard Drive</th> <th>Price/Mo</th> <th></th> <th></th> </tr> <tr> <td><img src='img/server.png' alt='Server' width="20" height="20" /></td> <td>Intel Xeon E3-1230 (4x3.2GHz)</td> <td>8 GB DDR3</td> <td>1x500 GB SATA</td> <td>$98.00</td> <td><a href="https://portal.securedservers.com/wap-jpost3/UP011013E31230" target="_self"><img src='img/deploy.png' alt='Deploy Now' width="86" height="18" /></a></td> <td class="wB"></td> </tr> <tr> <td><img src='img/server.png' alt='Server' width="20" height="20" /></td> <td><div style="position:relative;">Intel Xeon E3-1240 v3 (4x3.4GHz)</div></td> <td>8GB DDR3</td> <td>1x1 TB SATA</td> <td>$128.00</td> <td><a href="https://portal.securedservers.com/wap-jpost3/UP031013E31240" target="_self"><img src='img/deploy.png' alt='Deploy Now' width="86" height="18" /></a></td> <td class="wB"></td> </tr> <tr> <td><img src='img/server.png' alt='Server' width="20" height="20" /></td> <td><div style="position:relative;">Intel Xeon E3-1240 v3 4-bay (4x3.4GHz)</div></td> <td>8GB DDR3</td> <td>4x500 GB SATA</td> <td>$148.00</td> <td><a href="https://portal.securedservers.com/wap-jpost3/UP431013E31240" target="_self"><img src='img/deploy.png' alt='Deploy Now' width="86" height="18" /></a></td> <td class="wB"></td> </tr> <tr> </table> Submit Button --> sends to the "sorting process?" than into proper DB tables for search query. Ultimately, there I require to be able to pull from my DB upon query, pricing, hardware, processor, etc..Any recommendation for me to try? I'm new to PHP but I want to learn and do it myself (better after effect feeling than paying someone) Quote Link to comment https://forums.phpfreaks.com/topic/292025-requesting-recommendations/ Share on other sites More sharing options...
QuickOldCar Posted October 24, 2014 Share Posted October 24, 2014 (edited) Seems simple enough to use a single table and create a field for each variable. No reason to do different tables and joins on this. The sorting is done either by dynamic variables in the database query or manually inserting one. "SELECT * FROM `computer_db` WHERE `processor` LIKE '%{$processor}' " "SELECT * FROM `computer_db` WHERE `processor` = '{$processor}' AND `ram` = '{$ram}' " Edited October 24, 2014 by QuickOldCar Quote Link to comment https://forums.phpfreaks.com/topic/292025-requesting-recommendations/#findComment-1494555 Share on other sites More sharing options...
mrlankee Posted October 24, 2014 Author Share Posted October 24, 2014 I say different tables because (Game servers, ded servers, vps, and VOIP servers)my question is how do I go about code a sorting process to only insert the pricing, hardware, and other pertinent information into the DB of the HTML source? Quote Link to comment https://forums.phpfreaks.com/topic/292025-requesting-recommendations/#findComment-1494556 Share on other sites More sharing options...
QuickOldCar Posted October 24, 2014 Share Posted October 24, 2014 Is your question how to connect to a site and scrape particular data from it...then save. Quote Link to comment https://forums.phpfreaks.com/topic/292025-requesting-recommendations/#findComment-1494557 Share on other sites More sharing options...
mrlankee Posted October 24, 2014 Author Share Posted October 24, 2014 Essentially yes. Quote Link to comment https://forums.phpfreaks.com/topic/292025-requesting-recommendations/#findComment-1494558 Share on other sites More sharing options...
QuickOldCar Posted October 24, 2014 Share Posted October 24, 2014 Websites frown on other websites scraping their data. Do you own this site or have permission to do so? Use curl or file_get_contents() to connect to the website Parse the html data whichever method suits you simplehtmldom dom simplexml preg_match() or preg_match_all() display or store the data you discovered Quote Link to comment https://forums.phpfreaks.com/topic/292025-requesting-recommendations/#findComment-1494562 Share on other sites More sharing options...
QuickOldCar Posted October 24, 2014 Share Posted October 24, 2014 I think we misunderstood one another. You want to make a form and store that post data to a database Do you have the form created? to post into a form and insert using PDO you can try this <form action="" method="post"> cpu: <input type="text" name="cpu"><br> ram: <input type="text" name="ram"><br> <input type="submit" value="Submit"> </form> <?php if (!empty($_POST)) { if (isset($_POST['cpu']) && trim($_POST['cpu']) != '') { $cpu = trim($_POST['cpu']); } if (isset($_POST['ram']) && trim($_POST['ram']) != '' && ctype_digit($_POST['ram'])) { $ram = trim($_POST['ram']); } if (isset($cpu) && isset($ram)) { //save the data $dbname = "my_database"; $dbuser = "username"; $dbpass = "password"; $tablename = "my_table"; try { $pdo = new PDO("mysql:host=localhost;dbname=$dbname", $dbuser, $dbpass); $sql = "INSERT INTO {$tablename} (cpu,ram) VALUES (:cpu,:ram)"; $q = $pdo->prepare($sql); $q->execute(array( ':cpu' => $cpu, ':ram' => $ram )); } catch (PDOException $e) { print "Error!: " . $e->getMessage() . "<br/>"; die(); } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/292025-requesting-recommendations/#findComment-1494564 Share on other sites More sharing options...
mrlankee Posted October 24, 2014 Author Share Posted October 24, 2014 I think we misunderstood one another. You want to make a form and store that post data to a database Do you have the form created? to post into a form and insert using PDO you can try this <form action="" method="post"> cpu: <input type="text" name="cpu"><br> ram: <input type="text" name="ram"><br> <input type="submit" value="Submit"> </form> <?php if (!empty($_POST)) { if (isset($_POST['cpu']) && trim($_POST['cpu']) != '') { $cpu = trim($_POST['cpu']); } if (isset($_POST['ram']) && trim($_POST['ram']) != '' && ctype_digit($_POST['ram'])) { $ram = trim($_POST['ram']); } if (isset($cpu) && isset($ram)) { //save the data $dbname = "my_database"; $dbuser = "username"; $dbpass = "password"; $tablename = "my_table"; try { $pdo = new PDO("mysql:host=localhost;dbname=$dbname", $dbuser, $dbpass); $sql = "INSERT INTO {$tablename} (cpu,ram) VALUES (:cpu,:ram)"; $q = $pdo->prepare($sql); $q->execute(array( ':cpu' => $cpu, ':ram' => $ram )); } catch (PDOException $e) { print "Error!: " . $e->getMessage() . "<br/>"; die(); } } } ?> Exactly I REALLY appreicate that, made the process make so much sense. I'm new to the whole SQL db, How would one call from a search form results from the whole table in a nice chart? Quote Link to comment https://forums.phpfreaks.com/topic/292025-requesting-recommendations/#findComment-1494565 Share on other sites More sharing options...
QuickOldCar Posted October 25, 2014 Share Posted October 25, 2014 Is just like basic html making the table, except in your while loop for mysql you echo out the <td></td> while ($row = mysqli_fetch_assoc($result)) { echo '<td>'.$row['cpu'].'</td>'; echo '<td>'.$row['ram'].'</td>'; } Quote Link to comment https://forums.phpfreaks.com/topic/292025-requesting-recommendations/#findComment-1494663 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.