-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
Change $line = rtrim($line) . " Be careful with cats!" . PHP_EOL; to $lines[$n] = rtrim($line) . " Be careful with cats!" . PHP_EOL;
-
You have a mysqli connection but you are using mysql_query(). You can't mix the two libraries. Use mysqli_query(). Better would by to create a mysqli prepared statement and repeatedly execute that with the new data values each time.
-
Best way of organizing dropdown menus please
Barand replied to benoit1980's topic in PHP Coding Help
Here's an example <?php $a_towns = array(1=>'Town A','Town B','Town C','Town D','Town E'); $opts="<option value=''>- Select Town -</option>\n"; foreach($a_towns as $k=>$t) { $opts .= "<option value='$k'>$t</option>\n"; } ?> <html> <head> <style type='text/css'> div.hideable { border: 1px solid gray; width: 200px; height: 50px; padding: 20px; font-size: 20pt; } #div1 { background-color: red; } #div2 { background-color: green; } #div3 { background-color: blue; } </style> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script type="text/javascript"> $().ready(function() { $(".hideable").hide(); $("#menuA").change(function() { $(".hideable").hide(); switch ($("#menuA").val()) { case '1': case '2': $("#div1").show(); break; case '3': $("#div2").show(); break; case '4': $("#div3").show(); break; case '5': $("#div2").show(); break; } }) }) </script> </head> <body> <select name='menuA' id='menuA'> <?=$opts?> </select> <br> <div id="div1" class='hideable'>DIV 1</div> <div id="div2" class='hideable'>DIV 2</div> <div id="div3" class='hideable'>DIV 3</div> </body> </html> -
Best way of organizing dropdown menus please
Barand replied to benoit1980's topic in PHP Coding Help
You would initially build you page content and dropdown options with PHP, but the showing of the div content would be done client-side using javascript/jquery -
Quantity in shopping basket add and subtract buttons not working
Barand replied to mik_se7's topic in PHP Coding Help
How do you know which quantity belongs to which item, all you save is one $qty -
It was a bespoke application targeted specifically for the client's database and table relationships. It would not be of general use.
-
Quantity in shopping basket add and subtract buttons not working
Barand replied to mik_se7's topic in PHP Coding Help
if ($qty < 5){ $addqty = $qty + 1; Where is $qty defined? -
You could try removing 'message' from the $required array $required = array('name','email');
-
split array by first part of key name into other arrays
Barand replied to AdRock's topic in PHP Coding Help
try $data = array(); foreach ($rows as $arr) { foreach ($arr as $k => $v) { list($cat, $attr) = explode('.', $k); if ($attr == 'name') { $name = $v; $data[$cat][$name] = array(); } else { $data[$cat][$name][$attr] = $v; } } } RESULT $data = Array ( [fruit] => Array ( [Apple] => Array ( [colour] => Red [weight] => 0.1 ) [Banana] => Array ( [colour] => Yellow [weight] => 0.7 ) ) [vegetable] => Array ( [Carrot] => Array ( [colour] => Orange [weight] => 0.05 ) [Potato] => Array ( [colour] => Brown [weight] => 0.6 ) ) ) -
My query above did not take into account new clients who had no previous test results. SELECT a.iduser , CONCAT(first_name,' ',last_name) as name , DATE_FORMAT(apptime, '%a %D %l:%i%p') as time , a.idtreatment , a.idstylist , t.idtreatmentTest , tu.dateOfTreatment , tt.treatmentTestExpiry , CASE WHEN DATEDIFF(a.apptime, IFNULL(tu.dateOfTreatment,'0000-01-01')) > treatmentTestExpiry THEN 'TEST REQUIRED' ELSE '' END as testReq FROM appointment a INNER JOIN user u USING (iduser) INNER JOIN treatment t ON a.idtreatment = t.idtreatment LEFT JOIN treatmenttest tt ON t.idtreatmenttest = tt.idtreatmenttest LEFT JOIN ( SELECT iduser, idtreatment, MAX(dateOfTreatment) as dateOfTreatment FROM treatmentuser GROUP BY iduser, idtreatment ) tu ON a.idtreatment = tu.idtreatment AND a.iduser = tu.iduser ORDER BY time;
-
mysqli display field name / conditionally format table
Barand replied to TheAlmightyOS's topic in PHP Coding Help
I use this to print query results into a table with headings (useful for testing queries) echo query2HTMLtable($conn, "SELECT * FROM tablename"); function query2HTMLtable($db, $sql) { $output = "<table border='1' cellpadding='2' style='border-collapse:collapse'>\n"; // Query the database $result = $db->query($sql); // check for errors if (!$result) return ("$db->error <pre>$sql</pre>"); if ($result->num_rows == 0) return "No matching records"; // get the first row and display headings $row = $result->fetch_assoc(); $output .= "<tr><th>" . join('</th><th>', array_keys($row)) . "</th></tr>\n"; // display the data do { $output .= "<tr><td>" . join('</td><td>', $row) . "</td></tr>\n"; } while ($row = $result->fetch_assoc()); $output .= "</table>\n"; return $output; } -
I used your initial tables and added an appointment table CREATE TABLE treatmentUser ( idtreatmentUser INT NOT NULL PRIMARY KEY, idtreatment INT, iduser INT, dateOfTreatment DATE -- yyyy-mm-dd ); CREATE TABLE treatmentTest ( idtreatmentTest INT NOT NULL PRIMARY KEY, treatmentTestExpiry INT -- days for which the test is valid ); CREATE TABLE treatment ( idtreatment INT NOT NULL PRIMARY KEY, idtreatmentTest INT ); CREATE TABLE appointment ( idappointment INT NOT NULL PRIMARY KEY, iduser INT, apptime DATETIME, -- yyyy-mm-dd hh:ii:ss idstylist INT ); And used this query. (The subquery is used so you use only the latest test date for a user as they may have have several tests on record) SELECT a.iduser , CONCAT(first_name,' ',last_name) as name , DATE_FORMAT(apptime, '%a %D %l:%i%p') as time , a.idtreatment , a.idstylist , t.idtreatmentTest , tt.idtreatmentTest , tu.dateOfTreatment , tt.treatmentTestExpiry , CASE WHEN DATEDIFF(a.apptime, tu.dateOfTreatment) > treatmentTestExpiry THEN 'TEST REQUIRED' ELSE '' END as testReq FROM appointment a INNER JOIN user u USING (iduser) INNER JOIN treatment t ON a.idtreatment = t.idtreatment LEFT JOIN treatmenttest tt ON t.idtreatmenttest = tt.idtreatmenttest LEFT JOIN treatmentuser tu ON a.idtreatment = tu.idtreatment AND a.iduser = tu.iduser LEFT JOIN ( SELECT iduser, idtreatment, MAX(dateOfTreatment) as dateOfTreatment FROM treatmentuser GROUP BY iduser, idtreatment ) latest ON tu.iduser = latest.iduser AND tu.idtreatment = latest.idtreatment AND tu.dateOfTreatment = latest.dateOfTreatment ORDER BY time; edit - my data These were my results
-
Your other table structure in your previous post was better, once you get round the notion that users in your tables are actually clients Now you have lost both the association of a test with a treatment and the valid duration for a test before it expires. "Expired" is a derived value (and therefore should not be in a table) based on the duration and when the test was last given. How do you now know if a test has expired without going through and manually updating those "expired" flags?
-
Something like this $tabledata = ''; while($row=mysql_fetch_array($query)) { $subtotal=$_SESSION['cart'][$row['product_id']]['quantity']*$row['price']; $totalprice+=$subtotal; $tabledata .= <<<ROW <tr> <td>{$row['name']}</td> <td><input type="text" name="quantity[{$row['product_id']}]" size="5" value="{$_SESSION['cart'][$row['product_id']]['quantity']}"/></td> <td>{$row['price']}€</td> <td>$subtotal</td> </tr> ROW; }
-
While you are constructing the table for your page, store the HTML in a variable that can be added to your email message.
-
It would appear from that quote that you want to know if the client requires the test, but you record the dates the user gave the test so how do you relate it to a particular client?. treatmentTestExpiry - is that a period in days?
-
There are some other things you need to fix. Radio buttons need different values. All yours have a value of "radio" You don't change the search depending on the button selected (not that you could with those values) You are using mysql_xxxx() functions which are about to be removed from PHP. Try something like this <html> <body> <form id="form1" name="form1" method="post" action=""> <div id="Zoekend"> <p> <label for="Zoek"></label> <input type="text" name="Zoek" id="Zoek" /> </p> <p> <label> <input type="radio" name="RadioGroup1" value="1" id="RadioGroup1_0" /> Genre</label> <br /> <label> <input type="radio" name="RadioGroup1" value="2" id="RadioGroup1_1" checked="checked"/> Naam</label> <br /> <label> <input type="radio" name="RadioGroup1" value="3" id="RadioGroup1_2" /> Jaar</label> <br /> <label> <input type="radio" name="RadioGroup1" value="4" id="RadioGroup1_3" /> Regisseur</label> <br /> <input type="submit" name="Zoeken" id="Zoeken" value="Zoeken" /> <br /> </p> </div> </form> <div id="Resultaat"> <h1> Zoekresultaten: </h1> <?php // // if no search attempt then we don't want to process the results // if (isset($_POST['Zoek']) && trim($_POST['Zoek'])!='' ) { $zoekterm = $_POST['Zoek']; $username = '1509506_dyon'; $wachtwoord = '****'; // deleted for your protection $host = 'fdb6.awardspace.net'; $database = '1509506_dyon'; $db = new mysqli($host, $username, $wachtwoord, $database); $fields = array ( 1 => 'Genre', 2 => 'Naam', 3 => 'Jaar', 4 => 'Regisseur' ); $field = $fields[$_POST['RadioGroup1']]; $sql = "SELECT * FROM Movies WHERE $field LIKE '%$zoekterm%'"; $resultaat = $db->query ($sql); if ($resultaat->num_rows > 0) { while ( $row = $resultaat->fetch_assoc() ) { echo $row['Genre'] . " - " . $row['Naam'] . " - " . $row ['Jaar'] . " - " . $row ['Regisseur'] .'<br>' ; } } else { echo "No matching results found"; } } else { echo "No search"; } ?> </div> </body> </html>
-
-
$smbc is an object. You need to pass the directory path as a string
-
$mysqli->commit() returns false , but it is working!
Barand replied to invader7's topic in PHP Coding Help
I was unable to recreate that on my own test table. You do seem to be missing the point of prepared queries though. You keep the values separate from the query, prepare the statement once then execute with different your values, several times as required $mysqli->autocommit(FALSE); $sql = "INSERT INTO users (first_name,last_name) VALUES (?,?)"; $stmt = $mysqli->prepare($sql); $stmt->bind_param('ss', $fn, $ln); $fn = 'stelios'; $ln = 'stelios2'; $stmt->execute(); $fn = 'stelios3'; $ln = 'stelios4'; $stmt->execute(); var_dump($mysqli->commit()); $mysqli->close(); -
User Generated Tables (ala filemaker), sorting/filtering/pagination
Barand replied to fivestringsurf's topic in MySQL Help
Good luck! -
submit a form and unset a session variable on other page
Barand replied to Cyjm1120's topic in PHP Coding Help
Before you can use session_unset() you need to call session_start(); All pages using $_SESSION need session_start() at the top of the script. -
If you load this page without a search term it will execute a search WHERE ... LIKE '%%', which is all records
-
Check to see if a search value has been posted. Only process the second part of your script if there is a posted value.
-
If that is real password, change it.