-
Posts
24,565 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
Show us your table definition.
-
PHP isn't the only language ot there, and compiled code would be very difficult to spot.
-
Example <div> <img class='product-img' src='images/mac128.jpg' ></div> <div class='overlay'>Pre Order</br>NOW</div> CSS <style type='text/css'> .overlay { width: 60px; height: 60px; padding-top: 20px; border-radius: 50%; font-size: 8px; text-align: center; background-color: #E02222; color: #FFF; position: relative; top: -70px; left: 10px; z-index: 5; } </style> Result
-
Does $_FILES['photo']['error'] give any clues?
-
Generating XML from an html form and sending an attachment to e-mail
Barand replied to superzoom's topic in PHP Coding Help
You are creating an XML document in $doc, then right at the end, you decide to reference it as $xml instead of $doc. -
Select id that has more than one value in an in clause
Barand replied to Adamhumbug's topic in MySQL Help
Your hopes are not in vain select person_id , zones from ( select person_id , zones , find_in_set('301', zones) > 0 as has301 , find_in_set('401', zones) > 0 as has401 , find_in_set('501', zones) > 0 as has501 from ahtest ) checks WHERE has301 + has401 + has501 > 1; -
Select id that has more than one value in an in clause
Barand replied to Adamhumbug's topic in MySQL Help
You really have to stop storing your data as comma separated lists. I would expect that one solution could be along the same lines as that I gave you for the consecutive dates. What does the data look like in the table? -
It doesn't let you create a PDF once output has already been sent, therefore creating multiple pdfs in a single script doesn't appear to be an option. As an alternative I would suggest give users the option to select each product and create their pdfs separately, or create one pdf but put each product on a separate page Also, I prefer to put my pdf code in a separate file and create the pdf via a "create PDF" link and give the user the option of viewing or downloading the PDF. This version gives both the above options aswin_1.php <?php // // // CREATE YOUR OWN MYSQL CONNECTION HERE // // // function fetch_data($conn){ $output=''; $sql="SELECT * FROM product"; $result=mysqli_query($conn,$sql); $sno=0; while($row=mysqli_fetch_array($result)){ $output.= '<tr> <td><a href="aswin_2.php?product=' . $row["product_id"] . '">' . $row["product_id"] . '</a></td> <td>' .$row["product_name"].'</td> </tr>'; } return $output; } ?> <!DOCTYPE html> <html> <head> <title>Pdf Generation</title> <link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"> </head> <body> <br> <table style='width:400px; margin: 50px auto;'> <tr> <th>Id</th> <th>Name</th> </tr> <?php echo fetch_data($conn); ?> </table> <div style='width: 400px; margin: 20px auto;'> <a href="aswin_2.php?product=all" download>All products</a> </body> </html> aswin_2.php (creates the pdf) <?php // // // CREATE YOUR OWN MYSQL CONNECTION HERE // // // require_once '../tcpdf/tcpdf.php'; if (!isset($_GET['product'])) { exit; } if ($_GET['product']=='all') { $stmt = $conn->query("SELECT product_id , product_name FROM product ORDER BY product_id "); $obj_pdf= new TCPDF('P',PDF_UNIT,PDF_PAGE_FORMAT,true, 'UTF-8',false); $obj_pdf->SetCreator(PDF_CREATOR); $obj_pdf-> SetTitle("Product PDF"); $obj_pdf->SetHeaderData('', '',PDF_HEADER_TITLE,PDF_HEADER_STRING); $obj_pdf->SetHeaderFont(Array(PDF_FONT_NAME_MAIN, '',PDF_FONT_SIZE_MAIN)); $obj_pdf->SetHeaderFont(Array(PDF_FONT_NAME_DATA, '',PDF_FONT_SIZE_DATA)); $obj_pdf->SetDefaultMonospacedFont('helvetica'); $obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER); $obj_pdf->SetMargins(PDF_MARGIN_LEFT, '5' ,PDF_MARGIN_RIGHT); $obj_pdf->SetPrintHeader(false); $obj_pdf->SetPrintFooter(false); $obj_pdf->SetAutoPageBreak(TRUE,10); $obj_pdf -> SetFont('helvetica', '',12); foreach ($stmt as $row) { $obj_pdf->AddPage(); $content=''; $content .='<h4 align="center">Generate Pdf</h4><br> <table border="1" cellspacing="0" cellpadding="3"> <tr> <th>Id</th> <th>Name</th> </tr>'; $content .= "<tr> <td>{$row['product_id']}</td> <td>{$row['product_name']}</td> </tr> "; $content .= '</table>'; $obj_pdf->writeHTML($content); } $obj_pdf->Output('All Products','D'); } else { $stmt = $conn->prepare("SELECT product_id , product_name FROM product WHERE product_id = ? "); $stmt->bind_param('s', $_GET['product']); $stmt->execute(); $stmt->bind_result($product_id, $product_name); $stmt->fetch(); $obj_pdf= new TCPDF('P',PDF_UNIT,PDF_PAGE_FORMAT,true, 'UTF-8',false); $obj_pdf->SetCreator(PDF_CREATOR); $obj_pdf-> SetTitle("Product PDF"); $obj_pdf->SetHeaderData('', '',PDF_HEADER_TITLE,PDF_HEADER_STRING); $obj_pdf->SetHeaderFont(Array(PDF_FONT_NAME_MAIN, '',PDF_FONT_SIZE_MAIN)); $obj_pdf->SetHeaderFont(Array(PDF_FONT_NAME_DATA, '',PDF_FONT_SIZE_DATA)); $obj_pdf->SetDefaultMonospacedFont('helvetica'); $obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER); $obj_pdf->SetMargins(PDF_MARGIN_LEFT, '5' ,PDF_MARGIN_RIGHT); $obj_pdf->SetPrintHeader(false); $obj_pdf->SetPrintFooter(false); $obj_pdf->SetAutoPageBreak(TRUE,10); $obj_pdf -> SetFont('helvetica', '',12); $obj_pdf->AddPage(); $content=''; $content .='<h4 align="center">Generate Pdf</h4><br> <table border="1" cellspacing="0" cellpadding="3"> <tr> <th>Id</th> <th>Name</th> </tr>'; $content .= "<tr> <td>$product_id</td> <td>$product_name</td> </tr> "; $content .= '</table>'; $obj_pdf->writeHTML($content); $obj_pdf->Output("Product $product_id",'D'); } ?>
-
Yes No. If you want to pay someone to do it for you, post in the "job Offerings" forum. Otherwise, post the code you have already and tell us where you are having probems so we can help you with your coding.
-
How to solve: Trying to access array offset on value of type bool
Barand replied to OldGrim's topic in PHP Coding Help
or (cleaner) ... $data = dbarray($result); if (!$data) { $id = $title = $evday = null; } else { $id = $data['post_id']; $title = $data['post_title']; $evday = strtotime($data['post_date']); } -
How to solve: Trying to access array offset on value of type bool
Barand replied to OldGrim's topic in PHP Coding Help
So you called dbarray() 30 times. Twice it returned the array containing post data and 28 times it returned false. Yet every time you try to process it as though they all contain post data. Check that $data is not false before trying to get the $stuff. -
How to solve: Trying to access array offset on value of type bool
Barand replied to OldGrim's topic in PHP Coding Help
Your dbarray() function seems to return some weird stuff. -
How to solve: Trying to access array offset on value of type bool
Barand replied to OldGrim's topic in PHP Coding Help
Does var_dump($data) shed any light? -
You could save everyone's time by turning on php's error_reporting, display_errors, display_startup_errors in your php.ini file
-
I see in your query that you are selecting several columns named "id" When you use fetch_assoc() the column names must be unique otherwise $row["id"] will be overwritten by the last one (seller id) therefore you cannot reference the user id or catgory id etc. Use column aliases to differentiate. Now you can reference $row['pid'], $row['cid'] etc When producing output with various levels of headings and subheadings and subtotals, store your data in an array that reflects the output structure. For example... $data = [ 2 => [ 'seller_name' => 'Sasha', 'orders' => [ 10002 => [ 'lines' => [ 0 => [ 'purchase_price' => 200.00, 'uid' => 4, 'user_fullname' => 'yeewen' . . . ], 1 -> [ 'purchase_price' => 200.00, 'uid' => 4, 'user_fullname' => 'yeewen' . . . ] ] 'order_total' => 400.00 ] ], 'seller_total' = 400.00 ]; Then the processing becomes a set of nested loops... foreach ($data as $seller_id => $seller_data) { output seller heading foreach ($seller_data['orders'] as $order_no => $order_data) { output order heading foreach ($order_data['lines']) { output line data } output order subtotal } output seller subtotal accumulate grand total } output grand total
-
Shouldn't that be... the $adjective neighbors
-
-
How can I make the tryguess.php appear on the trynumber.php?
Barand replied to idk_php's topic in PHP Coding Help
All the seond script has to do is check the posted guess against the stored number and pass the result of that check back to the first script. Something like... session_start(); $resp = $_POST['guess'] <=> $_SESSION['correct_number']; header("Location: trynumber.php?response=$resp"); the first page can then check if a response was returned and what the value is. if $_GET['response'] == -1 then too low else if $_GET['response'] == 1 then too high else if $_GET['response'] == 0 correct -
You'll find other thing you can't do in MariaDB that you could in mysql, but you'll have fun finding them. Anyway, welcome.
-
Have you enabled php_mysqli extension in your php.ini file?
-
How do i cross join , Inner join and Group tables
Barand replied to sashavalentina's topic in MySQL Help
You are grouping by the condition category_name = 'Meat' This has two possible values (0 , 1) so you get 1 row for each value. Tubers just happens to be one of those where the condition evaluates to 0. You should GROUP BY <column name> Don't use SELECT *. Specify column names that you need. CROSS JOIN gives every combination of rows in table A joined with rows in table B so why would you want that here? For example Table A TableB ------- ------ a 1 b 2 c 3 SELECT a.col, b.col FROM tableA a CROSS JOIN tableB b; a 1 a 2 a 3 b 1 b 2 b 3 c 1 c 2 c 3 You seem to have gone overboard with unnecessary subqueries too. Try mysql> SELECT o.id -> , o.order_id -> , p.id -> , p.product_name -> , c.id -> , c.category_name -> FROM order_table o -> INNER JOIN product p ON o.product_id = p.id -> INNER JOIN category c ON p.product_category = c.id -> WHERE category_name = 'meat'; +----+----------+----+--------------+----+---------------+ | id | order_id | id | product_name | id | category_name | +----+----------+----+--------------+----+---------------+ | 4 | 10004 | 4 | Beef | 4 | Meat | +----+----------+----+--------------+----+---------------+- 1 reply
-
- 1
-
Best way is to do it manually, noting the steps, and then replicate those steps in code. Here are my neighbours and their dogs' names. Some have no dog, some have two. Allocate the dogs to their correct owners TABLE: neighbour TABLE: dog +-------+----------------+ +-------+----------------+-----------+ | ID | name | | ID | name | owner_id | +-------+----------------+ +-------+----------------+-----------+ | 1 | Peter | | 1 | Maxwell | ? | | 2 | Paul | | 2 | Hector | ? | | 3 | Mary | | 3 | Hugo | ? | | 4 | Fred | | 4 | Jasper | ? | | 5 | Wilma | | 5 | Coco | ? | | 6 | Barny | | 6 | Jaba | ? | | 7 | Betty | | 7 | Oliver | ? | +-------+----------------+ +-------+----------------+-----------+ The only way to do it is by using the "sorting hat" from Hogworts. Or manually.
-
I can't see your code ... $file = $im; ... helping much. If you want to write the GD image in memory (that was created by imagecreatefromjpeg()) back to the file in jpeg format, then use imagejpeg($im, $file); I do not know if this sequence has any cleansing effect though.
-
@gizmola I note your comments regarding dates and, had this been for a commercial marina with many comings and goings, stays of varying duration and future bookings, I too would have put them in the schema. However I was under the impression that this situation was more like allocating semi-permanent car-parking spaces to employees.