-
Posts
24,566 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
Identifiers names should contain [a-z][A-Z][0-9]_ characters. Hyphens are not valid. user-name is interpreted as user minus name
-
Are you calling session_start() on each of those pages?
-
Use a LEFT JOIN SELECT cat_title , CASE WHEN COUNT(post_id) = 0 THEN 'No posts' ELSE COUNT(post_id) END as total FROM categories c LEFT JOIN posts p ON c.cat_id = p.post_cat_id GROUP BY c.cat_title; I would also recommend using using valid column names.
-
Using parse_ini_file to parse an ini file with array-type entries?
Barand replied to KenHorse's topic in PHP Coding Help
When it comes to it, no part of php uses () format for arrays. try [Timers] Timer[1]=50 Timer[2]=30 Timer[3]=20 with $timers = parse_ini_file('mytimers.ini', 1); echo '<pre>', print_r($timers, 1), '</pre>'; giving Array ( [Timers] => Array ( [Timer] => Array ( [1] => 50 [2] => 30 [3] => 20 ) ) ) -
I would go for a slightly different model where the monthly charge is set for the duration of the lease. Charges can then be generated rather than having to enter them yourself. +--------------+ | unit | +--------------+ | unit_id |----+ | number | | +--------------+ | notes | | +--------------+ | payment | +--------------+ | | tenancy | +--------------+ | +--------------+ | ID | | | tenancy_ID |---------<| tenancy_ID | +--<| unit ID | | date | +---<| tenant_id | | amount | | | charge_p_m | | pay_type | (rental, deposit, contra, refund) | | start date | | notes | | | end date | +--------------+ | +--------------+ | | +--------------+ | | tenant | | +--------------+ | | tenant_id |---+ | name | | prev_address | | notes | +--------------+
-
When I connect (once at the top of the script, not for every query) I set the option to throw exceptions so I don't have to check for them every time. This brings me back to the two lines.
-
So while your writing try { $mydb = new DBWrapper(); // get the data and do what you want with it... $data = $mydb->readData('SELECT * FROM users where ID = :id', $userid); ... } catch (DBWrapperException $ex) { die($ex->getMessage()); } I write $data = $mydb->prepare("SELECT * FROM users WHERE ID = :id"); $data->execute(['id'=>$userid]); Not sure I'm totally sold on the benefits.
-
Have you turned on your error reporting, because this line should give a syntax error... $sql=("SELECT * FROM $tbl_name WHERE Form_Group ='$Form_Group' AND Att_Date = '$Att_Date'";; ^ And does the date format in $Att_Date match that in the DB table (which should be yyyy-mm-dd)
-
Both options have the same value
-
What is that supposed to tell us? What is doing that it shouldn't? What is it not doing that it should? (And note that whatever group you select (A or B) it will always be "Class A" with that HTML code.)
-
Here's a sample script with a small png image. First it creates a small copy then it enlarges that small copy back to the original size <?php $orig = imagecreatefrompng('images/snowman.png'); // copy to thumbnail sized image $im = imagecreatetruecolor(100,100); imagecopyresized($im, $orig, 0, 0, 0, 0, imagesx($im), imagesy($im), imagesx($orig), imagesy($orig)); imagepng($im, 'images/snowman_small.png'); imagedestroy($im); imagedestroy($orig); // restore thumbnail back to original size $orig = imagecreatefrompng('images/snowman_small.png'); $im2 = imagecreatetruecolor(400, 400); imagecopyresized($im2, $orig, 0, 0, 0, 0, imagesx($im2), imagesy($im2), imagesx($orig), imagesy($orig)); imagepng($im2, 'images/snowman_restored.png'); imagedestroy($orig); imagedestroy($im2); ?> As you can see, the final image has lost resolution, each pixel being magnified x4 The moral here is "never destroy the original". Not only will you lose resolution but you will also lose any embedded exif data.
-
Why was this posted in "PHP Coding Help" forum, and why is it talking about data? The posted code contains neither php code nor data.
-
I do not what to do because i think my coding is right please help me.
Barand replied to SNidhi's topic in PHP Coding Help
That suggestion will report some php errors. For all errors the settings need to be in the php.ini file, not the code. Also it won't inform you of mysqli errors $Title=$_POST['title']; $Price=$_POST['price']; $Author=$_POST['author']; mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); // ADD THIS LINE $con=mysqli_connect('localhost','root') or die("not connected"); mysqli_select_db($con,'BRM_DB'); . . . -
I do not what to do because i think my coding is right please help me.
Barand replied to SNidhi's topic in PHP Coding Help
Because $result is not equal to 1. You can check what it contains with var_dump($result); -
It did return the array - you were ignoring the returned value (the return value was not assigned to a variable)
-
You could do in exactly the same way that I showed you in this earlier post (if you actually read it)
-
steve.txt fruit , cherry , red vegetables , "celery, carrots" , green flowers , rose , fresh code $handle = fopen('steve.txt', 'r'); while ($line = fgetcsv($handle)) { echo '<pre>', print_r($line, 1), '</pre>'; } output Array ( [0] => fruit [1] => cherry [2] => red ) Array ( [0] => vegetables [1] => celery, carrots [2] => green ) Array ( [0] => flowers [1] => rose [2] => fresh ) Defaults give three per line for me.
-
Your operating system is full of infinite loops. Imagine how it would be if mouse-click detection only ran every five minutes.
-
The design of your recursive function isn't quite right. $duration = 2; $start='01-01-2019'; $month =date('n', strtotime($start)); $year =date('Y', strtotime($start)); $mon = 12-$month+1; $remainingMonth = $duration*12; $years_arr = array("$year"); $residue_arr = array("$remainingMonth"); $years_arr = process($remainingMonth,$year,$mon,$years_arr,$residue_arr); // THIS CALL RETURNS NOTHING print_r($years_arr); //<output function process($remainingMonth,$year,$mon,$years_arr,$residue_arr){ $residue = $remainingMonth - $mon;//$D$18-D20 if($residue != 0){ $new_year = $year+1; array_push($years_arr, $new_year); array_push($residue_arr, $residue); if($residue > 12 ){ $mon = 12; } else { $mon = $residue; } echo "<br>"; process($residue,$new_year,$mon,$years_arr,$residue_arr); // RETURNS VALUE BUT IS IGNORED } else { print_r($years_arr); return $years_arr; } }//end of process(..) The first call (lline 11) returns nothing as the if/else calls the process() function instead. This second call does go through the else{} branch and return the array. However your call does not collect the value returned and so, when the function exits, nothing is returned. You need to capture the result from that internal call to process() and return that value as the result so it is passed up the chain of calls, thus... function process($remainingMonth,$year,$mon,$years_arr,$residue_arr){ $residue = $remainingMonth - $mon;//$D$18-D20 if($residue != 0){ $new_year = $year+1; array_push($years_arr, $new_year); array_push($residue_arr, $residue); if($residue > 12 ){ $mon = 12; } else { $mon = $residue; } echo "<br>"; $years_arr = process($residue,$new_year,$mon,$years_arr,$residue_arr); // GET RETURNED VALUE } else { // print_r($years_arr); return $years_arr; } return $years_arr; // PASS IT BACK }//end of process(..) [edit] P.S. Is this a competition entry for the most convoluted code to return an array of 2 consecutive year numbers?
-
$user is already the output from a query you have just run.
-
Problem with Edit and Deletes on differ Tables
Barand replied to TheScruffyGuy's topic in PHP Coding Help
My advice is to rewrite it. You are repeating the same code three times. Put all the common bits in a function which you then call three times, passing a value to tell the function which table you want to output. -
The variable "$user" does not exist inside your function (variable scope!). Pass it in your function call. E.G. verify_staff($user);
-
or do it in the query when you get the data (and you can reformat the dates too) SELECT date_format(Date1, '%b-%d-%Y') as dstr1 , date_format(Date2, '%b-%d-%Y') as dstr2 , datediff(Date2, Date1) as days ...