Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. I used the Data Modeller in MySQL Workbench
  2. To associate the student's parent with the student
  3. In that case I have added back the category_subject table. I don't know if you need them but I also added in the enrollment of students on to courses (where "course" is a series of classes)
  4. Which is it? Can a subject belong to more than one category, or only one category
  5. I recommend you read up on data normalization before going any further http://forums.phpfreaks.com/topic/273634-best-way-to-set-up-tables-when-multiple-values/?do=findComment&comment=1408360
  6. Psycho, I think the "lecutures" table in the diagram is the "lecturer" table thara, from what you stated above
  7. Without knowing the precise relationships between your entities it is impossible to say whether it is correct or not. Also without knowing what processes you require and what you expect to produce from the data there is no way of knowing if it is fit for purpose. The best I can do it to say it looks reasonable.
  8. Approach what? All you have shown us is function that does nothing.
  9. Then normalize the table data +--------+ +----------+ | Table1 | | image | +--------+ +----------+ | id PK|---------<| T1_id PK| | name | | img_no PK| | url | | img | +--------+ +----------+
  10. You would get the header information by querying your customer table.
  11. This code must be worthy of an award Let's add the comments // Store current date in Y-m-d format . . . // Get date from database (which should be in Y-m-d format) // Convert this to Unix time // Convert this Unix time back to Y-m-d // Convert the Y-m-d back to Unix time and compare against the current stored Y-m-d date converted to Unix time instead of if ($order_transaction_date == $current_date) {
  12. Executing the query and looping through the result set should print the data. The code I posted was working, giving this from my test data DATA mysql> select * from invoice; +----+------------+----------+------------+-----------------+--------------------+-------------+----------------+-----------------+--------------+ | id | invoice_no | order_no | order_date | completion_date | artwork | customer_po | order_quantity | comments | order_amount | +----+------------+----------+------------+-----------------+--------------------+-------------+----------------+-----------------+--------------+ | 1 | 123 | A1234 | 2014-04-15 | 2014-06-09 | Logo designing | B985 | 1 | A few words | 2500.00 | | 2 | 123 | A1235 | 2014-04-16 | 2014-06-10 | Brochure designing | B986 | 1 | NULL | 10000.00 | | 3 | 123 | A1236 | 2014-04-17 | 2014-06-11 | Photography | B987 | 1 | Proofs attached | 2000.00 | +----+------------+----------+------------+-----------------+--------------------+-------------+----------------+-----------------+--------------+ OUTPUT
  13. Remove "COUNT(oid) as num, " from your query. Using an aggregation function (COUNT) in a query without a GROUP BY clause will return only a single row.
  14. Also, select only the columns you want to output in the query and in the order you want them to appear. That way it's a simple loop to output the cell values EG $db = new mysqli(HOST,USERNAME,PASSWORD,'test'); // use your credentials class INVPDF extends FPDF { var $id; var $today; var $widths; var $heads; var $aligns; var $formats; var $db; //constructor function INVPDF($invno, $db) { parent::fpdf(); $this->id = $invno; $this->db = $db; $this->today = date('jS M Y'); $this->heads = array('Order Date', 'Graphixide Order No', 'Artwork', 'PO #', 'Quantity', 'Amount', 'Comments'); $this->widths = array (25, 40, 40, 20, 20, 25, 25); $this->aligns = array ('C','C','L','C','C','R','L'); $this->formats = array (0,0,0,0,0,1,0); } //Page header function Header() { //Arial bold 15 //Title $this->SetFont('Arial','B',15); $this->setXY(35,20); $this->Cell(0,10,'INVOICE '.$this->id,0,2,'R'); $this->SetFont('Arial','B',10); $until = date ('jS F Y', strtotime($this->today)); $this->Cell(0,4,$until,0,2,'R'); //Line break $this->Ln(5); for ($i=0; $i<7; $i++) { $this->Cell ($this->widths[$i], 8, $this->heads[$i], 1, 0, 'C', 1); } $this->Ln(; } //Page footer function Footer() { //Position at 1.5 cm from bottom $this->SetY(-15); //Arial italic 8 $this->SetFont('Arial','I',9); //Page number $this->Cell(0,4,$this->PageNo().' / {nb}',0,0,'R'); } function makeInvoice() { $sql = "SELECT DATE_FORMAT(order_date, '%d-%m-%Y') as odate , order_no , artwork , customer_po , order_quantity , order_amount , comments FROM invoice WHERE invoice_no={$this->id} "; $res = $this->db->query($sql) or die($this->db->error); $this->SetFont('Arial','',9); if ($res->num_rows > 0) { while ($r = $res->fetch_row()) { foreach ($r as $c => $value) { if ($this->formats[$c]) { $value = number_format($value, 2); } $this->Cell($this->widths[$c],5,$value,'LR',0, $this->aligns[$c]); } $this->Ln(5); } } } } # invpdf class $invno = 123; //Instantiation of inherited class $pdf = new INVPDF($invno, $db); $pdf->Open(); $pdf->AliasNbPages(); $pdf->setLeftMargin(10); $pdf->setRightMargin(10); $pdf->SetFont('Helvetica','',; $pdf->SetDrawColor(102); $pdf->SetFillColor(220); $pdf->AddPage(); $pdf->makeInvoice(); $pdf->output();
  15. 1. You need to "submit" the form to send the data to the server. 2. Unless you specify "post" as the form's method it will default to "get" so you would need to use $_GET instead of $_POST
  16. Easiest way to process an XML file is with simpleXML library http://uk3.php.net/manual/en/book.simplexml.php
  17. Try putting a semicolon after use bromleyone ;
  18. There you go again, always looking for the easy way out :-)
  19. try $dt1 = new DateTime('tomorrow'); $dt2 = new DateTime('2015-01-01'); $di = DateInterval::createFromDateString('next weekday'); $dp = new DatePeriod($dt1, $di, $dt2); $count = 0; foreach ($dp as $d) { $dt = $d->format('D M j'); $wd = $d->format('w'); if ($wd != 5) { // not Friday ++$count; echo "$dt<br>"; // optional } } echo "<br>Total days - $count";
  20. You don't like to hang about for a reply, do you? Calculate age by subtracting year of birth from year now, but if you haven't yet reached your birthday this year then subtract 1. Simples! For example SELECT thedate , CASE WHEN DATE_FORMAT(CURDATE(),'%m%d') >= DATE_FORMAT(thedate,'%m%d') THEN YEAR(CURDATE()) - YEAR(thedate) ELSE YEAR(CURDATE()) - YEAR(thedate) - 1 END as age FROM dates WHERE CASE WHEN DATE_FORMAT(CURDATE(),'%m%d') >= DATE_FORMAT(thedate,'%m%d') THEN YEAR(CURDATE()) - YEAR(thedate) ELSE YEAR(CURDATE()) - YEAR(thedate) - 1 END BETWEEN $agefrom AND $ageto
  21. Don't publish passwords
  22. WHERE date BETWEEN CURDATE() - INTERVAL 7 DAY AND NOW() - INTERVAL 60 MINUTE
  23. Define "the last hour". It is now 11:29 (my time) so do you want to exclude everything since 11am, or do you you mean everything in the last 60 minutes to be excluded?
  24. Yes. For the following example to work you would need a database schema called "test" containing a table "person" CREATE TABLE `person` ( `id` int(3) unsigned zerofill NOT NULL AUTO_INCREMENT, `name` varchar(45) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 then a simple example would be <?php // connect to database server $db = new mysqli(HOST,USERNAME,PASSWORD,'test'); // use your credentials error_reporting(-1); $message = ''; if (isset($_POST['name']) && !empty($_POST['name'])) { // sanitize the input $name = $db->real_escape_string($_POST['name']); // insert into the database $sql = "INSERT INTO person (name) VALUES ('$name')"; $db->query($sql); } // list current names from database $sql = "SELECT name FROM person"; $res = $db->query($sql); // are there currently any names? if ($res->num_rows > 0) { $message = '<h3>Current Names</h3>'; while ($row = $res->fetch_assoc()) { $message .= $row['name'] . '<br>'; } } $message .= "<br>Please enter another name and click \"Submit\" "; ?> <html> <head> <title>Example 2</title> </head> <body> <?php echo $message; ?> <hr/> <form method="post" action=""> Name <input type='text' name='name' placeholder="Enter your name"> <br/> <br/> <input type="submit" name="btnSubmit" value="Submit"> </form> </body> </html>
  25. Frankly, I have no idea. With all your "thing" references there is no way of knowing exactly what you are trying to do in order to answer that question, but something along the lines of INSERT INTO database2(col1,col2,col3) SELECT thing1, 'text', '$content' FROM database1 but I do not how how you want to derive $content from the code you gave
×
×
  • 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.