PHP - Moved: Code For Adding Teasers To All Pages
This topic has been moved to PHP Applications.
http://www.phpfreaks.com/forums/index.php?topic=354302.0 Similar TutorialsHello everyone, I am not a php programmer, but I would like to solve a problem regarding math with PHP. I was looking around on the web on how to add (in this case digits) using PHP. I found out that adding two strings using a . I can then echo out the results; so far so good. My question however is as follow. How do I add up information from multiple pages? Let's say on one page (let's call it weekly.php) I have my weekly expenses of $300, and on the second page (let's call it monthly.php) I have my monthly expenses of $1400. I would like the result (weekly + monthly) to be displayed (echo'ed out) on the third page (let's call it totalamount.php). I don't want to take advantage of anyone's time, so I am not asking for the entire solution (code) unless you want to , but I would be just happy to be pointed in the right direction, I will do the rest on my own. Thank you very much for your time. Cheers, Luigi Hi there, I've been trying to implement pagination to an existing script that displays products, but at present only displays next and back buttons. The number of products is now increasing and we would like to show the number of pages of results but the tutorials I've been going through seem to use a very different way of displaying the results to the script we currently have. Does anyone have any suggestions how I could add pagination to this form..... // Build Pagination $ByPage = ($prod_rows * $prod_cols); $qnav = "SELECT devbg_products.*, devbg_categories.*, devbg_subcategories.* FROM devbg_products LEFT JOIN devbg_categories ON devbg_products.ItemCategory = devbg_categories.CategoryID LEFT JOIN devbg_subcategories ON devbg_products.ItemSubcategory = devbg_subcategories.SubcategoryID WHERE devbg_products.ItemCategory = " . sql($cgid); $rnav = mysql_query($qnav) or die(mysql_error()); $rows = mysql_num_rows($rnav); if($rows > $ByPage) { $pages = ceil ($rows / $ByPage); echo "<br>\n"; echo "<table align='center'>\n"; echo "<tr>\n"; echo "<td align=center><font face=verdana size=2>"; echo "<form method='POST' action='ShowCategory.php'>\n"; echo "<input type='hidden' name='Start' value='" . ($Start - $ByPage) . "'>\n"; echo "<input type='hidden' name='CategoryID' value='" . $_REQUEST["CategoryID"] . "'>\n"; echo "<input type='hidden' name='SubcategoryID' value='" . $_REQUEST["SubcategoryID"] . "'>\n"; if (($Start - $ByPage) <> -$ByPage) { echo "<input class='sub' type='submit' value='<<< Back' name='btnBack'>\n"; echo "</form>\n"; echo "</td>\n"; } echo "<td>\n"; echo "<form method='POST' action='ShowCategory.php'>\n"; echo "<input type='hidden' name='Start' value='" . ($Start + $ByPage) . "'>\n"; echo "<input type='hidden' name='CategoryID' value='" . $_REQUEST["CategoryID"] . "'>\n"; echo "<input type='hidden' name='SubcategoryID' value='" . $_REQUEST["SubcategoryID"] . "'>\n"; if ($Start + $ByPage < $pages * $ByPage) { echo "<input class='sub' type='submit' value='Next >>>' name='btnNext'>"; } echo "</form>\n"; echo "</td>\n"; echo "</tr>\n"; echo "</table><br><br>\n"; } Hi, I have some code which displays my blog post in a foreach loop, and I want to add some social sharing code(FB like button, share on Twitter etc.), but the problem is the way I have my code now, creates 3 instances of the sharing buttons, but if you like one post, all three are liked and any thing you do affects all of the blog post. How can I fix this? <?php include ("includes/includes.php"); $blogPosts = GetBlogPosts(); foreach ($blogPosts as $post) { echo "<div class='post'>"; echo "<h2>" . $post->title . "</h2>"; echo "<p class='postnote'>" . $post->post . "</p"; echo "<span class='footer'>Posted By: " . $post->author . "</span>"; echo "<span class='footer'>Posted On: " . $post->datePosted . "</span>"; echo "<span class='footer'>Tags: " . $post->tags . "</span>"; echo ' <div class="addthis_toolbox addthis_default_style "> <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a> <a class="addthis_button_tweet"></a> <a class="addthis_counter addthis_pill_style"></a> </div> <script type="text/javascript">var addthis_config = {"data_track_clickback":true};</script> <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=webguync"></script>'; echo "</div>"; } ?> This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=352551.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=349989.0 This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=355963.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=346715.0 Great conversation, wrong board. This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=357967.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=348274.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=356195.0 This topic has been moved to CSS Help. http://www.phpfreaks.com/forums/index.php?topic=358122.0 Hi all, I've been working with PHP for the past month to develop a simple web-site. It has two pages that are served dynamically - the events page and the members page. These are public pages. It has 3 other static pages. I've created the database tables in MYSql. The events page has one table. And the teachers page has a few more - particularly - one primary table for member basics, another for member address. These are one to one with the primary driver being the member basic table since it will also include an active/inactive flag. The 2 files that get used are member credentials, and member specialties. These have one to many relationship with basics table. So far I've been using PHPadmin to create dummy data. But my next step is to create an admin page for the events - where the admin can maintain any event. Then I need to create an admin page for the users. (Further down the line each user will be able to maintain their own events and information.) I was actually hoping to find a code generator to help with these. I know it would be a great learning experience to do them on my own. But I would also like to move a little faster than glacial speed. I'm an RPG programmer by day. So I have programming experience - just new to the web. I've looked at MySQl Table Editor from phpguru. But it used Pear - which I'm not using. And it's not clear to me whether/how it will handle the one to many relationships. I also looked at PhpMyEdit - but it looks like overkill and some of the documentation I've seen recommends that the first column in every table be unique(auto incremented) and I haven't done that with the children tables that have a one to many relationship. And I'm not quite sure why I would do that. Can anyone recommend a tool??? And/or a really good tutorial that includes multiple file being updated at the same time? I'd rather not reinvent the wheel. I apologize for the long first post. I've tried to google - but I actually kind of overwhelmed by the amount of material I find on PHP. Thanks. Vic Hello, Here's the weird thing, some of the pages shows the results, and some pages just won't show results at all, and I'm not getting any errors here is the one that doesn't Code: [Select] <? function display_mptt($user) { global $db; // retrieve the left and right value of the $root node $sql2 = "SELECT * from mptt where id='25'"; $result2 = mysql_query($sql2 ,$db); if(!$row2 = mysql_fetch_array($result2)) echo mysql_error(); echo '<h1>Users List</h1>'; // start with an empty $right stack $right = array(); // now, retrieve all descendants of the $root node $sql = "SELECT * from mptt WHERE 'left' BETWEEN '".$row2['left']."' AND '".$row2['right']."' ORDER BY 'left' ASC"; $result = mysql_query($sql ,$db); // display each row while ($row = mysql_fetch_array($result)or die(mysql_error())) { // only check stack if there is one $count = mysql_num_rows($result); if (count($right)>0) { // check if we should remove a node from the stack while ($right[count($right)-1]<$row['right']) { array_pop($right); } } // display indented node title // add this node to the stack $var3 = '10'; echo "<table width='589' border='1'> <tr> <th>ID</th> <th>Name</th> </tr>"; echo "<tr><td><a href=\"user.php?id=".$row['id']."\">".$row['id']."</a></td>"; echo "<td>" . $row['title'] ." </td>"; echo "</tr>"; echo "</table>"; $right[] = $row['right']; } } display_mptt(1); ?> and here is the page that does Code: [Select] <? function display_mptt($user) { global $db; $id = $_GET['id']; // retrieve the left and right value of the $root node $sql2 = "SELECT * from mptt where id= ".$id.""; $result2 = mysql_query($sql2 ,$db); if(!$row2 = mysql_fetch_array($result2)) echo mysql_error(); echo '<h1>Your Tree</h1>'; // start with an empty $right stack $right = array(); // now, retrieve all descendants of the $root node $sql = "SELECT * from mptt WHERE `left` BETWEEN ".$row2['left']." AND ".$row2['right']." ORDER BY 'left' ASC"; $result = mysql_query($sql ,$db); // display each row while ($row = mysql_fetch_array($result)) { // only check stack if there is one if (count($right)>0) { // check if we should remove a node from the stack while ($right[count($right)-1]<$row['right']) { array_pop($right); } } // display indented node title echo str_repeat(' ',count($right)).$row['title']."<br>"; // add this node to the stack $right[] = $row['right']; } } display_mptt(1); ?> Hi Everyone, I have an ecommerce store that I have done some coding for, and each category has some coding to create pages to display items in that category. For some reason, I am getting a couple of "ghost" pages on the end of a couple categories. For example, look at this page: http://www.autismcommunitystore.com/view.php?category=4 Pages 5 & 6 are blank - page 4 has the last of the items in the category. I have a table called prods_to_cats which connects the products and the categories (a many to many relationship). I'm posting the code here - could someone just let me know if they spot something that looks like trouble? Thank you in advance for your time! Code: [Select] <? $category=$_REQUEST['category']; $showcategory=$category; include 'connect.php'; $thiscategory = mysql_query("SELECT * FROM category WHERE category_id=$showcategory", $dbh); $thisrow = mysql_fetch_array($thiscategory); $this_des=$thisrow["category_description"]; $this_text=$thisrow["category_text"]; $titlekey="Products listed in $this_des at Autism Community Store 877-422-5932"; // If current page number, use it // if not, set one! if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } // Define the number of results per page $max_results = 40; // Figure out the limit for the query based // on the current page number. $from = (($page * $max_results) - $max_results); echo '<div id="product">'; $result = mysql_query("SELECT DISTINCT product.id, product.* FROM prods_to_cats INNER JOIN product ON prods_to_cats.id=product.id WHERE prods_to_cats.category_id=$showcategory ORDER BY product.title ASC LIMIT $from, $max_results", $dbh); $numresult = mysql_num_rows($result); if($numresult==0) { echo "<p style='padding-left: 50px'>There are no products listed in this category.</p>\n"; } else { $thiscategory = mysql_query("SELECT * FROM category WHERE category_id=$showcategory", $dbh); $thisrow = mysql_fetch_array($thiscategory); $this_des=$thisrow["category_description"]; echo "<table width='100%'><tr>"; echo "<div style='position:relative; left:150px;'><font size='2'>Return To: <strong><a href='http://www.autismcommunitystore.com'>Home </a></strong></font></div><br/>"; echo "<div style='position:relative ; width:100%' align='center'>"; echo "<br />"; echo "<img src='http://www.watchesandthings.com/autism/images/suppliesHeader.gif'>"; echo "</div>"; echo "<h2>"; echo "<div style='padding-right:20px ; position:relative ; width;100%; text-align:right;'>"; echo "<div style='position:relative ; width;80%; text-align:center; left:20%;'>"; echo $this_des; echo "</div>"; echo "</div>"; echo "</h2>"; echo "<div style='position:relative ; padding-left:30px ; padding-right:30px ; '>"; echo "<p>"; echo "$this_text </p>"; echo "</div>"; echo "</tr>"; $count = 1; $column = 1; //initialize column 1 or 2 //-----------------------code for drop down menu---------------------------------------- include 'browserChecker.php'; /* echo $browser; echo "<br/>"; echo $browser_version; echo "<br/>"; $main_version=$browser_version[0]; echo $main_version; */ if ($browser=='IE' && $browser_version<7){ echo '<br />'; //make version 6 compatible select box if ($category==1 || $category==24){ }else{ ?> <center> <div id="hiddendiv" style="display:;"> <form method="get" enctype="multipart/form-data" action="http://www.autismcommunitystore.com/viewsubcategory.php"> <select id="myselectbox" name="subcategory" > <? $sql="SELECT * FROM subcategory ORDER BY sub_description ASC"; $result=mysql_query($sql, $dbh); while($myrow=mysql_fetch_array($result)) { if ($myrow['category_id']==$category){ $myrow['sub_description'] ?> <option name="subcategory" value="<? echo $myrow['sub_id'] ?>" ><? echo $myrow['sub_description'] ?> </option> <? }//close if for category check }//close drop down while loop ?> </select> </center> <div id="go_subcat"> <input type="submit" value=" GO " style="background-color: #E4DFF3; color: #6F5079; border: 2px solid #6F5079"> </div> </form> </div> <? }//end check category }else{ //make normal select box if ($category==1 || $category==24){ }else{ ?><div style="z-index:2"><br /><form method="get" enctype="multipart/form-data" action="http://www.autismcommunitystore.com/viewsubcategory.php"> <div align="center" style='z-index:5'> <select name="subcategory" size="1" style="background-color: #ffffff; color: #6F5079; border: 2px solid #6F5079"> <? $sql="SELECT * FROM subcategory ORDER BY sub_description ASC"; $result=mysql_query($sql, $dbh); while($myrow=mysql_fetch_array($result)) { if ($myrow['category_id']==$category){ ?> <option name="subcategory" value="<? echo $myrow['sub_id'] ?>" ><? echo $myrow['sub_description'] ?> </option> <? }//close if for category check }//close drop down while loop ?> </select> <input type="submit" value=" GO " style="background-color: #E4DFF3; color: #6F5079; border: 2px solid #6F5079"> </div> </form> </div> <? } }//end browser checker if //-----------------------end code for drop down menu---------------------------------------- //reste variables $result = mysql_query("SELECT DISTINCT product.id, product.* FROM prods_to_cats INNER JOIN product ON prods_to_cats.id=product.id WHERE prods_to_cats.category_id=$showcategory ORDER BY product.title ASC LIMIT $from, $max_results", $dbh); echo "<TABLE cellspacing='20'>"; while($myrow = mysql_fetch_array($result)) { extract($myrow); $location=$image; $price=$sale_price; $item=$myrow["id"]; $stockstatus=$stat; if($stat=='IN STOCK') { $stockstatus=""; } else { $stockstatus="--Item Coming Soon--"; } if($price>0) { $printout="<table border=0 height=70 width=250><tr><td width='100px' align='center' ><a href=http://www.autismcommunitystore.com/item/$item/><img src=http://www.watchesandthings.com/autism/files/thumbnails/$location border=0 alt=$product_id></a></td><td><a href=http://www.autismcommunitystore.com/item/$item/>$title</a><br><span class=prod-dollar>$$price</span><br>$stockstatus</td></tr></table>"; } else { $printout="<table border=0 height=70 width=250><tr><td width='100px' align='center' ><a href=http://www.autismcommunitystore.com/item/$item/><img src=http://www.watchesandthings.com/autism/files/thumbnails/$location border=0 alt=$product_id></a></td><td><a href=http://www.autismcommunitystore.com/item/$item/>$title<br /><span class=prod-dollar>Click for Pricing</span></a><br>$stockstatus</td></tr></table>"; } if ($column=="1") { echo "<tr><td>$printout</td>"; // first column } else { echo "<td>$printout</td></tr>"; // 2nd column } // end of columns $count += 1; // this is a modulus operator it gets the remainder of the equation $column = $count % 2; } // end of while loop echo "</table>"; ; // Figure out the total number of results in DB: $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM prods_to_cats WHERE category_id=$showcategory"),0); //$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM product"),0); // Figure out the total number of pages. Always round up using ceil() $total_pages = ceil($total_results / $max_results); echo "<p><center>Pages<br />"; // Build Previous Link if($page > 1){ $prev = ($page - 1); echo "<a href='http://www.watchesandthings.com/autism/view.php?category=$showcategory&page=$prev'><<Previous</a> "; } for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; } else { echo "<a href='http://www.watchesandthings.com/autism/view.php?category=$showcategory&page=$i'>$i</a> "; } } // Build Next Link if($page < $total_pages){ $next = ($page + 1); echo "<a href='http://www.watchesandthings.com/autism/view.php?category=$showcategory&page=$next'>Next>></a>"; } echo "</center>"; }//end of else> echo "</table>"; echo "</div>"; ?> This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=330084.0 Hi everyone, I am a beginner web designer and a novice php user. I am a regular forum user and understand that you should always do a search and try to find the answer yourself but I have done that and didn't get any results (or I didn't understand them!). So I ask for some assistance - either you can tell me the code or link me to the correct answer. I am working on a website that I have built a enquiry form for and it has a php script for it. I have managed to get the form running properly and got the reCaptcha working correctly (with a custom error page) but I do not understand how to add custom error pages for incomplete email addresses, empty email addresses, or for a blank form? I tried using the same tactic I used for the reCaptcha error page but it didn't work - probably because I was guessing and just tried it in a bunch of different places. The error msg that displays now is just a plain white page with the msg - Email address is invalid appearing at the top left. While this is suitably functional it doesn't really look like much so I want to build a custom page for each error that could happen. So the code is below - if anyone can point a beginner in the right direction I would be super happy. :mrgreen: if you need anymore code or other details just tell me and I will post them up. The url of the form page is http://www.sunsolutionshomeimprovement.com/onlinesales.html This is the code I think you will need - I got it from a demo php script that I have modified. As I said I don't have much clue what I'm doing so I just posted it exactly how it looks - if I over did it I apologize... :oops: 68.// Validate email field. 69. 70.if(isset($_REQUEST['email']) && !empty($_REQUEST['email'])) 71.{ 72. 73.if(preg_match("/(%0A|%0D|\n+|\r+|:)/i",$_REQUEST['email'])){$errors[] = "Email address may not contain a new line or 74.a colon";} 75. 76.$_REQUEST['email'] = trim($_REQUEST['email']); 77. 78.if(substr_count($_REQUEST['email'],"@") != 1 || stristr($_REQUEST['email']," ")){$errors[] = "Email address is invalid";}else{$exploded_email = explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address is invalid";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}} 78. 79.) 80. 81.// Check referrer is from same site. 82. 83.if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form";} 84. 85.// Check for a blank form. 86. 87.function recursive_array_check_blank($element_value) 88.( 89. 90.global $set; 91. 92.if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}} 93.else 94. 95. 96.foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);} 97. 98.) 99. 100.) 101. 102.recursive_array_check_blank($_REQUEST); 103. 104.if(!$set){$errors[] = "You cannot send a blank form";} 105. 106.unset($set); 107. 108.// Display any errors and exit if errors exist. 109. 110.if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;} 111. 112.if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");} 113. 114.// Build message. I don't think there is anymore that is relevant? I just want to reiterate that I know nearly nothing about this stuff so if you could keep your answers simple it would help a lot - cheers! This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=317600.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=306905.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=358003.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=315503.0 |