Jump to content
Larry Ullman's Book Forums

banacan

Members
  • Posts

    48
  • Joined

  • Last visited

Everything posted by banacan

  1. Hi Larry, Thanks for replying. For some reason I did not get notified about your response which is why I'm just now seeing your post. I was hoping the Matthaus might chime in since he helped me once before with linux command line. Does anyone know how to reach him?
  2. I have my db backed up and emailed to me (the size of my db is small so email is not problem) using the following mysqldump command in a cron running weekly and it is working perfectly. mysqldump -e --user=username --password=password database | gzip | uuencode database_name.gz | mail me@domain.com All I want to do is add the current date of the backup to the gzip filename so each backup filename is unique. I have searched for the answer and found this suggestion: mysqldump -e --user=username --password=password database | gzip | uuencode $(date +%Y-%m-%d)-database_name.gz | mail me@domain.com But I get this error: unexpected EOF while looking for matching `)' I tried a different suggestion too: mysqldump -e --user=username --password=password database | gzip | uuencode `date +'%Y%m%d'`-database.gz | mail -s "`date +'%Y%m%d'`-database.gz mysqldump backup" me@domain.com But this also results in an error: unexpected EOF while looking for matching ``' I can't figure out why these solutions are causing errors nor how to fix it. Any suggested solutions would be welcome.
  3. Resolved I recreated both the connection script and DB query and now it is working fine on both the dev server and live server. I must confess, I don't see the difference between the original version and the new version, but who cares as long as it works.
  4. Sorry for the BUMP, but can anyone offer a suggestion as to why this works on my dev. server but not my live server? I have looked at the email output of my_error_handler, and I see the two different connection variables each of which has been assigned a Resource id. I also see the username and password for each connection which are both correct. The error I'm receiving is: mysql_num_rows(): supplied argument is not a valid MySQL result resource and the error is pointing to line 33 which is this: $totalrecords = mysql_num_rows($result); which indicates that the query is not producing anything, which is borne out by the error message content: [query] => SELECT user_id FROM ext_users [result] => the result is empty. To sum up, this works perfectly on my development server, but not on my production server. The error report shows both connections being made, each having a correct username and password. A separate Resource id has been assigned to each connection, but the first DB interaction with ext_users, the Select query, fails. What could this be? Is there a server setting that might be affecting this? Any helpful suggestions would be most welcome.
  5. I'm using the scripts in chapter 16 to register users on a site. Because I was concerned about granting privileges to Select, Insert, and Update on the entire DB, I created a separate DB just for "external users". Everything works just great, except now I want to access this external user DB in the Admin site which uses a different DB (the general site content DB). I tried adding two connection scripts in my admin.php file, and while it works fine on my MAMP Pro server, I'm getting errors on my production server. My connection scripts setup different connection variables, so there should be no conflict there, and I use those connection variables only in the include files accessing the respective DB's. Here are some samples of my connections: This first connection script is for the general site content DB if (stristr($_SERVER['HTTP_HOST'], DOMAIN) || (substr($_SERVER['HTTP_HOST'], 0, 7) == '192.168')) { $local = TRUE; } else { $local = FALSE; } if ($local) { $hostname_siteadmin = "localhost"; $database_siteadmin = "localgeneralsiteDB"; $username_siteadmin = "root"; $password_siteadmin = "localPWD"; $siteadmin = mysql_pconnect($hostname_siteadmin, $username_siteadmin, $password_siteadmin) or trigger_error(mysql_error(),E_USER_ERROR); } else { $hostname_siteadmin = "localhost"; $database_siteadmin = "productionsiteDB"; $username_siteadmin = "productionsiteUSER"; $password_siteadmin = "productionsitePWD"; $siteadmin = mysql_pconnect($hostname_siteadmin, $username_siteadmin, $password_siteadmin) or trigger_error(mysql_error(),E_USER_ERROR); } ?> This next one is for the external user DB if (stristr($_SERVER['HTTP_HOST'], DOMAIN) || (substr($_SERVER['HTTP_HOST'], 0, 7) == '192.168')) { $local = TRUE; } else { $local = FALSE; } if ($local) { $hostname_vusradmin = "localhost"; $database_vusradmin = "localextuserDB"; $username_vusradmin = "root"; $password_vusradmin = "localPWD"; $vusradmin = mysql_pconnect($hostname_vusradmin, $username_vusradmin, $password_vusradmin) or trigger_error(mysql_error(),E_USER_ERROR); } else { $hostname_vusradmin = "localhost"; $database_vusradmin = "productionsiteDB"; $username_vusradmin = "productionsiteUSER"; $password_vusradmin = "productionsitePWD"; $vusradmin = mysql_pconnect($hostname_vusradmin, $username_vusradmin, $password_vusradmin) or trigger_error(mysql_error(),E_USER_ERROR); } ?> Then in my admin.php file I call require_once() for each connection script. As I said, on my testing server this works with no problems, but on the production server only the connection script which is loaded last works. This would seem to indicate a variable conflict, but again, the variables are different for each connection script. mysql_select_db($database_vusradmin, $vusradmin); $query = "SELECT user_id FROM ext_users"; $result = mysql_query($query); mysql_select_db($database_siteadmin, $siteadmin); $query = "SELECT user_id FROM users WHERE hidden = 'n'"; $result = mysql_query($query); Now if someone can tell me what I'm doing wrong - why it works on my dev. server but not the production server - I would be most grateful. Otherwise... I searched the forum for threads related to accessing two databases at a time, and the replies were pretty consistent - use one database if possible. Larry suggests creating different users with different privileges - I have. The public side user for general site content has only Select privileges, admin side user for general site content has Select, Insert, Update and Delete privileges. But the privileges required for registering an external user are Select, Insert, and Update, isn't it risky giving such broad privileges to unknown visitors? So then my question is the same as the topic title, how can I limit the public side user (soon to be registered user) privileges to one table only? If I can do that, I will bring the ext_users table into the general DB and then one connection script will work. I sure would appreciate comments.
  6. Thanks. I only needed one solution and this was the first one that worked.
  7. Thanks HartleySan, that makes it clearer to me. So basically this creates an array of just the information I need for each row of the DB table. Couldn't $item have been constructed with $row['div_name'] and $row['grp_name'] at the same time the rest of the array was created? In other words: $item = array('div_name'=>$row['div_name'],'grp_name'=>$row['grp_name'],'title'=>$row['title'],'descr'=>$row['descr'],'price'=>$row['price'],'price2'=>$row['price2'],'price3'=>$row['price3']); Or is there something different about the line in question?
  8. My issue is solved, though I sure hope someone can explain it to me. Someone on another forum gave me the solution, but I couldn't get him to explain it. Here's the code: $listMenu = mysql_query($query_listMenu, $siteuser); while ( $row = mysql_fetch_array($listMenu, MYSQL_ASSOC) ) { $item = array('title'=>$row['title'],'descr'=>$row['descr'],'price'=>$row['price'],'price2'=>$row['price2'],'price3'=>$row['price3']); $menuRows[$row['div_name']][$row['grp_name']][] = $item; } ?> <div id="menu_list"> <?php foreach($menuRows as $divname=>$grp){ // echo out what you want... contains Beverages, Salads echo "<h3>" . $divname . "</h3>"; foreach($grp as $grpName=>$itemArr){ // again, echo out the divs echo '<table>'; ?> <tr><thead><th class="title"><?php if ($grpName !== $divname) { echo $grpName; } ?></th><th> </th><th> </th><th> </th></thead></tr><?php foreach($itemArr as $item) { // and now you can echo out your items ?> <tr> <td><strong><?php echo $item['title']; ?></strong><br /><?php echo $item['descr']; ?></td><td class="price"><?php echo $item['price']; ?></td><td class="price"><?php echo $item['price2']; ?></td><td class="price"><?php echo $item['price3']; ?></td></tr><?php } echo "</table>"; } } ?> </div> I get everything but this line: $menuRows[$row['div_name']][$row['grp_name']][] = $item; Can someone please explain what this does? I really want to understand this. Thanks.
  9. Hi Antonio, Thanks for replying. The Menu table is quite simple: Column Type Null Default menu_id int(10) No div_id int(10) No grp_id int(10) Yes NULL cat_id int(10) Yes NULL date_b date No date_e date No price float(6,2) Yes NULL price2 float(6,2) Yes NULL price3 float(6,2) Yes NULL title varchar(255) No descr text Yes NULL special enum('n', 'y') No n ordr int(4) No 10 My query: $query_listMenu = sprintf("SELECT menu.menu_id, menu.div_id, m_div.div_name, menu.grp_id, m_grp.grp_name, menu.cat_id, m_cat.cat_name, m_cat.cat_ord, menu.title, menu.descr, menu.price, menu.price2, menu.price3, menu.date_b, menu.date_e FROM menu LEFT JOIN m_div ON ( menu.div_id = m_div.div_id ) LEFT JOIN m_grp ON ( menu.grp_id = m_grp.grp_id ) LEFT JOIN m_cat ON ( menu.cat_id = m_cat.cat_id ) WHERE menu.date_e >= NOW() ORDER BY m_div.div_name, ordr, m_grp.grp_name, menu.title"); Here is my code: foreach ($menuRows as $section => $type) { echo "<h3>" . $type['div_name'] . "</h3>"; echo "<table>"; echo "<tr><th>" . $type['grp_name'] . "</th><th> </th><th> </th><th> </th></tr>"; foreach ($menuRows as $menu => $item) { if ($item['div_name'] == $type['div_name']) { echo "<tr><td><strong>" . $item['title'] . "</strong>" . $item['descr'] . "</td><td>" . $item['price'] . "</td><td>" . $item['price2'] . "</td><td>" . $item['price3'] . "</td></tr>"; } } echo '</table>'; } Here is some table data: Appetizer : Appetizer : Homemade Bread Sticks : 3.95 Appetizer : Appetizer : Sicilian Meatballs : 4.25 Appetizer : Appetizer : Wings : 7.50 Beverages : Beer - bottle : Yuengling Black & Tan : 2.75 Beverages : Beer - bottle : Yuengling Light : 2.75 Beverages : Beer - draft : Budweiser Light : 3.65 Beverages : Beer - draft : Killians : 3.75 Beverages : Wine - Red : Diseno, Balbec, Argentina : Beverages : Wine - Red : Riunite, Lambrusco, Italy : 4.00 Beverages : Wine - White : Beringer, Moscato, Califormia : 4.00 Beverages : Wine - White : Canyon Road, Chardonnay, California : 4.25 Dinner : Entre : Pasta with Marinara Sauce : 9.75 Dinner : Entre : Pasta with Meatballs : 10.95 Lunch : Entre : Calzone : 6.25 Lunch : Entre : Lasagna : 6.25 Salad : Salad : Side Salad : 3.50 Salad : Salad : Extra dressing for salad : 0.25 Sandwich : Sandwich : Breaded Chicken Parmesan Sub : 6.75 Sandwich : Sandwich : Meatball Sub : 6.25 The above code does produce results close to what I want. Here is a sample of the output: (sorry, I can't get the table output to display properly here) Appetizer Appetizer Bruschetta Toasted sliced ciabatta, marinated diced tomatoes and seasonings 4.95 Ciabatta Loaf Individual Loaves Covered with Garlic Butter, Tomatoes & Provolone Cheese 4.50 Garlic Bread with Cheese Served with a side of Marinara sauce 2.95 Garlic Bread with Marinara Sauce 1.75 Homemade Bread Sticks Served with Cheese and Tomato Sauce or Herb Flavored Olive Oil Dip 3.95 Sicilian Meatballs Meatballs with sauce and 3 bread sticks 4.25 Wings (1 dozen) B-B-Q, Hot, or Ranch. Served with Bleu Cheese or Ranch dressing and Celery 7.50 Extra dressing for wings 0.25 The problem is that this output is repeated as many times as there are Appetizer items - 8 times. Every additional entry repeats equal to the number of items in that category. This clearly is the result of having the nested foreach functions, but I can't determine the right code. Any help would be much appreciated.
  10. I have a query that returns all items in the DB table, including price(s), description, title, and menu section (lunch, dinner, beverages, etc.), ordered by menu section, menu item, title. The query results are dumped into a multidimensional array and displayed on the page. Now I want to put each menu section in a separate accordian window, so how do I iterate through the array and separate out items by menu section? This is made more difficult because I don't know what menu sections might be added later. Is a recursive function what I need instead of an iterative?
  11. HartleySan, No, I did not take your reply as snippy or sarcastic. You and Antonio are way more advanced in your programming skills and understanding than I am, and I like to take advantage of that knowledge whenever possible. As Antonio said in one post, he may not have the solution, but he can help my thought process. By you mentioning the iterative vs recursive, it got me thinking, and that led me to a search, which resulted in finding a very helpful article, that ended in better understanding. All of this was very important and helpful, which is why I'm so grateful to you and Antonio and of course Larry. Best wishes.
  12. HartleySan, It seems we were both posting about the same time. Yes, after reading the article, I realized the significance. BTW, I wasn't being flip, I just wasn't clear on the subtleties. I now have a much better understanding. Thanks for your input.
  13. Thanks to both of you for your comments. I did a search for "iterative vs recursive" and found a wonderful explanation of the two, and when which is appropriate. Without going into too much depth - that is done beautifully in the article - the main take-away for me was at the end of the article when the author stated: So when I look at what I'm trying to do (I started two separate posts addressing different parts of the same problem), I need to use both recursive and iterative functions. I need the recursive to traverse the tree to whatever depth is there, keeping track of the hierarchical relationship, and I need the iterative to display the results in a paged way. Thanks again to you both for sharing your knowledge and for helping to illuminate some important concepts.
  14. HartleySan, Is this a distinction without a difference? Thanks for taking the time to reply.
  15. Thanks again for replying. No, you didn't recommend that article to me but someone else. I just happened to read the thread and I was intrigued. Well, silly me. Sometimes I make things more complicated than they really are. While driving to the store I realized what logic I needed to determine the last child: items that are not top-level items (pid != 1) and have no dependents. Too easy.
  16. Hi Antonio, You must have posted while I was writing my post with the solution. Once again, thanks for taking the time to reply.
  17. I solved my problem by using array_slice and setting the offset and records per page within the function. Here is what I did: // Set page display limit $bunch = array_slice($parent, $offset, $recsperpage, TRUE); // Loop through each subarray: foreach ($bunch as $pid=>$item) { [ echo items here ] This fix actually had I great side effect. What I discovered is that limiting the number of array elements per page using array_slice, limited the number of top-level items only. That means that each parent item contained all of its decendents, and paging results returned X parent items with all of their decendents "attached". Therefore I don't get a page break between sub-items, which would make relationships more difficult to understand. Unless and until my sub-items become too numerous, this will work great. It just means uneven page lengths for display, depending on how many decendents are attached. That's a small price to pay for the clarity and comfort this provides. The other thing I had to do was to change one SQL from counting the number of records to counting the number of top-level records, and using that number in my calculations for total pages and records per page. I must say Larry, I am getting alot of mileage out of your Script. Thanks again for including it in you book.
  18. Hi HartleySan, Yes, I read that article before when you mentioned it in a reply in another thread. It is very interesting. However since I am so close already, and since I already have the styling set in my CSS, I'm hoping someone can suggest a way of targeting the last child. Thanks for your reply.
  19. Hi Larry, I have run into another issue that I hope you can help with. I have a standard paging function that limits the number of records displayed per screen. When the paging function is used in conjunction with the recursive function, the top-level records (those with pid=1) display and page correctly. However, child records no longer display with their parent, and when the paging function reaches a page with children, it produces an error: "Undefined offset: 1". Is there a way to maintain paging while using the recursion function? Thanks.
  20. I am using a modification of Script 1.3 to display a list, but the list is being displayed in a table, not a nested ul. Because I want to indicate the hierarchical relationship, I need to add left padding to all child items. So what I've done is add an incrementing number ("T1", "T2", etc.) as a class for each <tr> that has children. That works great and I can increase the left padding based on the "T" number. The problem is that the last child doesn't get the "T" number because it has no children itself. Can anyone suggest a method for targeting the last child in the hierachy? Many thanks.
  21. Hi Antonio, Thanks for your reply. I'm not sure how this affected things, but I changed my SQL to this: SELECT page_id, pid, page_name, headline, deck, ordr FROM webtext ORDER BY pid, ordr LIMIT $offset,$recsperpage By eliminating this: WHERE page_id != '1' from the SQL, it works as expected. The record which has page_id = 1 is a special record that establishes main, category pages (those that have a pid = 1). I guess by filtering out that record I was actually making the first record that was NOT page_id = 1, the first array element, and therefore it was not displaying. I guess I don't really understand exactly how that happens in this function, but I'm glad I figured it out, so now I can move forward. Thanks for your help.
  22. I'm using Script 1.3 to display an indented listing of all "pages" of my website. I say "pages" because each page is a record in a table. The problem is that one page, the home page, is always missing from the list and I can't figure out why. The SQL is correct and returns all records, including the home page record, when I run the SQL in phpmyadmin, but it never shows up in the script. Can anyone help me understand why not? Here is the modified recursive function: // Function for displaying a list. // Receives one argument: an array. function make_list ($parent) { // Need the main $tasks array: global $pagelist; // Start an ordered list: echo '<ul id="pagelist">'; // Loop through each subarray: foreach ($parent as $pid=>$item) { // Display the item: ?> <li class="pglist <?php if (isset($pagelist[$pid])) { echo 'haschild'; } else { echo ''; } ?>"> <table class="pgdisp"> <tr> <td class="pgname "><?php echo $item['pgname']; ?></td> <td class="hdline"><?php echo $item['hdline']; ?></td> <td class="deck"><?php echo $item['deck']; ?></td> <td class="order"><?php echo $item['ordr']; ?></td> <td class="edit"><a class="cnav" href="admin.php?content=Webtext%2ftextEdit&page_id=<?php echo $item['pgid']; ?>">EDIT</a></td> <td class="delete"><a class="cnav" href="admin.php?content=Webtext%2ftextDelete&page_id=<?php echo $item['pgid']; ?>">DELETE</a></td> </tr> </table> <?php // Check for subtasks: if (isset($pagelist[$pid])) { // Call this function: make_list($pagelist[$pid]); } // Complete the list item: echo '</li>'; } // End of FOREACH loop. // Close the ordered list: echo '</ul>'; } // End of make_list() function. // Initialize the storage array: $pagelist = array(); while (list($page_id, $pid, $page_name, $headline, $deck, $ordr ) = mysql_fetch_array($getText, MYSQL_BOTH)) { // Add to the array: $pagelist[$pid][$page_id] = array('pgid'=>$page_id,'pid'=>$pid, 'pgname'=>$page_name,'hdline'=>$headline,'deck'=>$deck,'ordr'=>$ordr ); } // For debugging: //echo '<pre>' . print_r($pagelist,1) . '</pre>'; // Send the first array element // to the make_list() function: make_list($pagelist[1]); Here is my SQL: mysql_select_db($database_siteadmin, $siteadmin); $query_getText = "SELECT page_id, pid, page_name, headline, deck, ordr FROM webtext WHERE page_id != '1' ORDER BY pid, ordr LIMIT $offset,$recsperpage"; $getText = mysql_query($query_getText, $siteadmin) or die(mysql_error()); $row_getText = mysql_fetch_assoc($getText); $totalRows_getText = mysql_num_rows($getText); Interestingly, I had the same problem with my nested navigation menu that was based on this recursive function. I was able to work around it so it wasn't a problem then, but it is now. Any ideas?
  23. Craig, Thanks for the suggestion and for replying. I found a different solution which is easier for me, but your idea might actually help me with another issue I'm facing. Anyway here are the RewriteRule changes: RewriteRule ^bf/events/([0-9-]+)$ /bf/index.php?content=events&event_id=$1 RewriteRule ^bf/news/([0-9-]+)$ /bf/index.php?content=news&article_id=$1 Thanks again for your help. Cheers.
  24. After looking at some info I had on RewriteRules, it appears that the only thing matched is the pattern, differences in the substitution variables are not considered. Because the pattern is the same for both Events and News, Apache is passing along event_id (when it is first) instead of article_id (when it is second). So then how can I differentiate between the two rules? Based on Larry's modular website concept, I have the site home page (index.php) in the root directory, and I have a content directory "bf". Within the bf directory there is another index.php file which handles all of the dynamic pages. I pass along the content variable in each link so that the correct page is served; my second RewriteRule takes care of that. Now I want to pass along a record_id so I can show the requested record on the requested page. How can I do that when the pattern is the same for both News and Events, when only the record_id variable is different? I hope this makes sense what I'm saying.
×
×
  • Create New...