Jump to content

PFMaBiSmAd

Staff Alumni
  • Posts

    16,734
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by PFMaBiSmAd

  1. I think you should slow down and fix one problem at a time. To retrieve existing posts and comments, that have a parent child relationship, you will need to do a self join of the table to itself. The will get the parent (original blog post) information joined with all the child (comment) information. There are a large number of examples posted on the Internet of how to do this common type of query.
  2. Your comment form would need to supply the id of the original post as a hidden field.
  3. Someone posted above how to properly call the addItem() method with the three parameters. If you want to literally echo what the resulting php statement is, instead of executing it, you would enclose the statement in double-quotes (so that the three parameters get replaced with their value) and escape the first $ (so that the object in $paymentRequest is not replaced with its actual value) - echo "\$paymentRequest->addItem($start_number,$productName,$price);";
  4. I would store the user_id, rather than the username.
  5. The three ->addItem() parameters are the actual values/variables holding the values. You are trying to make them into a string that looks like how it would get published in a book. $paymentRequest->addItem($start_number,$productName,$price);
  6. At some point your code is treating $m like it is a number, instead of a formatted string. What's your code from the point where you are assigning the formatted string to $m through to the point where you are displaying it?
  7. Here's an example of what has been suggested. Using a data driven design, where you define a data structure someplace (array, database table), and use general purpose code, that you don't have to modify to add/remove/change the data, that takes care of outputting or processing the information - // define a data structure that the code will use $stations['EANE'] = array('city'=>'Ft. Wayne','contact'=>'xx@xxxx.com'); $stations['WANE'] = array('city'=>'Ft. Wayne','contact'=>'xx@xxxx.com'); $stations['WISH'] = array('city'=>'Indianapolis','contact'=>'xx@xxxx.com'); $stations['WISH LWS'] = array('city'=>'Indianapolis','contact'=>'xx@xxxx.com'); $stations['WLFI'] = array('city'=>'Lafayette','contact'=>'xx@xxxx.com'); $stations['WNDY'] = array('city'=>'Marion','contact'=>'xx@xxxx.com'); // at some point, you have validated the submitted data and stored it in a named variable $var_station = $_POST['station']; // Begin section to send station dependent emails if(!isset($stations[$var_station])){ // the submitted station doesn't exist, handle that condition here... // should only occur due to a programing error or someone submitting their own data echo 'The submitted station does not exist.'; } else { // $var_station is one of the defined stations $to = $stations[$var_station]['contact']; $subject = "New Discrepancy for $var_station"; $message = "<html> <head> <title>New Record Added</title> </head> <body> <p>A new discrepancy has been added for:<br />Station: <strong>$var_station</strong></p><p>Log Date: <strong>$var_date</strong><br />Log Time: <strong>$var_time</strong><br />Trouble Source: <strong>$var_source</strong><br />Description: <strong>$var_description</strong><br />Content: <strong>$var_titleID</strong><br />Loss: <strong>$var_loss</strong><br />Operator: <strong>$var_operator</strong></p> <p>DO NOT reply to this email! For further assistance please contact Dave Sturgeon at <a href='mailto:dave.sturgeon@wishtv.com'>dave.sturgeon@wishtv.com</a> or Gerry Inks at <a href='mailto:gerry.inks@linmedia.com'>gerry.inks@linmedia.com</a>.</p> </body> </html>"; $headers = "From: LIN Discrepancy System <>"; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $sent = mail($to,$subject,$message,$headers); } Once you have a defining data structure, you would also use it everywhere that data is referenced - // produce the option list for the form $station_options = ''; foreach($stations as $station=>$arr){ $legend = "$station - {$arr['city']}"; $station_options .= "<option value='$station'>$legend</option>\n"; } // echo the above $station_options variable inside the <select></select> tags to build the complete select drop-down
  8. Your shouldn't be repeating blocks of code that only differs in the data it operates on. A switch/case statement is for running different code in each case, i.e. insert code, update code, delete code... Your switch/case statement should be replaced with code that validates that the input data is one of the permitted values, then use the (one) variable holding that value in the the message you are building. The code to build the message would only appear once. Also, the global keyword only has meaning inside of a function definition (those outside of a function definition just wasted your time typing them), and even inside of a function it should not be used. You should be passing the values into a function as call-time parameters. Another way of looking at this, if a function requires a long list of variables that are present in your main application, it's likely that the code in your function is part of your application and shouldn't be in a function.
  9. This post seems to be the question that you asked in your first thread. Merging the two threads together...
  10. A) What does your question have to do with a third party script? What third party script are you using? B) If your question concerns how to insert data into a database, there are countless tutorials posted on the Internet showing how to do basic operations like inserting data into a database. Your question isn't something that programming help forum is for, i.e. to show you something that you should learn first before doing it for your data. If on the other hand, you have written code that attempts to insert data into a database and it doesn't work, you could post your code and any error or symptom on a programming help forum and get help with the problem.
  11. String data values must be enclosed by single-quotes in the query. And for some reason you still have an unused file statement in your code. You must know what each statement does and why it is in your code and what it contributes to the overall goal. Otherwise it shouldn't be in your code.
  12. The code needs to save the new $row['iroom'] value into $lastLocation so that just a change in the value will result in closing the previous section/starting a new section - $lastLocation = $row['iroom'];
  13. @White_Lily, The destination is an (optional) path and the filename. Programming is an exact science, Please don't post replies unless you absolutely know what the answer is.
  14. The reason the data in the query is empty is because of the for(){} loop. When $c is zero (the first pass through the for loop), none of that code sets any values, but your INSERT query is executed anyway. See the following on how you could be accessing and using the data - <?php ini_set('auto_detect_line_endings', true); $handle = fopen("GeneratedList.csv", "r+"); fgetcsv($handle, 100000, ","); // get and discard the header row while (($data = fgetcsv($handle, 100000, ",")) !== FALSE) { $supplier_reference = $data[0]; $quantity = $data[1]; $price = $data[2]; $wholesale_price = $data[3]; // your code that uses the data goes here... } fclose($handle);
  15. Here's another question - if you are looping over the data using fgetcsv, why do you also have a file statement in your code to read it all at once into an array?
  16. I was going to mention this in your previous thread, but why do you have the for(){} loop in your code? You can reference all the elements of the $data array at one time and since the array indexes are 0-3 (for a count of 4 elements), your code will never have $c == 4
  17. mysql_query doesn't support multiple sql statements separated with ;, because too many programmers don't validate external input being put into query statements and php wanted to prevent injected sql from doing things like dropping tables. You need to execute each query statement separately.
  18. If you have a login script, you have a session variable that contains the user_id of the logged in member. You would use that user_id to filter the content/data that the page produces so that only the items that belong to that user are displayed.
  19. If you are defining or retrieving data in index.php, after the point where you have included header.php, that data does not exist at the time the header.php code is executed. Programming does not have the ability to go back in time. Using php include statements to paste together a page can only produce a very basic page. To do what you need, you must switch to a concept of having all the main php 'business' logic first on the page. That php code produces content that is stored in variables (different variables for the title, meta tags, navigation links, content...) Then you output your HTML document at the end of the code, echoing the php variables at the correct point to give you the output that you want.
  20. You would typically display the username, along with changing the navigation to include a logout link, so that the person would have a way to log out if desired. @White_Lily, having someone go to your site and see an example of a popup, ISN'T a coding example, and doesn't help. The OP specifically asked -
  21. What exactly is in the database? What does the following show when added inside of the while(){} loop - echo '<pre>'; var_dump($row); echo '</pre>';
  22. For your main navigation (what you have shown in this thread), you would use something like the following - <?php // define main navigation (used to build navigation links and to validate the page that is requested) $default_page = 'home'; $main_navigation['home'] = 'HOME'; $main_navigation['news'] = 'NEWS'; $main_navigation['galleries'] = 'GALLERIES'; // process page request and include the requested content $page = isset($_GET['page']) ? strtolower(trim($_GET['page'])) : $default_page; if(!isset($main_navigation[$page])){ // invalid page requested, use default $page = $default_page; } include "$page.php"; // produce main (i.e. these go to the root page without any extra get parameters) navigation - $main_nav = ''; foreach($main_navigation as $key=>$value){ $main_nav .= "<li><a href='?page=$key'>$value</a></li>"; } // output navigation in the actual HTML document - ?> <ul class="topMenu"> <?php echo $main_nav; ?> </ul>
  23. Since you haven't shown the desired navigation. Do you want all the galleries to be listed in the main navigation, or after you click on a main GALLERY link, you want to replace the navigation with a list of the galleries and for either case, what defines your galleries? How many of them, what are the id's, ...? Also, you should use an array (or a database table) to define your navigation, so that all you need to do is change the array to add, remove, or alter the navigation. Using a switch/case requires you to actually edit the program logic every time you want to change the navigation.
  24. @White_Lily, Please read the question that was asked in the thread.
  25. That method requires more code and the test for empty/not-empty is more complicated.
×
×
  • 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.