Jump to content

mcloan

Members
  • Posts

    48
  • Joined

  • Last visited

    Never

Everything posted by mcloan

  1. I am trying to learn curl for web scraping and I am trying to understand this example (http://www.devnewz.com/devnewz-3-20041221UsingPHPCURLLibrarytoScrapetheInternet.html).  It is very close to what I am trying to do.  I was wondering if someone would be willing to explain in english what each line is doing.  I pretty much undertand the first section, but I am not getting the second part that starts with $rows=explode("n",$grabber->searchtxt); eventhough I have read the article several times. If someone could explain the below section in basic english line by line I would much appreciate. $rows=explode("n",$grabber->searchtxt); foreach($rows as $row) { if(!$row) continue; if(!strstr($row,'href')) continue; if(strstr($row,">b<")) continue; //get name $name=cut("">","",$row); $name=str_replace("n","",$name); $href=cut("href="","">",$row); $href=trim($href); $name=htmlentities($name); $href=strip_tags($href); $name=trim($name); if(!empty($name)&&!empty($href)) { array_push($dirs,array('name'=>$name,'href'=>$href)); } } Thank you.
  2. I am interested in understanding which php functions and general logic I could use to handle the following steps with a php program. 1. Open a web page with php 2. Find a form field on the page input a value and submit it 3. On the returned page find a section of html in the results such as <td class="txtPopUp" valign="top" align="left"> and read the text value from the page that is right after it. 4. Step down to the next line and read the text value on the page Anyone’s help is much appreciated. Thank you.
  3. [quote author=wildteen88 link=topic=113471.msg461213#msg461213 date=1162402002] So when you go to create your links you'll need to use the newer seo URL. Like so: [code]<a href="myscript/5689">See product 5689</a>[/code] [/quote] So if I understand correctly you really need to plan out how your mod rewrite urls will appear before you start coding to ensure your code is in the right format.  Is this correct? Secondly is mod rewrite the only way to present clean seo friendly URLs? Thank you.
  4. [quote author=thorpe link=topic=113475.msg461148#msg461148 date=1162394898] One fetches a row as an array, the other as an object. [/quote] Sorry, I am in the process of learning, can you provide an example of what the difference is between a row and object? Thank you.
  5. Can someone tell me in simple terms what is the difference between fetch_row() and fetch_object()? Thank you.
  6. I am learning php and I am trying to visualize how mod rewrite would affect a script if I am looking to have a site will totally friendly SEO urls.  Let say I have this url myscript.php?catid=2343. If in places of my php script I uses $GET_['catid'], but then use mod rewrite via .htaccess later to rewite the urls will the $Get still work?  Secondly if I use mod rewrite I realize the link in the browser address bar will be rewritten, but how do the links appear as I hoover over the a link what will be shown in the browser task bar at the bottom of the browser?  The rewritten link or the link such as myscript.php?catid=2343.  Lastly, is modrewrite the best way to build seo friendly Urls with php? Thank you.
  7. [quote author=roopurt18 link=topic=113051.msg460147#msg460147 date=1162237390] I'd like to shove some more knowledge into your head if that's alright! Just think of an array as a collection.  Every array is just collected data, nothing more and nothing less.  Usually we collect data in an array because it makes our lives as programmers easier! For instance, would you rather create 100 variables named $book1, $book2, ..., $book100 or just a single array named $books and refer to them by $books[0], $books[1], ..., $books[99]?  What happens if you make a new variable for every book and have to perform the same operation on all of them?  You have to write that code 100 times!  If you use an array, you can loop over every element with for($i = 0; $i < 100; $i++){} or a foreach($books as $book){}!  That's a lot easier! What if you have an application that processes employee data?  Would you rather call 10 different functions to get the data for an employee like this: [code]<?php $name = GetEmployeeName(); $add = GetEmployeeAddress(); $phone = GetEmployeePhone(); ?>[/code] Or would you rather call one function like this: [code]<?php $Employee = GetEmployee(); echo $Employee['Name']; echo $Employee['Phone']; ?>[/code] Whoah wait a minute there!  You just used text in the array!  That's right.  Up until now you've been using arrays and accessing them with integers.  Those values you use to access elements inside the array are what we call keys and they can be anything you want really.  Most of the time integers or strings will do fine though. How about this array? [code]<?php $ShoppingCart = Array(); $ShoppingCart['Milk'] = Array( 'Brand' => 'Jed\'s Milk', 'Qty' => 2 ); $ShoppingCart['Cheese'] = Array( 'Brand' => 'Tillamook Pepper Jack', 'Qty' => 1 ); ?>[/code] From that array I know that my shopping cart consists of milk and cheese but not only that, I can see which brands and how much of each I have.  Just in case you didn't notice, $ShoppingCart is an array of arrays! Good times! [/quote] Roopurt18, Thank you very much for the good overview.  It is very helpful for me getting the basic concept.  I appreciate you taking the time to be so detailed. Thank you again!!!   
  8. Chris Thanks a lot, I am glad I am on the right track!!
  9. I am in the process of learning php and sql.  I am trying to conceptualize how a basic design may work. Here is an example my questions are below the example.  Assume I have an online store selling books, which I wanted to have the flow of the site go from main broad level to a sub category which then flows into a product page.  For example I may have a main category as computer books, which flows into a sub category page of internet, networking, mainframe etc.  Each sub category page will show a listing of the books in the sub category.  Then when you select a book it will take you to a product page. This is what I am thinking as far as design from a database standpoint (3 tables). [b]1.  Category table[/b]   a. Category id (key field)   b. Category Name   c. Category description (for meta description of the page)   d. Category Title (for meta Title of the page) [b]2.  Sub Category Table[/b]   a. Sub Category Id (key field)   b. Category id (key field)   c. Sub Category Name   d. Sub Category Description (for meta description of the page)   e. Sub Category Title (for meta Title of the page) [b]3.  Product Table[/b]   a. Product Id (key field)   b. Sub Category Id (key field)   c. Category id (key field)   d. Product Description (for meta description of the page)   e. Product Long Description (for meta description of the page)   f. Product Title (for meta Title of the page)   g. Product Features Here are my questions: 1.  Would you expect this be an efficient database design?  If not what is a better way? 2.  What having meta description data and page titles in a database the best way to handle these items? 3.  What is the best way to build site navigation based on this design?  Just pull from category tables and loop through an array?  Also can DHTML menus be used if I pull my navigation from a database? Your assistance with helping me understand these concepts would be much appreciated. Thank you.
  10. [quote author=mjdamato link=topic=113051.msg459667#msg459667 date=1162152969] actually, $count starts at 0 and then inreases by 1 every iterations through the loop. Let's go through that bit of code line by line: [code]1) $url_array  = array() 2) for ($count = 0; $row = $results->Fetch_row(); ++count) 3) { 4)    $url_array[$count] = $row[0] 5) }[/code] Line 1 simply creates an array variable called "$url_array". However it has no items in the array. Line 2 creates a loop that 1. sets the value of $count to 0 and sets the exist condtiion for when "$row = $results->Fetch_row();" returns false (i.e. when there are no more records). The 3rd expression is what happens on each successive iteration of the loop - does not happen the first time through. So, the first iteration through the loop $count = 0, 2nd time $count = 1, etc. Line 4 sets the value of $url_array[$count] to the value of the first item in the $row array. In other words, when the loop is complete: $url_array[0] = the item from the 1st $row $url_array[1] = the item from the 2nd $row $url_array[2] = the item from the 3rd $row . . . [/quote] Wow thank you very much. :)  This was very helpful in helping me with the concept of what is going on in this loop.  I really appreciate you spending the extra time to get me up to speed. I know that was a lot of code I pasted.  I can not say I am an expert on visualizing the many uses of arrays, but this has definitely help me a ton with one application.  For some reason arrays are a bit confusing to me as a whole.  Hopefully I will start seeing all the uses soon so that as I just think about something and pragmatically see it visually.  At least I feel I can move on in my book now that I have this concept understanding. Thank you again!!!!
  11. [quote] It exits the loop because the 2nd expression "$i < 5" becomes false. That expression doesn't need to use anything from expression 1 or expression 3. So, in the example yougave the loop will iterate until there are no more rows to fetch (i.e. returns false). It is using the $count to count the number of records there are. [/quote] Thank you.  It helps a lot.  I am starting to get it now.  I totally see how the for loop is ending.  However I am still a little confused on one line in the for loop.     $url_array[$count] = $row[0]; What exactly is the [$count] for?  I understand the $row[0] is the first field of the query results and the value of this is getting added to $url_array.  But $count starts out at 1 in the for loop so why is it being used here? Thank you again.
  12. Can someone tell me what the difference is between $HTTP_POST_VARS and $Post? Thank you.
  13. [quote author=wildteen88 link=topic=113051.msg459185#msg459185 date=1162059929] $row[0] is created from the for loops second parameter (highlighted below): for ($count = 0; [b]$row = $results->Fetch_row();[/b] ++count) Looks like $results is a class which calls a method (function) called Fetch_row. Fetch_row returns an array of results from the query that was previously executed. $row[0] will be the first field from the table that was queried. I cant really explain it as I don't know what's going on. But I'd say that's the basics though. [/quote] I got it on the $rows, but there are a couple things else I do not completely understand.  I am learning through a book and I would like to get the concept down before I move on.  The overall script below is basically adding a new bookmark to a web based bookmarking system.  It then gets the urls for a user for sql database and displays them.  Below is the entire code.  I am having difficulty understanding some of the section I noted above.  This is my issue.  Essentially my understanding is the fetch_row() is returning an array of numbers from the query.  So $row would look something like an array such as (1,2,3,4) etc...  So my first problem is understanding exactly how this for loop is executing.  Normally it would have an end value such as for ($count=0; $count=5; ++count) , but in the code I presented it uses for ($count = 1; $row = $result->fetch_row(); ++$count) and I believe this is an array so I do not exactly understand the $result->fetch_row() criteria for ending the for loop. How does it know when to stop and what number to stop at? Next I do not understand the $url_array.  My understanding is that it would essentially be a value such as (0,1,2,3) if I understand correctly.  However this $url_array is returned to the orginal script and then passed to function display_user_urls($url_array);. The function display_user_urls appears to be using $url_array to make the actual booked marked urls be displayed on the screen.  However, how can it do this if the values were never placed into $url_array.  As I stated before I would think the value of $url_array is (1,2,3,4) etc.. from how it was set in the get_users_urls function. Your assistance with helping me understand this concept is very much appreciated.  Thank you. [code] ////  Main Code For .php page <?php session_start();   //create short variable name   $new_url = $_POST['new_url'];   do_html_header('Adding bookmarks');     try   {     check_valid_user();     if (!filled_out($_POST))     {       throw new Exception('Form not completely filled out.');        }     // check URL format     if (strstr($new_url, 'http://')===false)        $new_url = 'http://'.$new_url;     // check URL is valid     if (!(@fopen($new_url, 'r')))       throw new Exception('Not a valid URL.');     // try to add bm     add_bm($new_url);     echo 'Bookmark added.';     // get the bookmarks this user has saved     if ($url_array = get_user_urls($_SESSION['valid_user']))       display_user_urls($url_array);   }   catch (Exception $e)   {     echo $e->getMessage();   }   display_user_menu();   do_html_footer(); ?> --------------  function begin here------------------ function add_bm($new_url) {   // Add new bookmark to the database   echo "Attempting to add ".htmlspecialchars($new_url).'<br />';   $valid_user = $_SESSION['valid_user'];     $conn = db_connect();   // check not a repeat bookmark   $result = $conn->query("select * from bookmark                          where username='$valid_user'                          and bm_URL='$new_url'");   if ($result && ($result->num_rows>0))     throw new Exception('Bookmark already exists.');   // insert the new bookmark   if (!$conn->query( "insert into bookmark values                           ('$valid_user', '$new_url')"))     throw new Exception('Bookmark could not be inserted.');   return true; } function get_user_urls($username) {   //extract from the database all the URLs this user has stored   $conn = db_connect();   $result = $conn->query( "select bm_URL                           from bookmark                           where username = '$username'");   if (!$result)     return false;   //create an array of the URLs   $url_array = array();   for ($count = 1; $row = $result->fetch_row(); ++$count)   {     $url_array[$count] = $row[0];   }    return $url_array; } function display_user_urls($url_array) {   // display the table of URLs   // set global variable, so we can test later if this is on the page   global $bm_table;   $bm_table = true; ?>   <br />   <form name='bm_table' action='delete_bms.php' method='post'>   <table width=300 cellpadding=2 cellspacing=0>   <?php   $color = "#cccccc";   echo "<tr bgcolor='$color'><td><strong>Bookmark</strong></td>";   echo "<td><strong>Delete?</strong></td></tr>";   if (is_array($url_array) && count($url_array)>0)   {     foreach ($url_array as $url)     {       if ($color == "#cccccc")         $color = "#ffffff";       else         $color = "#cccccc";       // remember to call htmlspecialchars() when we are displaying user data       echo "<tr bgcolor='$color'><td><a href=\"$url\">".htmlspecialchars($url)."</a></td>";       echo "<td><input type='checkbox' name=\"del_me[]\"              value=\"$url\"></td>";       echo "</tr>";     }   }   else     echo "<tr><td>No bookmarks on record</td></tr>"; ?>   </table>   </form> <?php } [/code]
  14. Can some one help me understand this script?  The fetch row was from sql results $results variable.  I think I understand pretty much what this is doing I am just mainly confused on the $row[0].  What does this mean?  $url_array  = array() for ($count = 0; $row = $results->Fetch_row(); ++count) {     $url_array[$count] = $row[0] } Thank you.
  15. The book is php and msql web development by luke wellington and laura thomson.  It is a darn good book so far.
  16. Thank you so much very helpful!
  17. obsidian - Perfect, your example is exactly what I needed to understand.  I really appreciate the thorough example.  Now I finally have the concept down. This will help me so much as I move forward in my book. Thank you again!!!!
  18. I am in the process of learning php and I am trying to get some concepts.  Below is some code for a logout script in the book I am reading.  I understand it all but one section.  I do not understand the line  if ($result_dest).  Can someone explain what is this check for?  The variable $result_dest was set to session_destroy(); so I would think it would have no value.  Also I am a little confused by an if statment without a condition.  For istance this is If ($result_dest), but normally I see ifs with a condition like if (!empty($result_dest)) or something like that.  Can some also explain what if statement without a condition is doing?  [code] <?php // include function files for this application require_once('bookmark_fns.php'); session_start(); $old_user = $_SESSION['valid_user'];  // store  to test if they *were* logged in unset($_SESSION['valid_user']); $result_dest = session_destroy(); // start output html do_html_header('Logging Out'); if (!empty($old_user)) {   if ($result_dest)   {     // if they were logged in and are now logged out     echo 'Logged out.<br />';     do_html_url('login.php', 'Login');   }   else   {   // they were logged in and could not be logged out     echo 'Could not log you out.<br />';   } } else {   // if they weren't logged in but came to this page somehow   echo 'You were not logged in, and so have not been logged out.<br />';   do_html_url('login.php', 'Login'); } do_html_footer(); ?> [/code]
  19. [quote author=obsidian link=topic=112256.msg455582#msg455582 date=1161463474] in addition, it allows you to [b]pull[/b] the key out of an array when looping in a foreach. it has other more obscure functions as well, but i'll let someone a little more familiar with it cover those. [code] <?php foreach ($myArray as $key => $val) {   echo "$key = $val<br />\n"; } ?> [/code] [/quote] Thank you actually this use is what invoked my question, but I am still a little confused on this application of it.  For instance.  You may invoke the above code by setting it up as a function and passing $myArray as a variable which will probably be $_Post. So if the above was function was named fillout, it would do something like the below: fillout($_Post) function fillout($myArray) { foreach ($myArray as $key => $val) {   if (!isset($key) || ($val== ' '))       return false; }       return true; } What I do not understand is how the value ($val) is getting set?  The key will be the form name but what about the value?  I think it may be in $_Post but I do not have a clear understanding of exactly what $_Post does.  It is setting up an associtive array with $key as field name => value of field name for each field on a form? Your help is much appreciated. Thank you.
  20. Very helpful. Thank you so much!
  21. I am in the process of learning php.  In the book I am reading it has an array as $prices = array('tires=>'100', 'oil'=>10); Can someone tell me what the => means?  Is this different than just = Thank you.
  22. Thank you both very much for the reply.  Very helpful information. invincible_virus my table structure would be something such as the following assuming I have categories that follow into products. Table Categories: Category_id  Key Field Auto Increment Product_id Category Description Tables Products: Product_id Key Field Auto Increment Category_id Product Description If I am understanding correctly I would have to have a mod rewrite rule for each category and each product page.  So a product page may look like this: http://www.mysite.com/seestore.php?cat_id=1&prodID=53 RewriteRule ^seestore/hats/angels-baseball-hat$ seestore.php?cat_id=1&prodID=53 Is this correct? Also, if I have a section of the site where users add a profile is there a more dynamic way to rewrite the url since I will not have a id upfront? For instance think of a forum.  Each post has a post id and post title.  Essentially, I would want to rewrite a post id with the title of the post such as below: No Mod rewrite:  http://www.mysite.com/post.php?category_id=1&postID=35 After Mod Rewrite:  http://www.mysite.com/baseball/how-to-hit-a-baseball/ The “how to hit a baseball” is the post topic.  DO you have any suggestions for this? Thank you very much for your help.
  23. I am in the process of learning php and dynamic web site building.  I am trying to conceptualize how to use mod rewrite to have clean urls with keywords. The book I am reading structures most all database with a primary key auto increment.  Suppose I have product an online store with product categories.  Then the url for the page becomes something like: <a href=\"seestore.php?cat_id=cat_id \">$cat_title</a> In browser this becomes http://mysite.com/seestore.php?cat_id=1 (or 2,3,4 etc..) My understanding is that I can use mod rewrite to make the url like this: RewriteRule ^seestore/([0-9][0-9])/$ seestore.php?cat_id=$1 Output:  http://mysite.com/seestore/1 My questions lies in how do I get the number out of the url?  For seo I would much rather have the category name be presented in the url. For instance.  http://mysite.com/seestore/hats/. I am assuming that an easy way to do this would be to structure my database with the actual category names as the category id, but is this the best and only way to accomplish this? You assistance with helping me understand this concept is much appreciated. Thank you,
×
×
  • 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.