Jump to content
Larry Ullman's Book Forums

banacan

Members
  • Posts

    48
  • Joined

  • Last visited

banacan's Achievements

Newbie

Newbie (1/14)

2

Reputation

  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.
×
×
  • Create New...