![](https://forums.phpfreaks.com/uploads/set_resources_1/84c1e40ea0e759e3f1505eb1788ddf3c_pattern.png)
jarvis
Members-
Posts
543 -
Joined
-
Last visited
Everything posted by jarvis
-
Thanks ignace. Would that work though? Is it really that damn simple?
-
Hi, i've the following basic script which tells me the distance between 2 postcodes - which you need to enter the postcodes for. So one could be my house and one the nearest sports hall All postcode info is stored in a db table What I'd like to do is alter this for sports halls within the uk. When you enter your postcode, it returns the 5 nearest sports halls. I've no idea where to start. My code is: <?php require_once('../mysql_connect.php');// Connect to the db if (isset($_POST['submitted'])) { // Handle the form. if (!empty($_POST['start'])) { $start = escape_data($_POST['start']); } else { $start = FALSE; echo '<p>Please enter a valid postcode!</p>'; } if (!empty($_POST['finish'])) { $finish = escape_data($_POST['finish']); } else { $finish = FALSE; echo '<p>Please enter a valid postcode!</p>'; } #Convert the post code to upper case and trim the variable $start = strtoupper(trim($start)); $finish = strtoupper(trim($finish)); #Remove any spaces $start = str_replace(" ","",$start); $finish = str_replace(" ","",$finish); #Trim the last 3 characters off the end $start = substr($start,0,strlen($start)-3); $finish = substr($finish,0,strlen($finish)-3); #query the db $query_start = "SELECT latitude, longitude FROM postcodes WHERE postcode = '$start' LIMIT 1"; $result_start = mysql_query ($query_start); $num = mysql_num_rows ($result_start); // How many users are there? if ($num > 0) { // If it ran OK, display the records. while ($row = mysql_fetch_array ($result_start, MYSQL_ASSOC)) { #Assign variables $lat1 = $row["latitude"]; echo $row["latitude"] .' - lat<br/>'; $long1 = $row["longitude"]; echo $row["longitude"] .' - lat<br/>'; } } else { echo '<p>post code not found</p>'; } echo $query_start; echo '<hr>'; $query_finish = "SELECT latitude, longitude FROM postcodes WHERE postcode = '$finish' LIMIT 1"; $result_finish = mysql_query ($query_finish); $num = mysql_num_rows ($result_finish); // How many users are there? if ($num > 0) { // If it ran OK, display the records. while ($row = mysql_fetch_array ($result_finish, MYSQL_ASSOC)) { #Assign variables $lat2 = $row["latitude"]; echo $row["latitude"] .' - lat<br/>'; $long2 = $row["longitude"]; echo $row["longitude"] .' - lat<br/>'; } } else { echo '<p>post code not found</p>'; } echo $query_finish; function getDistance($lat1, $long1, $lat2, $long2){ #$earth = 6371; #km change accordingly $earth = 3960; #miles #Point 1 cords $lat1 = deg2rad($lat1); $long1= deg2rad($long1); #Point 2 cords $lat2 = deg2rad($lat2); $long2= deg2rad($long2); #Haversine Formula $dlong=$long2-$long1; $dlat=$lat2-$lat1; $sinlat=sin($dlat/2); $sinlong=sin($dlong/2); $a=($sinlat*$sinlat)+cos($lat1)*cos($lat2)*($sinlong*$sinlong); $c=2*asin(min(1,sqrt($a))); $d=round($earth*$c); return $d; } #Returns the distance in miles $distance = getDistance($lat1, $long1, $lat2, $long2); } echo '<p>'.$distance.'</p>'; ?> <form method="post" action="index.php"> start: <input type="text" name="start" value="<?php if (isset($_POST['start'])) echo $_POST['start']; ?>" /> finish: <input type="text" name="finish" value="<?php if (isset($_POST['finish'])) echo $_POST['finish']; ?>" /> <input type="submit" name="submit" value="Go" /> <input type="hidden" name="submitted" value="TRUE" /> </form> Any help is very much appreciated! Thanks in advanced
-
Sorry to bump this once again but could do with a hand! Thanks
-
[SOLVED] Pass value from a function into mysql query
jarvis replied to jarvis's topic in PHP Coding Help
Damn, so simple! Thanks, you rock!! -
Hi, Am struggling with trying to pass a value from a function into a mysql query. The function: function get_id() { $query1 = "SELECT `article_category_id` FROM `article_categories` WHERE `category` = 'Features'"; $result1 = mysql_query($query1) or die( "Could not execute SQL query" ); $row = mysql_fetch_array ($result1, MYSQL_ASSOC); $id = $row['article_category_id']; #echo $id; } The query: $query = " SELECT DISTINCT articles.article_id, articles.title, LEFT(articles.description, 150) AS abbrev, articles.status, article_associations.article_id, article_categories.category, DATE_FORMAT(articles.date_entered,'%M') as month, DATE_FORMAT(articles.date_entered,'%Y') as year, DATE_FORMAT(articles.date_entered,'%d %M %Y') as date FROM articles INNER JOIN (article_categories INNER JOIN article_associations ON article_categories.article_category_id = article_associations.article_category_id) ON articles.article_id = article_associations.article_id WHERE articles.article_id = article_associations.article_id AND article_associations.article_category_id=".get_id()." AND article_associations.approved = 'Y' AND status !='0' AND DATE_FORMAT(articles.date_entered,'%Y') = '$year' ORDER BY date_entered DESC LIMIT 3"; What I need to do is get the id value from the function and pass it into the query. Simple? I cannot get my head around it so any help is very much appreciated right now! Many thanks
-
Hi suresh64633, Currently I've a database with articles. Each article can be assigned to a particular category. When you click a category, it shows the articles relevant to it. This works fine. At present, the articles list in reverse month order, starting with the current month. So: August July June etc etc What I'd like to do, as the articles are for every 2 months, I'd like to list them like so: July - August May - June March - April January - February So the articles which currently display under August and under July will display under the one heading of July - August and so on. Does this help? Thanks in advanced
-
Sorry to bump, any help with this would be much appreciated!
-
Hi all, I've got the following script which lists all the articles by month order for a given year. This works fine. However, it simply lists by month order Aug, Jul, Jun, may etc for a given year. What I need to do is display 2 monthly ie: jan - feb mar - apr may - jun jul - aug etc etc My script is: <?php // This page displays all articles within a specified category $page_title = 'View Featured News Articles'; require('includes/header.html'); require_once('../mysql_connect.php'); // Connect to the db // Set the category id $id="18"; // Set the sorting order by months if (isset($_GET['year'])) { // $month will be appended to the links $year = $_GET['year']; } else { // Set a default sorting month to current month $year= date('Y'); } $query=" SELECT articles.article_id, articles.title, LEFT(articles.description, 50) AS abbrev, articles.status, article_associations.article_id, article_categories.category, DATE_FORMAT(articles.date_entered,'%M') as month,DATE_FORMAT(articles.date_entered,'%Y') as year, DATE_FORMAT(articles.date_entered,'%d %M %Y') as date FROM `articles` INNER JOIN (article_categories INNER JOIN article_associations ON article_categories.article_category_id = article_associations.article_category_id) ON articles.article_id = article_associations.article_id WHERE article_associations.article_category_id=$id AND DATE_FORMAT(articles.date_entered, '%Y') = '$year' AND status='1' "; $result = @mysql_query ($query); // Run the query. $num = mysql_num_rows ($result); // How many users are there? if ($num > 0) { // If it ran OK, display the records. echo "<h1>There is currently $num new articles for the month of $order_by</h1>"; echo '<table cellpadding="3" cellspacing="3" border="0" align="center" width="100%">'; echo '<tr> <td><p><b>Title:</b></p></td> <td><p><b>Description:</b></p></td> <td> </td> <td> </td> </tr>'; // Fetch and print all the records. $bg = '#CCCCCC'; // Set the background color. while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $category = '' .$row['5']. ''; $bg = ($bg=='#CCCCCC' ? '#FFFFFF' : '#CCCCCC'); // Switch the background color. echo '<tr bgcolor="' . $bg . '"> <td>' .$row['1']. '</td> <td>'; $extract = $row['2']; // find position of last space in extract $lastSpace = strrpos($extract, ' '); // use $lastSpace to set length of new extract and add ... echo substr($extract, 0, $lastSpace).'... '; echo '</td>'; echo '<td>'.$row['6'].'</td>'; echo "<td><a href=\"articles.php?aid={$row['0']}\">Read More...</a></td>"; echo '</tr>'; } echo '</table>'; echo '<h1 style="text-align: right; color: #AE0026;">'.$category.'</h1>'; echo '<p> </p>'; } else { // Not records in related to that category ID. echo '<p class="error">There are currently no news articles!</p>'; } $startYear = "1 january 2006"; //get the starting year function printYears($var) { $id="18"; //include the category id for the links $start = strtotime($var); //timestamp of the entered date $now = strtotime("Now"); //timestamp of now so it does not write anything in the future while ($now > $start) //while the start is less than now { echo '<a href="news_archive_annually.php?s=&id=' . $id . '&year=' . date("Y", $now) .'">'.date(" Y", $now).'</a>'; echo " | "; $now = strtotime("-1 year", $now); // subtract a month from the start timestamp } } printYears($startYear); //execute the function mysql_close(); // Close the database connection. require('includes/footer.html'); ?> I have no idea how to do this so any help is very much appreciated! Thanks in advanced
-
You have lowercase n on name but in the query it's uppercase? What happens if you echo the query out to see what happens? Also, if you have access to PHPMyAdmin, run the query direct but change the id numbers to those that you're actually trying to update. It may help show you were the error is.
-
What happens if you define the url then call that in the header redirect, i.e // Start defining the URL. $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); // Check for a trailing slash. if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // Chop off the slash. } // Add the page. $url .= '/index.php'; ob_end_clean(); // Delete the buffer. header("Location: $url");
-
Please can you post your code so we can take a look - thanks
-
Is that test.php or does test.php call in the above?
-
This is a great link and makes one for you from your company logo or image: http://tools.dynamicdrive.com/favicon/
-
Sorry to bump this one but am going nuts trying to work it out! Thanks
-
Aren't you missing a close tag for the table? //If that was the sixth column, and the eighth row, end the table. if (($i == 6) && ($j == ) { echo '</tr></table><br /><br /><br /><br />'; $i = 0; $j = 0; } So I can see you've ended the table here, however, you then go to: //If that was the sixth column, and not the eighth row, end the row, and start a new one. elseif (($i == 6) && ($j != ) { echo '</tr><tr>'; $i = 0; $j++; } else { $i++; } There after there isn't a close tag - am only looking quickly so apologies if not!
-
Hi hookit, Are you trying to add data into the table but you want to check whether those fields are already used to prevent duplicate entries or are youyou trying to search those fields?
-
[SOLVED] varable not echoing anything at all
jarvis replied to jigsawsoul's topic in PHP Coding Help
As smerny says - <?php echo $tablerows; ?> Just tried it with your code and that worked fine -
Found this floatinf on the net: <!-- Instructive notes: 1. to use the if (isset($_POST['submit'])) construct, the submit button must have a name defined as 'submit' 2. if each of the checkboxes has been named with the same name (ie 'fruit') followed by a pair of square brackets '[]', when the form is submitted, the $_POST superglobal will have a variable named $_POST['fruit'] that represents an array containing array elements from only those checkboxes that have been checked. 3. count() returns the number of elements in an array. here it returns '0' if no checkboxes are checked. This could be because $_POST['fruit'] is not set, or because $_POST['fruit'] represents an array that has been set but has no elements. if we change the if statement to if (isset($_POST['fruit'])), the statements in the 'if' block are never executed, so $_POST['fruit'] is not set and must evaluate to null. count() accurately returns '0' when its parameter is null. 4. the value of each element in the array $_POST['fruit'] is determined by the value attribute of each of the checkboxes. 5. note that in the absence of an 'action = "some_script.php" attribute in the form element, the browser reloads this script when the submit button is clicked. --> <html> <head> <title>checkbox help</title> </head> <?php if (isset($_POST['submit'])) { $fruit = $_POST["fruit"]; $how_many = count($fruit); echo 'Fruits chosen: '.$how_many.'<br><br>'; if ($how_many>0) { echo 'You chose the following fruits:<br>'; } for ($i=0; $i<$how_many; $i++) { echo ($i+1) . '- ' . $fruit[$i] . '<br>'; } echo "<br><br>"; } ?> <body bgcolor="#ffffff"> <form method="post"> Choose a fruit:<br><br> <input type="checkbox" name="fruit[]" value="apples">apples <br> <input type="checkbox" name="fruit[]" value="oranges">oranges <br> <input type="checkbox" name="fruit[]" value="peaches">peaches <br> <input type="checkbox" name="fruit[]" value="mangos">mangos<br> <input type="submit" name = "submit"> </form> </body> <html> May help!?
-
Thanks perrij3, I think im sort of there(?), I use: // Set the sorting order by months if (isset($_GET['month'])) { // $month will be appended to the links $month = $_GET['month']; } else { // Set a default sorting month to current month $month= date('F'); } // Set the sorting order by years if (isset($_GET['year'])) { // $year will be appended to the pagination links $year = $_GET['year']; } else { // Set a default sorting year to current year $year= date('Y'); } They pass the selected value into the query. It seems that the months one works for August only and if you select the years, nothing happens. Hmmm....
-
Hi, I'm :'( to sort this one. It's driving me mad literally - I'm pulling a list of articles out of a DB with the following query $query = " SELECT articles.article_id, articles.title, LEFT(articles.description, 50) AS abbrev, articles.status, article_associations.article_id, article_categories.category, DATE_FORMAT(articles.date_entered,'%M') as month,DATE_FORMAT(articles.date_entered,'%Y') as year, DATE_FORMAT(articles.date_entered,'%d %M %Y') as date FROM articles INNER JOIN (article_categories INNER JOIN article_associations ON article_categories.article_category_id = article_associations.article_category_id) ON articles.article_id = article_associations.article_id WHERE articles.article_id = article_associations.article_id AND article_associations.article_category_id=$id AND article_associations.approved = 'Y' AND status='1' AND (DATE_FORMAT(articles.date_entered,'%M') = '$month' AND DATE_FORMAT(articles.date_entered,'%Y') = '$year') ORDER BY date_entered DESC"; I then use 2 functions to create loops - one for months (current -> january): echo '<p>Sort By:</p>'; $year = date("Y"); //get the current year $startDate = "1 january".$year; // set the end date to current year function printMonths($var) { $id="18"; //include the category id for the links $start = strtotime($var); //timestamp of the entered date $now = strtotime("Now"); //timestamp of now so it does not write anything in the future while ($now > $start) //while the start is less than now { echo '<a href="news_archive.php?s=&id=' . $id . '&month=' . date("F", $now) .'">'.date("F", $now).'</a>'; echo " | "; $now = strtotime("-1 month", $now); // subtract a month from the start timestamp } } printMonths($startDate); //execute the function One for the years $startYear = "1 january 2006"; //get the starting year function printYears($var) { $id="18"; //include the category id for the links $start = strtotime($var); //timestamp of the entered date $now = strtotime("Now"); //timestamp of now so it does not write anything in the future while ($now > $start) //while the start is less than now { echo '<a href="news_archive.php?s=&id=' . $id . '&year=' . date("Y", $now) .'">'.date(" Y", $now).'</a>'; echo " | "; $now = strtotime("-1 year", $now); // subtract a month from the start timestamp } } printYears($startYear); //execute the function Although I've got articles with dates back to Aug 08, it simply wont work. I then thought about combining them: $startYear = "1 january 2006"; //get the starting year function printCombi($var) { $id="18"; //include the category id for the links $start = strtotime($var); //timestamp of the entered date $now = strtotime("Now"); //timestamp of now so it does not write anything in the future while ($now > $start) //while the start is less than now { echo '<a href="news_archive.php?s=&id=' . $id . '&year=' . date("Y", $now) .'&month=' . date("F", $now) .' ">'.date("M Y", $now).'</a>'; echo " | "; $now = strtotime("-1 month", $now); // subtract a month from the start timestamp } } printCombi($startYear); //execute the function Although I'd rather they were seperate, i think it will need to be done like the latter, unless I alter the query. What I need is simply the current month -> Jan of the current year. Then ideally to select a year, it will then show say, Dec -> Jan 2008. Any help is much appreciated! Thanks
-
Oh jesus, it was that simple!? :-( So in order to maximise it's benefits, would I add a folder called font, add my particular font to that dir and then reference it in the code? Or does the font still need to be installed in the server font dir? Thanks again!
-
Hi all, I've found this brill script which can produce a graphic of your text with a given font: <?php header("Content-type: image/png"); //Picture Format header("Expires: Mon, 01 Jul 2003 00:00:00 GMT"); // Past date header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Consitnuously modified header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Pragma: no-cache"); // NO CACHE /*image generation code*/ //create Image of size 350px x 75px $bg = imagecreatetruecolor(350, 75); //This will make it transparent imagesavealpha($bg, true); $trans_colour = imagecolorallocatealpha($bg, 0, 0, 0, 127); imagefill($bg, 0, 0, $trans_colour); //Text to be written $helloworld = isset($_GET['text']) ? $_GET['text'] : "hello World"; // White text $white = imagecolorallocate($bg, 255, 255, 255); // Grey Text $grey = imagecolorallocate($bg, 128, 128, 128); // Black Text $black = imagecolorallocate($bg, 0,0,0); #$font = 'arial.ttf'; //path to font you want to use $fontsize = 20; //size of font //Writes text to the image using fonts using FreeType 2 imagettftext($bg, $fontsize, 0, 20, 20, $grey, $font, $helloworld); //Create image imagepng($bg); //destroy image ImageDestroy($bg); ?> Simple question, how would you use the above for mutliple graphics and how do you use it on a page? I've tried adding other information around it and it simply errors or won't show anything else! Am new to this side of things so please note this is not me being ignorant, just trying to learn & work it out! Thanks
-
Thanks scooby545 although I don't thin that would do what I'm after! Effectively, I'm on a page such as www.mydomain.com/article.php?id=7 or www.mydomain.com/article.php?id=77 This is a single script - article.php which calls in the relevant info depending on the id. On that page is a link, say send to friend: echo '<a href="send_to_friend.php" onClick="return popup(this, \'send_to_friend\')">Send to friend</a>'; If they click the link, a pop up window opens which is now running send_to_friend.php. What I need to do, is pass www.mydomain.com/article.php?id=7 or www.mydomain.com/article.php?id=77 to that script and include it in the email. Hope that makes a bit more sense? Thanks
-
Hi all, I can't believe how awkward this is. I've a send to friend link on a page: echo '<a href="send_to_friend.php" onClick="return popup(this, \'send_to_friend\')" ><img src="images/envelope.jpg" width="30" height="30" alt="send to friend" border="0"/></a>'; This then opens up a new window with a simple form - your name, friends name and email and comments. What I want to do is add the original page URL into the email. This is a dynamic site so the url could be www.mydomain.com/article.php?id=7 So I've added the above to my article.php page. All I need to do is pass the effectively dynamic URL through to the send_to_friend.php script. I've tried: $ref = getenv("HTTP_REFERER"); $referer = $_SERVER['HTTP_REFERER']; $ref=@$HTTP_REFERER; To no avail Any help much appreciated!
-
EDIT - APOLOGIES - wrong code! <?php // This page displays all articles within a specified category $page_title = 'View Featured News Articles'; require('includes/header.html'); require_once('../mysql_connect.php'); // Connect to the db // Set the category id $id="18"; // Set the sorting order by months if (isset($_GET['month'])) { // $month will be appended to the links $order_by = $_GET['month']; } else { // Set a default sorting month to current month $order_by= date('F'); } // Set the sorting order by years if (isset($_GET['year'])) { // $year will be appended to the pagination links $year = $_GET['year']; } else { // Set a default sorting year to current year $year= date('Y'); } $query = " SELECT articles.article_id, articles.title, LEFT(articles.description, 50) AS abbrev, articles.status, article_associations.article_id, article_categories.category, DATE_FORMAT(articles.date_entered,'%M') as month,DATE_FORMAT(articles.date_entered,'%Y') as year, DATE_FORMAT(articles.date_entered,'%d %M %Y') as date FROM articles INNER JOIN (article_categories INNER JOIN article_associations ON article_categories.article_category_id = article_associations.article_category_id) ON articles.article_id = article_associations.article_id WHERE articles.article_id = article_associations.article_id AND article_associations.article_category_id=$id AND article_associations.approved = 'Y' AND status='1' AND DATE_FORMAT(articles.date_entered,'%M') = '$order_by' AND DATE_FORMAT(articles.date_entered,'%Y') = '$year' ORDER BY date_entered DESC"; $result = @mysql_query ($query); // Run the query. $num = mysql_num_rows ($result); // How many users are there? if ($num > 0) { // If it ran OK, display the records. echo "<h1>There is currently $num new articles for the month of $order_by</h1>"; echo '<table cellpadding="3" cellspacing="3" border="0" align="center" width="100%">'; echo '<tr> <td><p><b>Title:</b></p></td> <td><p><b>Description:</b></p></td> <td> </td> <td> </td> </tr>'; // Fetch and print all the records. $bg = '#CCCCCC'; // Set the background color. while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $category = '' .$row['5']. ''; $bg = ($bg=='#CCCCCC' ? '#FFFFFF' : '#CCCCCC'); // Switch the background color. echo '<tr bgcolor="' . $bg . '"> <td>' .$row['1']. '</td> <td>'; $extract = $row['2']; // find position of last space in extract $lastSpace = strrpos($extract, ' '); // use $lastSpace to set length of new extract and add ... echo substr($extract, 0, $lastSpace).'... '; echo '</td>'; echo '<td>'.$row['7'].'</td>'; echo "<td><a href=\"articles.php?aid={$row['0']}\">Read More...</a></td>"; echo '</tr>'; } echo '</table>'; echo '<h1 style="text-align: right; color: #AE0026;">'.$category.'</h1>'; echo '<p> </p>'; } else { // Not records in related to that category ID. echo '<p class="error">There are currently no news articles!</p>'; } echo '<p>Sort By:</p>'; $year = date("Y"); //get the current year $startDate = "1 january".$year; // set the end date to current year function printMonths($var) { $id="18"; //include the category id for the links $start = strtotime($var); //timestamp of the entered date $now = strtotime("Now"); //timestamp of now so it does not write anything in the future while ($now > $start) //while the start is less than now { echo '<a href="news_archive.php?s=&id=' . $id . '&month=' . date("F", $now) .'">'.date("F", $now).'</a>'; echo " | "; $now = strtotime("-1 month", $now); // subtract a month from the start timestamp } } printMonths($startDate); //execute the function echo '<p> </p>'; $startYear = "1 january 2006"; //get the starting year function printYears($var) { $id="18"; //include the category id for the links $start = strtotime($var); //timestamp of the entered date $now = strtotime("Now"); //timestamp of now so it does not write anything in the future while ($now > $start) //while the start is less than now { echo '<a href="news_archive.php?s=&id=' . $id . '&year=' . date("Y", $now) .'">'.date(" Y", $now).'</a>'; echo " | "; $now = strtotime("-1 year", $now); // subtract a month from the start timestamp } } printYears($startYear); //execute the function mysql_close(); // Close the database connection. require('includes/footer.html'); ?> The years show but cannot get the sql to work - sorry!