PHP - Price Comparison Calculator
Similar TutorialsHi all, I'm new here (first post) so hopefully you'll all go easy on me I'm created a price comparison website for cameras and lenses. I will have around fifteen retailers on the site. Now I need to scrape each of their websites for the prices - this I can do. However, need a little help and advice on the best way to go about tackling this...is it best to create one big script or have various ones for each retailer, etc? Any help would be appreciated greatly Hi guys I was just wondering if there is some date combination for which this type of comparisons will not work. var_dump("2010-15-1">"2010-4-01"); Provided the date is always in the YYYY-mm-dd format with optional preceding 0 . Thanks Hi! gud pm guys! I have a simple problem which i can't seem to workout so i kinda need your expert help! I'm trying to compare a variable to a string in my db, the variable and the entry on my db has a format of (car - branch), I made this simple function to do that but it doesn't seem to compare properly.. Code: [Select] function get_car_code($branch) { global $connection; $query = "SELECT code "; $query .= "FROM car_code "; $query .= "WHERE branch =" . '"$branch"'; $query .= " LIMIT 1"; $result_set = mysql_query($query, $connection); confirm_query($result_set); return $result_set; } when its called back it doesn't return anything.. I'm thinking its the white spaces (or I'm wrong) but i needed them so i cant removed them.. Any suggestions? Thanks in advance! I have a couple of loops that are supposed to 1) list all the values of one table as check boxes then 2)compare them to the values of another table. If they match that checkbox is supposed to be pre-checked. I have some code but it is not working just right yet and I was hoping someone could help me. Code: [Select] <?php include("../../../cart/includes/openDbConn.php"); $sql = "SELECT Name FROM FabricType"; $dogettype = 'SELECT Type FROM FabricsTypes WHERE SKU = "'.$sku.'";'; $result = mysql_query($sql); while($results = mysql_fetch_array($result)) { if( $i % 3 == 0 ) { echo '</tr><tr>'; } $result2 = mysql_query($dogettype); while($results2 = mysql_fetch_array($result2)) { if(trim($results2['Type']) == trim($results['Name'])) { $ischecked = 'checked="checked"'; $value = 1; } else { $ischecked = ''; $value = 0; } } $i++; $tn = trim(ucfirst($results["Name"])); echo '<td> <label> <input type="checkbox" name="typeGroup1[]" '.$ischecked.' value="'.$results['Name'].'"> '.$tn.' </label> </td>'; } ?> With this code it echoes the check boxes correctly but only checks it if it is the last value in $results2. If I move the second while loop like so: Code: [Select] <?php include("../../../cart/includes/openDbConn.php"); $sql = "SELECT Name FROM FabricType"; $dogettype = 'SELECT Type FROM FabricsTypes WHERE SKU = "'.$sku.'";'; $result = mysql_query($sql); while($results = mysql_fetch_array($result)) { if( $i % 3 == 0 ) { echo '</tr><tr>'; } $result2 = mysql_query($dogettype); while($results2 = mysql_fetch_array($result2)) { if(trim($results2['Type']) == trim($results['Name'])) { $ischecked = 'checked="checked"'; $value = 1; } else { $ischecked = ''; $value = 0; } $i++; $tn = trim(ucfirst($results["Name"])); echo '<td> <label> <input type="checkbox" name="typeGroup1[]" '.$ischecked.' value="'.$results['Name'].'"> '.$tn.' </label> </td>'; } } ?> It only echoes out the first results of $results for however many values there are in $results2. Thanks for any help. Hi guys I am looking for a loop which will run untill there is a difference of 10 minutes. The timestamp I wish to use is "ISO 8601 date (added in PHP 5)" [ date("c")] If anyone know some code for this it would be much appreicated. I can do the loop its just the comparison between the two timestamps as part of the loop I have no idea where to start on. Cheers, and thanks in advance. Hi Everyone. I am new to SQL and trying to write a query against the following results table that would allow me to list the subjects where the student Mary has got a higher score than Tom.
Subject
Student
Teacher
Score
Maths
Tom
Anderson
67
Maths
Mary
Anderson
68
English
Tom
Lewis
55
English
Mary
Lewis
44
French
Tom
Joubert
87
French
Mary
Joubert
76
Geography
Tom
Arnold
76
Geography
Mary
Arnold
82
I believe I should be using the join clause but am unable to get this to work.
Thanks
Hi, its me again! So i have this function which gets all the events in my db according to its mall_id and a date (year-month). I merged the $month and $year so i can compare it to the date field in my table. I used DATE_FORMAT to modify my date field so i can compare them but it doesn't seem to work perfectly, Code: [Select] function select_all_events($mall_id, $month, $year, $public) { global $connection; $monthname = $month; $monthnum = date("n", strtotime("01-".$monthname."-2011 00:00:00")); if($monthnum < 10) { $monthnum = "0" . $monthnum; } $selected_date = $year . "-" . $monthnum; $query = "SELECT *, DATE_FORMAT(date ,'%Y-%m' ) AS date "; $query .= "FROM table "; $query .= "WHERE malls_id=" . $mall_id; $query .=" AND date =" . $selected_date; if($public == true) { $query .= " AND visible = 1"; } $query .= " ORDER BY date DESC"; $result_set = mysql_query($query, $connection); confirm_query($result_set); return $result_set; } I tried echoing $selected_date, the format is correct, the problem seems to be the comparison.. Also i tried doing it like this: Code: [Select] $query = "SELECT * "; $query .= "FROM table "; $query .= "WHERE malls_id=" . $mall_id; $query .=" AND DATE_FORMAT(date ,'%Y-%m' ) =" . $selected_date; but the results are mismatched, like when i choose 2012 January it display's 2011 December ... This dates are making my head dizzy and costing me time..lol Any ideas? Thanks in advance! all my dates I'm reading from a database are formatted mm/dd/yyyy and I want to find the number of days difference from the duedate and the datepaid (dayslate) . ? I need some idea of why my code works on 2 servers except the one that it needs to work on. Below is the code including the sites where the phpinfo is loaded. Please help me figure this one out, it's probably simple but I don't see it. phpinfo of the one not working as expected phpinfo of the one that works as expected The problem is here I think? Quote $insertGoTo = SITE_URL."?pg=registered&addr=".$myid; header('Location:'.$insertGoTo); The code is too long to be posted... in reply... I have this $str variable which say holds "String" and in my comparison I'm checking if it's content is "string" and it is supposed to return true but it isnt because of the case, how do I compare them without the case being an issue ? Code: [Select] if( date('j') < 1 && > 14) { $EnrollDate = "1/".date('n')."/".date('y'); }else { $EnrollDate = "15/".date('n')."/".date('y'); } What could be wrong here, i cant work! Hey there, Now usually after a while I can always solve bugs with my code but this one really has me at a halt here. So basically I have a function that returns true if the accounts username = demo and false if it doesn't but the following if statement returns true and executes the code every time regardless of the returned value of the function like so: Code: [Select] if(isset($_POST['server_start']) or isset($_POST['server_stop']) or isset($_POST['server_restart']) && $Class['Account']->is_demo_account($_SESSION['account_id']) == false) Now if I run the following code right above that: Code: [Select] if($Class['Account']->is_demo_account($_SESSION['account_id']) == false) echo "it isn't a demo account."; else echo "it is a demo account."; It will echo "it is a demo account" correctly. Now can somebody please tell me why the if statement with the post values in always return true. Thanks for your time! I'm compiling and running C++ applications from PHP. I'm using backticks to capture the output of the applications ran. The output is just some simple text. In my case "Miles per gallon = x" where x is just a number. I cannot for the life of me get the comparison to return true. For example Code: [Select] $command1="./a.out1 <input1"; $a = `$command1`; $command2="./a.out2 <input2"; $b = `$command2`; if(strcmp($a,$b)==0){ ... } else{ // this is always executing ... } The two strings $a and $b are both "Miles per gallon = 10". I have checked both variables using var_dump(bin2hex($a)) and get dump1= string(42) "4d696c6573207065722067616c6c6f6e203d203130" dump2= string(42) "4d696c6573207065722067616c6c6f6e203d203130" Any idea on what's happening? Hi guys.
I have tried implementing PDO in my php. Basically, I have created a form, which will take a letter, and then pass it to the php file.
My hope was, whatever was entered by the user, whether that was in the guise of being manually entered by them or chosen by a dropbox etc, this would then be able to be used within the LIKE comparison. When I run my file however, I get the following message: Error: SQLSTATE[HY093]: Invalid parameter number: no parameters were bound. I am a little confused by this. I have used $_POST with the HTML form element, and have specified it in the SQL syntax. Can anyone please advise me as to where I am going wrong? Hi
i am trying to compare to arrays
$a = Array ( [q1] => no [q3] => yes [q2] => yes );
$b = Array ( [q1] => no [q3] => yes [q2] => yes );
But when i intersect them it results in one element only, dont know why???
$c = array_intersect($a,$b);
print_r($c);
output -
Array ( [q1] => no )
Hi guys ,
Again i facing array comparison problem
i got this after var_dump() $a and $b
array(4) { ["q1"]=> string(3) "yes" ["q4"]=> string(2) "no" ["q3"]=> string(2) "no" ["q2"]=> string(2) "no" } array(4) { ["q1"]=> string(2) "no" ["q4"]=> string(3) "yes" ["q3"]=> string(3) "yes" ["q2"]=> string(3) "yes" } But when i use array_intersect($a,$b).. it results this array(4) { ["q1"]=> string(3) "yes" ["q4"]=> string(2) "no" ["q3"]=> string(2) "no" ["q2"]=> string(2) "no" } Don't know why, but there is no same value in both hi everyone
i keep seeing the following Comparison Operators:
<>i see it used in the following context: if ($connection <> 'SSL') { $connection = 'NONSSL'; }be grateful if somone would tell me what it means, i looked online but could not find the symbol thanks Gud pm! I need some help guys! I made this simple code to compare $check_location to $events['location'] every loop so if they are equal it should not echo what's inside the if statement.. Here's my code: Code: [Select] $events_set = select_all_events($mall_id, $month, $year, $public); while($events = mysql_fetch_array($events_set)) { $check_location = ""; if($check_location != trim($events['event_location'])) { $check_location = trim($events['event_location']); echo "<tr>"; echo "<td colspan=7 id='header'>"; echo "<br />"; echo $events['event_location']; echo "</td>"; echo "</tr>"; } before the loop is finished, $check_location must store a new events['location']... I know the problem is kinda simple but the comparison can't seem to work.. Thanks in advance! Hello everyone:
I'm having trouble with code that compares a Form value ($uname) to Field values (username) from my database. In testing, I'm using the same Form data over and over, and I now have several identical records instead of just one unique record for this user.
if (empty($_POST["uname"])) { $unameErr = "* Username is required"; } else { $uname = test_input($_POST["uname"]); if (!preg_match("/^[a-zA-Z0-9]*$/",$uname)) { $unameErr = "* Only letters and numerals are allowed"; } else { // Now sure the username is legit, we check to see if it's a // unique username by comparing it to all usernames already in member table. require_once 'login.php'; // This file contains database access credentials $db_conn = new mysqli($db_hostname, $db_username, $db_password, 'login'); if($db_conn->connect_error) die ('Connect Error: ('.$db_conn->connect_errno.')'.$db_conn->connect_error); $query = "select username from member"; // Only selecting the field to compare to $result = $db_conn->query($query); if(!$result) die ('Database access failed: ('.$db_conn->connect_errno.')'.$db_conn->connect_error); $rows = $result->num_rows; for($i = 0; $i <= $rows; $i++) { if(mysqli_fetch_assoc($result) == $uname) { $unameErr = "* Username already in use. Please choose another."; mysql_close($db_conn); exit; } } $query = "insert into member values(NULL, '$uname', '$pwd1', '$fname', '$lname')"; $result = $db_conn->query($query); if(!$result) die ("Database insertion failed: ".mysql_error()); } }This is my first attempt at this using PHP and am pleased that I can at least access my db. But I just can't figure out how to make this comparison check. Thanks in advance for any help you offer. ~Landslyde |