Jump to content

Jeremysr

Members
  • Posts

    199
  • Joined

  • Last visited

    Never

Everything posted by Jeremysr

  1. This should do it: $lines = file('your_filename'); foreach ($lines as $line) { $line = chop($line); mysql_query("INSERT INTO table1 values('', '$line');"); } Edit: whoops, too late. It won't let me delete my post...
  2. I would make an array of submenu arrays like this: $sub_menus = array( 'Home' => array( 'home_subnav1.php' => 'Home subnav item 1', 'home_subnav2.php' => 'Home subnav item 2', 'home_subnav3.php' => 'Home subnav item 3' ), 'Reports' => array( 'reports_subnav1.php' => 'Reports subnav item 1', 'reports_subnav2.php' => 'Reports subnav item 2', 'reports_subnav3.php' => 'Reports subnav item 3' ), ... ); Then you can print the subnav the same way as the main menu: foreach ($sub_menus[$selected] as $url => $text) { // $selected is the main menu item that is selected, for example 'Home' if ($text == $subnav_selected) { $class = 'class="selected"'; } else { $class = ''; } echo "<a $class href='$url'>$text</a>"; }
  3. Put the menu items in an associative array where the keys are the URL's, and the values are the text of the link. Then loop through the array, printing out each menu item. $main_menu = array( 'home.php' => 'Home', 'reports.php' => 'Reports', 'admin.php' => 'Administration', 'logout.php' => 'Log Out' ); foreach ($main_menu as $url => $text) { if ($text == $selected) { $class = 'class="selected"'; } else { $class = ''; } echo "<a $class href='$url'><span>$text</span></a>"; }
  4. This will probably work: where p.products_id = p2c.products_id and products_status = '1' and (p2c.categories_id = 48 or p2c.categories_id = 49 or p2c.categories_id = 50) Or this: where p.products_id = p2c.products_id and products_status = '1' and (p2c.categories_id >= 48 and p2c.categories_id <= 50)
  5. Maybe you have a '?>' in one of your str_replace()'s? (I've had this problem before, with putting '?>' in a comment...)
  6. In this case it's optional, but if a table or column name contains spaces or is a MySQL keyword, you have to put it in backquotes.
  7. For me, exec('df') only displays one line but passthru('df') displays all of them. So try using passthru(). (It prints the output by default, or copies the output into a string variable if you give the variable as the second argument.)
  8. I would just do this: <?php if (strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== FALSE) { echo '<link rel="stylesheet" type="text/css" href="stylesheet.css" />'; } else if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) { echo '<link rel="stylesheet" type="text/css" href="iestyle.css" />'; } ?>
  9. The only problem with your regex is that it won't work if there is a '<' inside the <p> tags. This should work: preg_match('/<p>(.*?)<\/p>/', $text, $matches); $p_tag_text = $matches[1];
  10. Use number_format(): $bignum = 12000000; echo number_format($bignum, 0, '', ''); // echos 12000000
  11. date() will format a timestamp into a string for you. It looks like you want something like this: $date = date('Y-m-d H:i:s', $timestamp);
  12. time() returns the current timestamp in GMT (which is the same as UTC, right?) So here are the two values you want: $now = time(); $seven_days_ago = $now - 60*60*24*7; 60*60*24*7 is the number of seconds in 7 days (60 seconds in a minute, 60 minutes in an hour, 24 hours in a day, and 7 days.)
  13. Not like that, but this will do what you want: $_GET['section'] = 'section2'; include '../incl/myfile.php';
  14. Yes, I do this all the time. The code would be something like this: // This will execute after they submit the form, going to this page again if ($_POST) { // Check username and password, log them in if (password_is_correct($_POST['username'], $_POST['password'])) { $_SESSION['loggedin'] = true; } else { echo "Error: Wrong password.<br />"; } } // Print log in form if they're not logged in, otherwise print success message if (!$_SESSION['loggedin']) { echo '<form method="post" action="login.php"> ... </form>'; } else { echo 'You have been logged in successfully!'; }
  15. The only way I can think of is doing it manually like this: function round_to_quarter($num) { $floor = floor($num); $fractional_part = $num - $floor; if ($fractional_part < 0.125) { return $floor; } if ($fractional_part < 0.375) { return $floor + 0.25; } if ($fractional_part < 0.625) { return $floor + 0.5; } if ($fractional_part < 0.875) { return $floor + 0.75; } return $floor + 1; } It's not very pretty, but I can't think of another way.
  16. You may have to put 'date' in backquotes because 'DATE' is a MySQL keyword. "INSERT INTO shows (showname, showlabel, location, arena, `date`) VALUES ('".$_POST['names']."','".$_POST['showlabel']."','".$_POST['location']."','".$_POST['arena']."','".$_POST['date']."')";
  17. Looks like there is no $get_country['country_name'] or $get_country['iso_code'].
  18. I would make the search form use the GET method (<form action="get">), then when linking to the next page, have the search result in the URL like you said.
  19. Your UPDATE queries should look like this: UPDATE `account` SET age = "'.$age.'", email = "'.$email.'", dob = "'.$dob.'" This will update ALL rows in the table to those values, however, so you might want to add a WHERE clause to only update one row. Something like: UPDATE `account` SET age = "'.$age.'", email = "'.$email.'", dob = "'.$dob.'" WHERE user_id = "'.$user_id.'"'
  20. To help debug it, try changing the get_country() function to this: function get_country(){ $user_ip = check_ip(); $temp = explode('.',$user_ip); $ipnum = 16777216*$temp[0] + 65536*$temp[1] + 256*$temp[2] + $temp[3]; $qry = "SELECT * FROM `geo_ip` WHERE '$ipnum' >= `begin_num` AND '$ipnum' <= `end_num`"; echo "$qry<br /><br />"; // debugging code $qry = mysql_query($qry) or die(mysql_error()); $get_country = mysql_fetch_array($qry) or die(mysql_error()); print_r($get_country); // debugging code if ($get_country['country_name']=="") { return 'Unknown'; } else { return $get_country['country_name'].':'.$get_country['iso_code']; } }
  21. Divide the number of votes for a particular answer by the total number of votes and multiply by 100, and you'll have the percentage for that particular answer.
  22. When executing php from the command line it should set the $argc (number of arguments) and $argv (array of the actual arguments) variables. $first_argument = $argv[1];
  23. First load your two images: $image1 = imagecreatefrompng('image1.png'); $image2 = imagecreatefrompng('image2.png'); Then create your new image calculating the width and height from the previous two images. If you want the images side-by-side, the width of the new image will be the width of the first image plus the width of the second image. $new_image_width = imagesx($image1) + imagesx($image2); $new_image_height = max(imagesy($image1), imagesy($image2)); // Make height the height of the taller image. $new_image = imagecreatetruecolor($new_image_width, $new_image_height); Finally, copy the two images onto your new image and output the image. imagecopy($new_image, $image1, 0, 0, 0, 0, imagesx($image1), imagesy($image1)); imagecopy($new_image, $image2, imagesx($image1), 0, 0, 0, imagesx($image2), imagesy($image2)); imagepng($new_image); See imagecopy() for more information.
  24. Take a look at the set_error_handler() function. It allows you to specify a function you've created to handle PHP errors.
×
×
  • 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.