Jump to content

QuickOldCar

Staff Alumni
  • Posts

    2,972
  • Joined

  • Last visited

  • Days Won

    28

Community Answers

  1. QuickOldCar's post in MySQL lists generated in PHP was marked as the answer   
    Font has been deprecated a long time, use css style or style right in the html.
     
    I would suggest using rgb or hex versus normal colors so can do them all.
    I don't know how simple or advanced your application will be.
     
    If you need functions to use and convert to different color display formats let me know.
     
    Here is a simple example using a function to change the colors.
    <?php function showColor($color){ if(!isset($color) || empty($color)){ $color = "black"; } return "<p style='color:$color';>$color</p>"; } //dummy data $colorarray = array("red","orange","yellow","green","blue","indigo","violet","not-a-color"," "); ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Show color</title> </head> <body> <div> <?php foreach($colorarray as $thecolor){ echo showColor($thecolor); } ?> </div> </body> </html>
  2. QuickOldCar's post in help with _GET, assigning to variable and checking that variable was marked as the answer   
    Single = to assign, double == to compare if equal, triple === to compare if equal and also same type
     
    http://php.net/manual/en/language.operators.comparison.php
  3. QuickOldCar's post in pagination help if page number dont exist was marked as the answer   
    You would want to do the row count for this query
     
    $res = mysql_query("SELECT * FROM article LIMIT ".$per_page." OFFSET ".$offset);
     
    The $allrecords is being used to create pagination links all records with no offset or limit.
     
    Also check row like this...a number.
    if(mysql_num_rows($res) < 1){ header("Location: https://localhost/pagi/articles.php"); exit; } Can link back to the main script since you already set page to 1 if not set
  4. QuickOldCar's post in API Integration help was marked as the answer   
    For things like this I would typically run a script with cron and cache the data results.
    Most likely doing each of those 400 you said individually.
    The cron script would be connecting a timely manner looking for any changes and overwrite the cache file.
    Your script uses the local cached data.
  5. QuickOldCar's post in Security Questions About set_include_path and PEAR was marked as the answer   
    Have a look at $_SERVER['DOCUMENT_ROOT'] or dirname()
     
    If you set the include path and is the correct location is fine.
    PEAR comes with php as an extension.
     
    an example adding the separator so PEAR doesn't toss messages
    $directory_path = dirname(__FILE__) . DIRECTORY_SEPARATOR; require_once($directory_path . "/include/functions.php");
  6. QuickOldCar's post in Why at the beginning keeps saying undefined index with a session variable was marked as the answer   
    Before trying to use something first check if it exists.
    You are doing addition on the session values that won't exist the first time or until the first one was set using the form.
     
    Can set them to a default value of zero the first view
    <?php session_start(); if (!isset($_SESSION['conted'])) { $_SESSION['conted'] = 0; } if (!isset($_SESSION['contper'])) { $_SESSION['contper'] = 0; } if (isset($_POST['btn1'])) {               $_SESSION['conted'] = $_SESSION['conted'] + $_REQUEST['ed'];         $_SESSION['contper'] = $_SESSION['contper'] + 1;     echo "El contador de edad va en " . $_SESSION['conted'];     echo '<br>';     echo "El contador de personas va en " . $_SESSION['contper']; } ?>
  7. QuickOldCar's post in Auto Selection was marked as the answer   
    http://www.plus2net.com/php_tutorial/ajax_drop_down_list.php
  8. QuickOldCar's post in Simple php function working with Undefined offset ? was marked as the answer   
    You could also loop for just less than $n value rather than less or equals $n
    function plusmin ($tab) { $n = count($tab); $plus = 0; $min = 0; for ($i = 0; $i < $n; $i++) { if ($tab[$i] > 0){ $plus++; } elseif ($tab[$i] < 0){ $min++; } } if ($plus > $min) { $result = "+1"; } elseif ($plus < $min) { $result = "-1"; } elseif ($plus == $min){ $result = "0"; } return $result; }
  9. QuickOldCar's post in Parse error: syntax error, unexpected 'else' (T_ELSE) in C:\xampp new\htdocs\POSNICC\tt.php on line 201 was marked as the answer   
    Look at your last php block, you had an else where should be an echo
     
    You can work out the if else issues if there is any
     
    A suggestion would be to do all php processing above and the html display below in your code.
    <?php include_once("init.php"); // Use session variable on this page. This function must put on the top of page. if (!isset($_SESSION['username']) || $_SESSION['usertype'] != 'admin') { // if session variable "username" does not exist. header("location: index.php?msg=Please%20login%20to%20access%20admin%20area%20!"); // Re-direct to index.php exit; } else { error_reporting(0); if (isset($_GET['sid'])) { echo $_GET['sid']; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> <title>Simple invoice in PHP</title> <style type="text/css"> body { font-family: Verdana;; } div.invoice { border:1px solid #ccc; padding:10px; height:740pt; width:570pt; } div.company-address { border:1px solid #ccc; float:left; width:200pt; } div.invoice-details { border:1px solid #ccc; float:right; width:200pt; } div.customer-address { border:1px solid #ccc; float:right; margin-bottom:50px; margin-top:100px; width:200pt; } div.clear-fix { clear:both; float:none; } table { width:100%; } th { text-align: left; } td { } .text-left { text-align:left; } .text-center { text-align:center; } .text-right { text-align:right; } </style> </head> <body> <div class="invoice"> <div class="company-address"> <?php $sid = $_GET['sid']; $line = $db->queryUniqueObject("SELECT * FROM stock_sales WHERE transactionid='$sid' "); $mysqldate = $line->date; $phpdate = strtotime($mysqldate); $phpdate = date("d/m/Y", $phpdate); echo $phpdate; ?><?php echo $sid; ?> <?php $line4 = $db->queryUniqueObject("SELECT * FROM store_details "); ?> <?php echo $line4->name; ?> <br /> <?php echo $line4->address; ?>,<?php echo $line4->place; ?> <br /> LPhone <strong>:<?php echo $line4->phone; ?></strong> <br /> </div> <div class="invoice-details"> Invoice no : <?php echo $sid; ?> <br /> Date: <?php $sid = $_GET['sid']; $line = $db->queryUniqueObject("SELECT * FROM stock_sales WHERE transactionid='$sid' "); $mysqldate = $line->date; $phpdate = strtotime($mysqldate); $phpdate = date("d/m/Y", $phpdate); echo $phpdate; ?> </div> <div class="customer-address"> To: <br /> <?php echo $line->customer_id; $cname = $line->customer_id; $line2 = $db->queryUniqueObject("SELECT * FROM customer_details WHERE customer_name='$cname' "); echo $line2->customer_address; ?> <br /> 123 Long Street <br /> London, DC3P F3Z <br /> </div> <div class="clear-fix"></div> <table border='1' cellspacing='0'> <tr> <th width=250>Description</th> <th width=80>Quantity</th> <th width=100>Unit price</th> <th width=100>Total price</th> </tr> <?php $db->query("SELECT * FROM stock_sales where transactionid='$sid'"); while ($line3 = $db->fetchNextObject()) { ?> echo("<tr>"); echo("<td><?php echo $line3->stock_name; ?></td>"); echo("<td class='text-center'><?php echo $line3->quantity; ?></td>"); echo("<td class='text-right'><?php echo $line3->selling_price; ?></td>"); echo("<td class='text-right'><?php echo $line3->amount; ?></td>"); echo("</tr>"); } ?> echo("<tr>"); echo("<td colspan='3' class='text-right'>Sub total</td>"); echo("<td class='text-right'><?php $subtotal = $line3->subtotal; ?></td>"); echo("</tr>"); echo("<tr>"); echo("<td colspan='3' class='text-right'>VAT</td>"); echo("<td class='text-right'><?php $discount = $line3->discount; ?></td>"); echo("</tr>"); echo("<tr>"); echo("<td colspan='3' class='text-right'><b>TOTAL</b></td>"); echo("<td class='text-right'><b><?php $payment = $line3->payment; ?></b></td>"); echo("</tr>"); </table> </div> </body> </html> <?php echo "Error in processing printing the sales receipt"; } } ?>
  10. QuickOldCar's post in php session redirect issue was marked as the answer   
    I believe you want to use the $_SESSION['user'] versus $id for the redirect.
    if ($_SESSION['user']!='') {header("Location: affiliate-profile.php?id=".$_SESSION['user']);} Actually do you really need to pass the GET value to the script when can directly use their $_SESSION['user'] in the affiliate-profile.php script itself? Just send them to affiliate-profile.php and use the session values from there.
  11. QuickOldCar's post in Account removal... was marked as the answer   
    Personal information was hidden.
  12. QuickOldCar's post in Any help please was marked as the answer   
    Could do with two if's and actually use the variable are setting, then echo after
    if($xcatname) {     $query = "SELECT catdesc FROM `$t_cats` WHERE `catname` = '".$xcatname."'";         if ($resa = mysql_query($query)) {             while($rowa = mysql_fetch_assoc($resa)){                 $desc_msg = $rowa['catdesc'];             }         } } if($xsubcatname) {     $query = "SELECT subdesc FROM `$t_subcats` WHERE `subcatname` = '".$xsubcatname."'";         if ($resa = mysql_query($query)) {             while($rowa = mysql_fetch_assoc($resa)){                 $desc_msg = $rowa['subdesc'];             }         } } if($desc_msg){ echo '<div id="showad-textbox">'.$desc_msg.'</div><br>'; } Shouldn't use the outdated mysql_ functions and use mysqli_ or pdo
     
    Should also escape or use prepared statements for anything inserted into queries.
     
    Another thing is that when you fetch an array it returns both the numerical index and associative array, double the data. If you do not need the numerical array use mysqli_fetch_assoc
     
    There are example codes there can look over.
     
    Any reason are using LIKE?
    I would assume your categories are specific since not doing a while loop, in that case can just use an = versus LIKE
     
    If using LIKE for searching...
    Firstly would be using a while loop for multiple results.
    % are for wildcards
    If did have categories with similar words would want to place a % in front and after the term so can find any similar that at least contains the term.
    "SELECT catdesc FROM `$t_cats` WHERE `catname` LIKE '%".$xcatname."%'"
    "SELECT subdesc FROM `$t_subcats` WHERE `subcatname`LIKE '%".$xsubcatname."%'"
     
    I personally like using full-text search in boolean mode,
    When you get to using multiple where/and , then also multiple columns, full-text simplifies the queries and additionally makes for very specific searches.
  13. QuickOldCar's post in Flexibility of the table header was marked as the answer   
    Start using css and not tables.
     
    Create a wrapper for each row that can dynamically change via content within.
    Create dividers within those that can also dynamically change.
  14. QuickOldCar's post in inserting into table was marked as the answer   
    It's fine to do as that, just run a second query for the update.
×
×
  • 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.