Jump to content

devilindisguise

Members
  • Posts

    14
  • Joined

  • Last visited

devilindisguise's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello all Thanks for your input and apologies if it was frustrating. I managed to get it working. CroNIX your last post gave me food for thought. Here's the updated and working config: <----OUTPUT omitted----> $pdf->SetFillColor(255,255,255); $pdf->SetFont('Arial','BU',12); $pdf->SetY(155); $pdf->SetX(25); $pdf->Cell(25,6,'Top 5 Sites:',9,0,'L',1); //Next Set of Results// $pdf->SetFillColor(192,192,192); $pdf->SetFont('Arial','B',10); $pdf->SetY(165); $pdf->SetX(25); $pdf->Cell(50,6,'Site',1,0,'C',1); $pdf->Cell(50,6,'Number of faults',1,0,'C',1); $y_axis = $y_axis + $row_height; $result_topten = mysqli_query($con, "SELECT site_details.sitename AS `sitename`, COUNT(*) AS `count` FROM site_details LEFT JOIN faults ON site_details.site_id = faults.site_id GROUP BY `sitename` ORDER BY COUNT(*) DESC LIMIT 5;"); $y_axis = 171; $i = 0; $max = 25; $row_height = 6; while($row = mysqli_fetch_array($result_topten)) { if ($i == $max) { $pdf->AddPage(); $pdf->SetFillColor(192,192,192); $pdf->SetFont('Arial','B',10); $pdf->SetY(165); $pdf->SetX(25); $pdf->Cell(50,6,'Site',1,0,'C',1); $pdf->Cell(50,6,'Number of faults',1,0,'C',1); //Go to next row $y_axis = $y_axis + $row_height; $i = $i++; } $site = $row['sitename']; $num_faults = $row['count']; $pdf->SetFillColor(232,232,232); $pdf->SetFont('Arial','',10); $pdf->SetY($y_axis); $pdf->SetX(25); $pdf->Cell(50,6,$site,1,0,'C',1); $pdf->Cell(50,6,$num_faults,1,0,'C',1); //Go to next row $y_axis = $y_axis + $row_height; $i = $i++; } ?> Again, many thanks.
  2. Hi there I'm afraid not. No matter which way I spin it I always only ever get the last row. You are right that block of code should come out of the while loop as it simply provides the header. Looking at my code I haven't initialised the variable $i. Do I perhaps need an If statement in there for good measure that checks $i against another value? Thanks
  3. CroNIX Thanks for your speedy reply. I think I know where you're coming from. Would it be something along the lines of: <?php require('pdf/fpdf/fpdf.php'); include('core/connect.php'); //Create new pdf file $pdf=new FPDF(); $pdf->Open(); //Disable automatic page break $pdf->SetAutoPageBreak(false); //Add first page $pdf->AddPage(); //Heading $pdf->SetFillColor(255,255,255); $pdf->SetFont('Arial','BU',12); $pdf->SetY(25); $pdf->SetX(25); $pdf->Cell(25,6,'Top Site:',9,0,'L',1); $result_topten = mysqli_query($con, "SELECT `site_id` AS `site`, COUNT(*) AS `count` FROM `faults` GROUP BY `site` ORDER BY count(*) DESC;"); while($row = mysqli_fetch_array($result_topten)) { $site = $row['site']; $num_faults = $row['count']; $pdf->SetFillColor(192,192,192); $pdf->SetFont('Arial','B',10); $pdf->SetY(35); $pdf->SetX(25); $pdf->Cell(50,6,'Site',1,0,'C',1); $pdf->Cell(50,6,'Number of faults',1,0,'C',1); $pdf->SetFillColor(232,232,232); $pdf->SetFont('Arial','',10); $pdf->SetY(45); $pdf->SetX(25); $pdf->Cell(50,6,$site,1,0,'C',1); $pdf->Cell(50,6,$num_faults,1,0,'C',1); $i = $i++; } //Send file $pdf->Output(); ?> Thanks
  4. Hello again Sorry, I come back cap in hand to ask for one last bit of help. After this I should be done never to bother you again. I posted just previously regarding outputting the results of a MySQL COUNT query to a PDF file. Staying on that subject to an extent, I've been wracking my brains on why this conundrum isn't working. As before, I wish to display the information from one table but unlike before there are multiple rows as opposed to multiple columns. I have my table 'faults' and wish to query the top ten, or top most occurring 'site_id' in this table. The following MySLQ query as before works just fine in phpMyAdmin: "SELECT `site_id` AS `site`, COUNT(*) AS `count` FROM `faults` GROUP BY `site` ORDER BY count(*) DESC;" Not much in the DB right now but it yields the following as I expect: Site Count 1 7 2 6 3 6 I was hoping getting this into a PDF wouldn't be so tricky but as usual I've come unstuck. Essentially what is happening is that it's only displays the bottom row, not all. Here's my code: <?php require('pdf/fpdf/fpdf.php'); include('core/connect.php'); //Create new pdf file $pdf=new FPDF(); $pdf->Open(); //Disable automatic page break $pdf->SetAutoPageBreak(false); //Add first page $pdf->AddPage(); //Heading $pdf->SetFillColor(255,255,255); $pdf->SetFont('Arial','BU',12); $pdf->SetY(25); $pdf->SetX(25); $pdf->Cell(25,6,'Top Site:',9,0,'L',1); $result_topten = mysqli_query($con, "SELECT `site_id` AS `site`, COUNT(*) AS `count` FROM `faults` GROUP BY `site` ORDER BY count(*) DESC;"); while($row = mysqli_fetch_array($result_topten)) { $site = $row['site']; $num_faults = $row['count']; } $pdf->SetFillColor(192,192,192); $pdf->SetFont('Arial','B',10); $pdf->SetY(35); $pdf->SetX(25); $pdf->Cell(50,6,'Site',1,0,'C',1); $pdf->Cell(50,6,'Number of faults',1,0,'C',1); $pdf->SetFillColor(232,232,232); $pdf->SetFont('Arial','',10); $pdf->SetY(45); $pdf->SetX(25); $pdf->Cell(50,6,$site,1,0,'C',1); $pdf->Cell(50,6,$num_faults,1,0,'C',1); $i = $i++; //Send file $pdf->Output(); ?> Resulting output in the PDF: Top Site: Site Count 3 6 Appreciate this may elementary and of course appreciate your help. Thanks again!
  5. Thanks Barand Made the amendment, works great. Thank you
  6. Ch0cu3r If you were a fine young blonde I'd offer to take you out for a drink for this, alas, I'll just have to say thanks. That was the ticket. Many thanks
  7. Hi everyone I have a requirement to create some reports and outputting these to a PDF. I'm using FPDF which seems to be rather user-friendly. I was hoping someone could help with me a problem I have regarding MySQL COUNT and PHP arrays. I have a table named 'faults' and within this a row called 'level'. There are three 'levels' = P1, P2, P3 that could populate this row. I wish to display the output into a PDF so it looks something like this: Total number of faults; P1 P2 P3 1 2 3 Where I'm falling short is how to perform the COUNT and then grab the data stick it into an array and output it to the PDF. The MySQL statement you see below, if put directly into phpMyAdmin, seems to do the trick, so I'm hoping I'm on the right track. So far I have this: <----OUTPUT OMITTED----> $result=mysqli_query($con, "SELECT COUNT(IF(level='P1',1, NULL)) 'P1', COUNT(IF(level='P2',1, NULL)) 'P2', COUNT(IF(level='P3',1, NULL)) 'P3' FROM faults"); //initialize counter $i = 0; //Set maximum rows per page $max = 25; while($row = mysqli_fetch_array($result)) { //If the current row is the last one, create new page and print column title if ($i == $max) { $pdf->AddPage(); //print column titles for the current page $pdf->SetY($y_axis); $pdf->SetX(25); $pdf->Cell(50,6,'Total P1s',1,0,'L',1); $pdf->Cell(50,6,'Total P2s',1,0,'L',1); $pdf->Cell(50,6,'Total P3s',1,0,'L',1); //Go to next row $y_axis = $y_axis + $row_height; //Set $i variable to 0 (first row) $i = 0; } //This bit definitely ain't right $p1 = $row['level']; $p2 = $row['level']; $p3 = $row['level']; $pdf->SetY($y_axis); $pdf->SetX(25); $pdf->Cell(50,6,$p1,1,0,'L',1); $pdf->Cell(50,6,$p2,1,0,'L',1); $pdf->Cell(50,6,$p3,1,0,'R',1); //Go to next row $y_axis = $y_axis + $row_height; $i = $i + 1; } //Send file $pdf->Output(); ?> Appreciate it must look a mess, but would appreciate someone cleverer than me pointing me in the right direction. Thanks for this and for your help so far!
  8. Ginerjm Understood mate. A wrapping of the knuckles was to be expected.
  9. Thanks Barand for your reply. Think I need to file this one under dufus. Seems there were no customer records to pull out, I thought there were. So yes, your comment was right. Apologies for wasting people's time. Thanks
  10. Hello all I have the need to join up two tables and display the output in a table. These tables are a 'Site Details' table and a 'Customer Details' table where the 'cust_id' (PK on the CD table and FK on the SD table) match. The MySQL statement (within PHP) I have works a treat in as much as the join seems to do the trick and join the two up on the correct row: <?php if($letter == 'ALL') {$query = mysqli_query($con, SELECT site_details.site_id, site_details.sitename, site_details.sitecode, site_details.postcode,customer_details.cust_number, customer_details.cust_fname FROM site_details LEFT JOIN customer_details ON site_details.cust_id = customer_details.cust_id ORDER BY sitename ASC); } I then display this data in a table as follows: <table class="table table-striped table-hover"> <thead> <tr> <th>Site Code</th> <th>Site Name</th> <th>Postcode</th> <th>Contact Name</th> <th>Contact Number</th> </tr> </thead> <tbody> Then want to display the records in the tables: <?php while($row = mysqli_fetch_assoc($query)) { ?> <tr> <td><?php echo $row['sitecode']; ?></td> <td><?php echo $row['sitename']; ?></td> <td><?php echo $row['postcode'];?></td> <td><?php echo $row['cust_fname']; ?></td> <td><?php echo $row['cust_number']; ?></td> </tr> <?php } ?> </tbody> </table> Where my lack of understanding lies are with arrays which I'm suspecting is part of the problem. With the above it echoes out the details from the 'Site Details' table no problem. I just can't get anything from the 'Customer Details' table. The answer as ever is probably staring me in the face. I would appreciate if someone could advise on where I'm going wrong please? Many thanks
  11. Thanks requinix Apologies for the delay. That works a treat. Absolute URL was what I needed to add. Thanks!
  12. Hello all Was hoping someone could help. I have a .htaccess file that contains the following: RewriteEngine On RewriteRule ^sites/([a-z0-9]+)/?$ sites.php?letter=$1 [NC,L,QSA] RewriteRule ^network-devices/([a-z0-9]+)/?$ network-devices.php?letter=$1 [NC,L,QSA] RewriteRule ^site/([0-9]+)/?$ site.php?site_id=$1 [NC,L] RewriteRule ^network-device/([0-9]+)/?$ network-device.php?device_id=$1 [NC,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php?%{QUERY_STRING} The problem I am having is that if I try to restrict access to a page via the following code I get the following error from Chrome: Code: if(!isset($_SESSION['username'])) { header('location: login'); } Chrome Error: I also get a similar error on other browsers so leads me to think that something strange is afoot in that .htaccess file. So for example, I can restrict access quite nicely to my index.php page. If I try enter it into my URL I get whisked away to: http://localhost:8888/<SITENAME>/login If I then try to browse to an area of the site called 'sites' I get the loop and see that the URL has now changed to: http://localhost:8888/<SITENAME>/sites/login Pretty sure that it should rather read: http://localhost:8888/<SITENAME>/login Is it immediately obvious to anyone as to what the issue could be? Thank you
  13. Hi mac_gyver Thanks for your swift response. In typical fashion I wrote this too hastily. Thinking about it what I actually wanted to do is have it so that when the form was filled and submitted both current timestamp and the timestamp + 4 days would be inserted in the the DB. I achieved it thanks to someone who posted the following: http://coursesweb.net/forum/insert-date-after-days-added-now-function-mysql-t32.htm My code therefore now resembles: "INSERT INTO faults (datetime, target_date) VALUES (NOW(), DATE_ADD(NOW(), INTERVAL 4 DAY))"); Had to convert the MySQL columns to a TIMESTAMP format but it now does the trick. Thanks
  14. Hello everyone Hoping someone could lend me a hand. I have a form that takes some end-user's details and adds the date and time into a MySQL table of when the form was submitted. I wish to display that date/time + 4 days ahead using PHP. I believe the MySLQ DATE_ADD should do the trick quite nicely. In fact plumbing the following statement into phpMyAdmin gives me exactly the results I require: SELECT DATE_ADD(`datetime`,INTERVAL 4 DAY) FROM `faults` WHERE fault_id = '51'; However, just having a pig of a time getting this displayed using PHP. I'm sure this is elementary so forgive me. Here's what I had in mind but is no working. Can someone please point me in the right direction: <?php $date_query = mysqli_query($con, "SELECT DATE_ADD(`datetime`,INTERVAL 4 DAY) FROM `faults` WHERE fault_id = '51'"); while($row = mysqli_fetch_assoc($date_query)){ echo $row ['datetime']; } ?> Many thanks for your help and advice.
×
×
  • 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.