Jump to content

PFMaBiSmAd

Staff Alumni
  • Posts

    16,734
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by PFMaBiSmAd

  1. $heading_column = 'FleetName'; $last_heading = null; while($row = mysql_fetch_assoc($Fleet)){ // detect a change in the heading value and output the new heading if($last_heading != $row[$heading_column]){ // detect if it is not the first heading - close out the previous section if($last_heading != null){ // your code to close the previous table... echo "</table>\n"; } // output the new heading here... echo "<table>\n"; echo "<tr><th>Fleet Name: </th><th>{$row['FleetName']}</th></tr>\n"; // save the new heading as the last_heading $last_heading = $row[$heading_column]; } // output the actual data here... echo "<tr><td>Ship Name: </td><td>{$row['ShipName']}</td></tr>\n"; echo "<tr><td>Detected: </td><td>"; if ($row['Detected'] == '1') echo 'Yes'; else echo 'No'; echo "</td></tr>\n"; echo "<tr><td>Hull: </td><td>{$row['HealthA']} / {$row['HealthB']}</td></tr>\n"; echo "<tr><td></td></tr>\n"; } // if there was any output - close out the last section if($last_heading != null){ // your code to close the previous table... echo "</table>\n"; } Also, I see in your code an extra $row_Fleet = mysql_fetch_assoc($Fleet); statement that is fetching and discarding the first row from your result set. You would probably want to remove that line from your code so that the first row of data doesn't turn up as missing.
  2. Persistent database connections cannot be 'saved'. You must still call the code on every page to get one of the existing persistent connections or to create a new persistent connection if an existing one is not available. Edit, Also, persistent connections only work on a very few web server/php configurations and in only the latest php versions.
  3. Your existing while(){} loop would be altered to use that logic to start and end each section when a new FleetName heading is detected.
  4. BTW - the above code is missing a single-quote on the end of FleetName'; i the first line.
  5. See the following pseudo code. You will need to read the comments in it and alter it to suit your needs - $heading_column = 'FleetName; $last_heading = null; while($row = your_fetch_assoc_statement){ // detect a change in the heading value and output the new heading if($last_heading != $row[$heading_column]){ // detect if it is not the first heading - close out the previous section if($last_heading != null){ // your code to close the previouse table... echo "close section<br />"; } // output the new heading here... echo "new section title - {$row[$heading_column]}<br />"; // save the new heading as the last_heading $last_heading = $row[$heading_column]; } // output the actual data here... echo "data - {$row['your_data']}<br />"; } // if there was any output - close out the last section if($last_heading != null){ // your code to close the previouse table... echo "close section<br ?>"; }
  6. The only thing that comes to mind is if you got the php binary that was complied with the opposite Windows complier, VC6 vs VC9, from the complier that was used for Apache or some of the XAMPP files.
  7. You have got a SPACE between the single-quote and the $username variable in the following line of code - $query = mysql_query("SELECT * FROM users WHERE username=' $username'"); You are asking the database to find values in the username column that match 'space$username'. I'm sure that wont' match any of the data values you have in your table. Remove the space that is in there.
  8. Php is a parsed, tokenized, and interpreted language. Unless you are using things like shell_exec() with operating system dependent commands, there's generally nothing you need to change when moving between different operating systems. Also, except for specific php language extensions that your code might be using, as long as you are not using any old depreciated features or functions or any of the lazy-way short-cuts, your php code will work when moving between different servers. What sort of problems or errors did you get when you tried this?
  9. You also need an echo statement with that - <?php echo WEB_ROOT ?>
  10. And, if you want to use some css that is not obsolete - <?php // list of colors (must be valid css color specifiers - name, HEX, RGB, ...) $color = array('red','green','blue'); // build tr css color classes (tr.c0, tr.c1, ...) $styles = ''; foreach($color as $key => $value){ $styles .= "tr.c$key {background-color:$value;}\n"; } $max_color = count($color) - 1; // build table content $content = "<table>\n"; $i = 0; while ($row = mysql_fetch_assoc($exec)){ $content .= "<tr class='c$i'>"; $content .= '<td>'.$row['brand_name'].'</td>'; $content .= '<td>'.$row['contact_name'].'</td>'; $content .= '<td>'.$row['contact_info'].'</td>'; $content .= '<td>'.$row['email'].'</td>'; $content .= '<td>'.$row['description'].'</td>'; $content .= "</tr>\n"; $i++; if($i > $max_color){ $i = 0; } } $content .= "</table>\n"; ?> <!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> <title>Cycle between table row colors</title> <style type="text/css"> table {border-collapse:collapse;} <?php echo $styles; ?> </style> </head> <body> <?php echo $content; ?> </body> </html>
  11. The following link would be worth reading - http://us3.php.net/manual/en/features.file-upload.php
  12. It would probably help if you defined "my server"? Is this a web server? An FTP server? As that would define what protocol(s) could be used to accomplish this. It would also help if you defined - "my computer"? What operating system? How small is x seconds? Does it already have php installed (either as CLI or as a web server extension)?
  13. To resize an image or do any other image manipulation, you must make an uncompressed bitmap version of that image. jpeg, gif, png are compressed image formats, where sections of the image are sampled to get the colors used in that section and then each section is compressed, taking into account just the range of colors used in that section instead of all the possible colors. An 2560x1440 image could easily take 20-50MB of memory. If you turn on full php error reporting (error_reporting = E_ALL and display_errors = ON) and comment out any header() statements in your code, php will likely output an error that would tell you why the code is failing.
  14. So, have you even visited the web site of one of the php mailer classes of your choice and looked at an example showing how to use SMTP Authentication with it? In programming, lack of attempt = automatic failure. You have got to at least try or I could move this thread to the Freelancing Forum section for you if you want to pay someone to do this and get it working on your web host?
  15. You can use PEAR:Mail or one of the two scripts I already suggested. At the point of calling the mail() function in the current script, you would instead create an instance of whatever mailer class you are using, configure it to use SMTP Authentication (password and mail box name/email address) against a mail box you have on the mail server, pass it the to and from address, the subject, and the message body, and call the send method.
  16. The code you posted at the start of this thread isn't using PEAR. It is using the php mail() function.
  17. If your web host told you that you unconditionally need to use SMTP Authentication in order to send an email through the mail server at your web host, you will need to do so. The php mail() function does not support SMTP Authentication. You could write a script that opens a socket with the mail server and exchanges SMTP commands, including those needed for SMTP Authentication, but it will be easier if you just use an existing php mailer class that can do this for you. See the phpmailer - http://phpmailer.worxware.com/ or swift mailer - http://swiftmailer.org/
  18. You wouldn't use a switch/case for this. You would use simple conditional logic to test the value as you loop through the result set - $q = "SELECT * FROM categories"; $r = mysqli_query ($dbc, $q); if($r){ //If $r ran OK while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)){ if($row['id_cat'] == $group){ $h1 = $row['group']; } // the rest of your code in the loop } }
  19. As to why you are getting an error at the mysql_fetch_array statement, no one here can tell that just by looking at your query. There's nothing logically wrong with it, which is why always using the above suggested logic is important. Here is what the code for that query should look like - <?php $sql = "SELECT DISTINCT manufacturer_reel,manufacturer_reel_id FROM kit order by manufacturer_reel"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Please Choose an Option</option>"; while($row = mysql_fetch_array($result)) { if($row['manufacturer_reel_id']==@$cat){echo "<option selected value='$row[manufacturer_reel_id]'>$row[manufacturer_reel]</option>"."<BR>";} else{echo "<option value='$row[manufacturer_reel_id]'>$row[manufacturer_reel]</option>";} } echo "</select>"; } else { // no results found, display message. echo 'No manufacturers were found'; } } else { // query failed, handle error. $user_message = "Sorry, a server error is preventing this page from working!"; $system_message = "Query failed: $sql<br />\nReason: " . mysql_error(); echo $user_message; trigger_error($system_message); } ?> Provided you have the error_reporting and display_errors/log_errors settings set as suggested, the above code will tell you if and why your query is failing.
  20. Do you need help in actually fetching the data from the result set or in storing the information in a way that your script can access the name/status pairs?
  21. The logic that thorpe showed in his post, should be used for every SELECT query you have in your code so that you can handle when an error of some kind occurs with the query and when the query matches no data. For INSERT, UPDATE, and DELETE queries, you would use similar logic but use mysql_affected_rows instead of mysql_num_rows. Where he put the comment // $result is good to use is where you would build your select menu, because the query executed without an error and it matched one or more rows in your table. Also by putting the code that access the result of the query at this point in the logic, you prevent the generation of follow-on errors that make your web pages look unprofessional. Where he put the comment // no results found, display message is where you would output a message such as 'No manufacturers were found' or do you intend your code to produce a select menu that has no choices and a person wondering why the menu doesn't work? Where he put the comment // query failed, handle error. is where you would output an error message to the visitor to let him know that the page experienced fatal problem that prevents it from working - 'Sorry, a server error is preventing this page from working!' AND where you report and display/log the error information so that you can find and fix the problem. For mysql_query errors (and for mysql_connect and mysql_select_db errors), you can use mysql_error to get the reason why the query failed. If you use trigger_error to handle the error, you can use php's built in error_reporting/display_errors, log_errors settings to cause the error to be printed during development and logged on a live server. For that block of code, you should do something like - } else { // query failed, handle error. $user_message = "Sorry, a server error is preventing this page from working!"; $system_message = "Query failed: $sql<br />\nReason: " . mysql_error(); echo $user_message; trigger_error($system_message); } To get the above trigger_error() code to work, you should always have error_reporting set to E_ALL (or to a -1) and for development, display_errors should be on, and on a live server, display_errors should be off and log_errors should be on. Not all query errors are due to things that are under your control. Once you debug why your query is failing and fix the problem, you still need logic like this in your code so that query errors due to actual problems on the server that are out of your control are handled properly by your code.
  22. I'm guessing you are referring to the readability of the resulting dump of information? Enclose the output in <pre>...</pre> tags so that the new-line characters that are being output by the print_r/var_dump will be rendered in the browser.
  23. This topic has been moved to PHP Coding Help. http://www.phpfreaks.com/forums/index.php?topic=331109.0 Not a mysql question.
  24. What makes you think someone can see your login details if they browse to your con.php file? Did you try this yourself and look at what you get?
  25. If both the $_POST and $_FILES arrays are empty, it generally means that you exceeded the post_max_size setting. What does a phpinfo() statement show for the post_max_size setting and what size file did you attempt to upload?
×
×
  • 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.