Jump to content

All Activity

This stream auto-updates

  1. Today
  2. By now you should have learned to place code inside a code block! I'm happy try and help. Any data tables I already have from you are several years out of date and does not include the following tables used in your code: subject_position dummy arms_level promotion I would, therefore, require an up-to-date DB dump. (I'll PM you with my email address). Also - what MySQL version are you using?
  3. @Barand @All help me out This is my code $sql_mee ="SELECT yearid , semesterid , regno , subjectid , rank , total , grade , comment FROM ( SELECT yearid , semesterid , subjectid , @seq := CASE WHEN yss <> @prev THEN 1 ELSE @seq + 1 END as seq , @rank := CASE WHEN total = @prevtot THEN @rank ELSE @seq END as rank , @prevtot := total as total , @prev := yss as yss , regno , armsLevelId -- added FROM ( SELECT yearid , semesterid , subjectid , concat(yearid, armsLevelId, semesterid, subjectid) as yss , regno , total , armsLevelId -- added FROM subject_position ORDER BY yearid, armsLevelId, semesterid, subjectid, total DESC ) sorted JOIN (SELECT @prev := '', @seq := 0, @rank := 0, @prevtot := 0) as init ) ranked JOIN grade ON total BETWEEN grade.lomark AND grade.himark WHERE regNo='$_GET[name]' -- A and armsLevelId='$levelid' -- D and semesterid='$sem' -- E and yearid='$odun' -- D ORDER BY subjectid"; $query_mee = mysqli_query($con, $sql_mee); $data_sub_pos = array(); while($row_mee = mysqli_fetch_array($query_mee)){ $yearid_me = $row_mee["yearid"]; $semesterid_me = $row_mee["semesterid"]; $regNo_me = $row_mee["regNo"]; $subjectid_me = $row_mee["subjectid"]; $rank_me = $row_mee["rank"]; $total_me = $row_mee["total"]; $grade_me = $row_mee["grade"]; $data_sub_pos[] = $rank_me; } /*End of Subject Position Ranking*/ $sql = "select * from dummy where regid='$regno' and armsLevelId='$levelid' and yearid='$odun' and semesterid='$sem' group by subjectid"; $result = mysqli_query($con,$sql); while ($row_query=mysqli_fetch_array($result)){ $RegNo=$row_query["regid"]; $subject_id=$row_query["subjectid"]; $level_id=$row_query["armsLevelId"]; $semester=$row_query["semesterid"]; $session=$row_query["yearid"]; $fca=$row_query["firstCA"]; $sca=$row_query["secondCA"]; $exam=$row_query["exam"]; $total =$row_query["total"]; $grade =$row_query["grade"]; $comment =$row_query["comment"]; //subject $query_sub=mysqli_query($con,"select * from subject where id='".$subject_id."'"); while ($row_sub=mysqli_fetch_array($query_sub)){ $r_sub = $row_sub["subject_name"]; } //level $query_level=mysqli_query($con,"select * from armslevel where id='".$level_id."'"); while ($row_level=mysqli_fetch_array($query_level)){ $r_level = $row_level["Armslevel"]; } //semester $query_semester=mysqli_query($con,"select * from semester where id='".$semester."'"); while ($row_semester=mysqli_fetch_array($query_semester)){ $r_semester = $row_semester["term"]; } //session $query_year=mysqli_query($con,"select * from year where id='".$session."'"); while ($row_year=mysqli_fetch_array($query_year)){ $r_year = $row_year["session"]; } //student details $query_reg=mysqli_query($con,"select * from promotion where regNo='".$RegNo."'"); while ($row_reg=mysqli_fetch_array($query_reg)){ $reg_ID = $row_reg["id"]; $reg_title = $row_reg["title"]; $reg_Regno = $row_reg["regNo"]; $reg_firstName = $row_reg["firstname"]; $reg_middleName = $row_reg["middleName"]; $reg_lastName = $row_reg["lastName"]; $reg_gender = $row_reg["gender"]; $reg_houseID = $row_reg["houseid"]; $reg_profile_pic = $row_reg["passport"]; $reg_level_id=$row_reg["armslevelid"]; $reg_semester=$row_reg["semesterid"]; $reg_session=$row_reg["yearid"]; $reg_nationality=$row_reg["nationality"]; $reg_stateID=$row_reg["stateID"]; $reg_localgovtID=$row_reg["localgovtID"]; $reg_phone=$row_reg["phone"]; $reg_email=$row_reg["email"]; $reg_signup_date=$row_reg["signup_date"]; // $reg_status=$row_reg["status"]; //echo "select * from promotion where regNo='".$RegNo."' and armslevelid='$level_id' and arms='$arms' and yearid='$session'"; } for ($pos=0; $pos<count($data_sub_pos); $pos++) { if(!empty($data_sub_pos[$pos])){ $position = $data_sub_pos[$pos]; $position = $position; }else{ echo "Error Occured"; } } $outputdata .="<tr> <td>$sn</td> <td>$r_sub</td> <td>$fca</td> <td>$sca</td> <td>$exam</td> <td>$total</td> <td>$position</td> <td>$grade</td> <td>$comment</td> </tr>"; $sn++; } Note: the position column is populating the last data. the position column should populate 1st, 8th, 7th, 3rd the last data (3rd is populated). thanks for your help in advance.
  4. Yesterday
  5. FYI Here is a simpler non-recursive solution... $cat_data = []; $res = $pdo->query("SELECT id , CONCAT(name, '::', position) as name , parent FROM category "); foreach ($res as $r) { $cat_data[$r['id']] = [ 'name' => $r['name'], 'parent' => $r['parent'] ] ; } $breadcrumbs = retrieve_category_path(552, $cat_data); echo $breadcrumbs; function retrieve_category_path($id, &$cats) { if (!isset($cats[$id])) { return "Unknown category"; } $category_path_array = []; do { array_unshift($category_path_array, $cats[$id]['name']); $id = $cats[$id]['parent']; } while ($id); return join(' / ', $category_path_array); }
  6. Last week
  7. We want to add a new element to the $cpa array in each call to the function. To do this we need always to add to the original empty array. The ampersand allows us to to this. Without it, a copy of the array would be passed to the function and we would just keep adding to a new empty array each time. &$cpa passes the array by reference (ie its address in memory) instead of a copy. P.S. This method below (which stores all the category data into a $cat_data array instead of running a query in every call to the function, is 5x faster. $cat_data looks like this... Array ( [532] => Array ( [name] => Motorbikes::1 [parent] => 0 ) [533] => Array ( [name] => Cars::2 [parent] => 0 ) [534] => Array ( [name] => Boats::3 [parent] => 0 ) [535] => Array ( [name] => Bicycles::4 [parent] => 0 ) . . . ) CODE $cat_data = []; $res = $pdo->query("SELECT id , CONCAT(name, '::', position) as name , parent FROM category "); foreach ($res as $r) { $cat_data[$r['id']] = [ 'name' => $r['name'], 'parent' => $r['parent'] ] ; } $category_path_array = []; retrieve_category_path ($cat_data, 552, $category_path_array); $breadcrumbs = join('/', $category_path_array); echo $breadcrumbs; function retrieve_category_path (&$cats, $id, &$cpa) { array_unshift($cpa,$cats[$id]['name']); if ($cats[$id]['parent']) { retrieve_category_path($cats, $cats[$id]['parent'], $cpa); } } Thank you - much appreciated.
  8. Slightly different to how i thought it would be done, but with a bit of tweaking it works Why is there an ampersand on the function call "function retrieve_category_path($pdo, $id, &$cpa)" ? Also what purpose does the $cpa serve below, is it sending the "$cpa[] = $row['name']" array data back round to the function call for the next loop, i.e. is the built array data from the 1st loop sent to the function call to be included on each following loop? As for not including DB connection inside functions, i'll have to look into how to do this as i'm not aware of any other way to do it! I'm picking up PHP as i go along, i've picked it up on this method from code examples which has stuck with me as standard practice so i'll have to figure out how to do it more efficiently Many thanks for your help, i've sent you a small donation for a drink
  9. After calling your recursive array you need finish up with a single array - you output a separate array during each iteration. Don't connect to db inside functions - it's the slowest part of the process and inefficient (plus you can quickly reach your connctions limit). Connect once then pass the connection to the functions. Don't include the separator in you results - add that when you implode (join). (Sorry for any delay - it's not easy to load an image of data into a database test table) My method... function retrieve_category_path($pdo, $id, &$cpa){ // DB connection // Company ID $stmt = $pdo->prepare("SELECT CONCAT(name, '::', position) as name , parent FROM category WHERE id = ? "); $stmt->execute([$id]); while($row=$stmt->fetch()){ $parent =$row['parent']; $name = $row['name']; $cpa[] = $row['name']; // append into array if($row['parent'] > 0){ retrieve_category_path($pdo, $row['parent'], $cpa); } } } $category_path_array = []; retrieve_category_path($pdo, 552, $category_path_array); $breadcrumbs = join('/', array_reverse($category_path_array)); echo $breadcrumbs; // Cars::2/Sports cars::1/Petrol::1/2 Door::0
  10. SQL DB Category Table Basically you will call the function with category id (retrieve_category_path($id) and it will loop through the database returning the category data until the parent id = 0 (ID for top Parent = 0, Parent ID > 0 = Child) Just looking to combine the returned arrays into a single array (Parent/Child/Child/Child) rather than (Parent/) (Child/) (Child/) (Child/)
  11. Instead of the above final line, can you post something processable such as var_export($category_path_array) Or, better still, a dump of your test data (struture and data) so we can reproduce the array ourselves. (The more you help us the more we can help you)
  12. I'm stuck on trying to generate the full Category Path / Breadcrumb path for a category including its parent categories e.g. Cars / Sports Cars / Petrol / 2 Door I have a category ID such as 123 for "2 Door" in the path example above, which is sent to the function below in hope of getting the full category path including parent categories. function retrieve_category_path($id){ // DB connection require("../../config/db/connection.php"); // Company ID $company_id = 1 ; $stmt = $conn->prepare("SELECT id, name, parent, position FROM category WHERE company_id = ? AND id = ?"); $stmt->bind_param("ii", $company_id, $id); $stmt->execute(); $result = $stmt->get_result(); $category_path_array = []; while($row=$result->fetch_assoc()){ $parent =$row['parent']; $name = $row['name']; $position = $row['position']; $position_seperator = '::'; $seperator = '/'; $category_path_array = [$name, $position_seperator, $position, $seperator]; if($parent > 0){ retrieve_category_path($parent); } } // return $category_path_array; var_dump($category_path_array); } This creates an array: which when imploded, the array has split to 4 seperate array rows: However i want the rows combined into a single row such as: ideally with the end forward slash removed to Can anyone please advise where i'm going wrong? Many thanks
  13. @requinix Indeed! I spent a good part of the day digging in to understand it more, though I'm not totally getting it in my head yet but I understand a lot more now. Luckily, these profiles are on a completely seperate part of the website so the htaccess file only applies to that folder, and there's a different domain name that points to it. So it serves it's purpose. However as you said, if I restructure that then I'll have to revisit how I path the pages. Might end up having to use it by id's only
  14. Well, look at the difference between the two (besides the IfModule). Before you had RewriteRule ^(.*)$ profile.php?$1 [L,QSA] That would turn "johndoe" into "profile.php?johndoe". That's not what you wanted. Now you have RewriteRule (.*) /profile.php?id=$1 [L] That will produce "profile.php?id=johndoe". Keep in mind this will kick in for any path that doesn't exist - not just "words". You should consider limiting exactly what this can match.
  15. UPDATE: The following works. I'm posting it here in case it helps anyone else. I have to admit though that I don't understand WHY it works and I am going to dig deeper in this so I can understand. I give credit to @requinix because that reply did spark a few flares in this old noggin on some things to search for too Working htaccess code <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*) /profile.php?id=$1 [L] </IfModule>
  16. UPDATE: I changed the setting in PLESK that I found for the error so that's not an issue anymore. Now it's just a matter of it not working because the page isn't finding the chosen URL value extension
  17. @requinix sorry I forgot to mention that. Yes I looked in the logs and the only error is how the htaccess file is affecting other pages with "Option FollowSymLinks not allowed here" but I'll tackle that headache later. I might have to do all of this in a different folder with its own htaccess to avoid all of that (example www.website.com/artist/john...) This is the newest one I have. No errors for it's own page but it's returning my own connection error I made when it can't find the specific name in the database so https://www.examplewebsite.com/profile.php?id=johndoe but https://www.examplewebsite.com/johndoe now just says "Which profile are you trying to see" (from not being able to grab the "custurl" value in the database) (side note: custurl is the row in the database where the value is entered for the chosen friendly url, in this case it being johndoe) ReWriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ profile.php?$1 [L,QSA]
  18. PHP is the cart, your web server is the horse. You cannot put the cart before the horse. Pick the simplest .htaccess you've tried and post it here, then we'll see what's wrong with it. Can I also assume that you, at some point during these 500 errors, looked in your server's error logs for an error message? What did it say?
  19. Hello I've tried many many many different ways of making a rewrite htaccess file for this and every time I've come up with getting a 500 error. Even when used a bunch of the different generators to make them online. However even the generators don't really produce what I would want anyways, though I was using them to at least get a good starting point to figure it out. However no htaccess file will work as I keep getting the 500 error regardless This is what I'm trying to do. 1: There is a form on my website where people can type a single word with no spaces (and is forced lower case) to have a custom url 2: I want to make it so this url is what pulls up their page This link currently works https://www.examplewebsite.com/profile.php?id=johndoe (not a real link but for testing it works) And I am trying to get it to be so he can share his link to people just using https://www.examplewebsite.com/johndoe (much like you see for facebook pages and other friendly url website links) Alas, after 3 weeks and dried up eyes, I have had no luck at all. Is there a way to do this with just PHP? and if not, then is there a way to do this another way other than the htaccess rewrite file? Many thanks Note: I didn't include any of the htaccess codes that I tried because I tried so many of them that I don't even know which one would have been the closest to correct since they all gave me the same error
  20. I have a row of 2 columns. Left is an image, right is text. The image is cropped at the bottom, so when it gets to the width of a smaller device, I want to swap them over, so that they go 1/1 on each col, and the image is under the text. I tried Flex, but that forces it to be 50/50 width. I'm sure in CSS it is easy, but can't figure it out. Hope someone can help. I have tried this: @media only screen and (max-width: 950px) { #flex { display: flex!important; flex-flow: column!important; } #flex .grve-row { display: flex!important;} #left { order: 1!important; } #right { order: 2!important; } }
  21. I was going to suggest mysql> select * from tprojects; +-----------+---------+----------+------------+ | IdProject | service | IsActive | start | +-----------+---------+----------+------------+ | 6 | 123 | 1 | 2024-05-01 | | 7 | 123 | 1 | 2024-05-02 | | 8 | 123 | 1 | 2024-05-03 | | 9 | 123 | 1 | 2024-05-04 | | 10 | 123 | 1 | 2024-05-05 | | 11 | 123 | 1 | NULL | | 12 | 123 | 1 | NULL | | 13 | 123 | 1 | NULL | | 14 | 123 | 1 | NULL | | 15 | 123 | 1 | NULL | | 16 | 123 | 1 | NULL | | 17 | 123 | 1 | NULL | +-----------+---------+----------+------------+ mysql> SELECT COUNT(IdProject) as Sales -> , DATE_FORMAT(start, '%M %Y') AS Month -> FROM tprojects -> WHERE IsActive = '1' -> AND Service = 123 -> AND MONTH(start) IS NOT NULL -> GROUP BY month; +-------+----------+ | Sales | Month | +-------+----------+ | 5 | May 2024 | +-------+----------+
  22. Sorted thanks I ended up putting if(!empty($counts->Counter) && !empty($counts->Month)) { array_push($sales, array('Count' => $counts->Counter, 'Month' => $counts->Month)); } At least its giving the correct count
  23. Are you also doing something silly like storing your "start" column as type VARCHAR instead of type DATE?
  24. Found an issue, i haven't converted the datetime string to sql datetime somewhere
  25. Execute your query in phpmyadmin. What do you get?
  26. i think it may be returning them on different rows in the array [0]=> array(2) { ["Count"]=> int(61) ["Month"]=> NULL } [1]=> array(2) { ["Count"]=> int(5) ["Month"]=> int(5) } } [0]is returning the count and [1] is returning the month (5) May!
  1. Load more activity
×
×
  • 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.