Jump to content

Requesting recommendations


mrlankee

Recommended Posts

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)

Link to comment
Share on other sites

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 by QuickOldCar
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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();
        }
        
    }
}
?>
Link to comment
Share on other sites

 

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? 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.