Jump to content

wrave

Members
  • Posts

    24
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

wrave's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I'm gonna take a stab at this one. If I understand your question, you want to have two selection boxes on your page. You want to select from either both or only one. So one is independent and one is dependent. Initially you only need to display the independent selection. After that value is set, you can display the second value's selection box. I think I'd build one form with potentially three form elements. Element one (a selection box) would display and allow the first selection and execute an action to re-call the page the form resides in ($SERVER('PHP_SELF')). It would pass the first selected value back to itself and then I would build a second element that does essentially the same thing but is dependent on the first value being chosen. It wouldn't even show up in the page until the independent value was set. Then I'd build a submission element to pass the variables to the query code. If both selectors are independent, I'd set up a default value of NULL for them and show both and pass them both to a script that made decisions based on what was un/set. Sorry if this isn't any help. Sometimes I think writing about code is like dancing about architecture.
  2. Thanks laffin, I went back to the manual and found the example for mysql_fetch_field() and here is my code to build my table header... echo "<table border=1><tr bgcolor=\"#ffeedd\">"; $i = 0; while ($i < mysql_num_fields($data)) { $meta = mysql_fetch_field($data, $i); if (!$meta) { echo "No information available<br />\n"; } echo "<th> $meta->name </th>"; $i++; } echo "</tr>\n"; This handles everything. Thank you all. I didn't ever find an answer to my original question as to why the function execution halted after one of the function calls but I expect there is an error in my original code somewhere. Anyway, I now have a function that will turn a query result into an HTML table and I am quite happy to have solved tis problem. I think I can mark this topic solved.
  3. I tried using mysql_field_name() and it works but how can I determine the number of fields returned by the query? When I know the fields I can number the calls to... echo mysql_field_name($r,0); echo mysql_field_name($r,1); echo mysql_field_name($r,2); ...just like the example in the manual shows. But I want the function to be able to iterate through the query fields and I don't see how to obtain that information.
  4. Thanks. So many functions so little time to read all the docs. But I keep plugging away. At least I learned a little about the split() and preg_split() functions and a teensy bit about regex. What fun!
  5. I don't like unanswered questions so here's what I have been doing... I now have a function that will display any arbitrary query in an HTML table except when all columns are selected in the query by using the asterisk (*). That's a problem for another day. I finally decided to extract the results table header list by extracting the field names from the query itself. So now my solution looks like this... function disp_query_results_HTML($query,$data) { //////////////////////////////////////// // REMOVE the QUERY tail. // //////////////////////////////////////// $list = preg_split("[ FROM.*]", $query); // show_array($list); //////////////////////////////////////// // REMOVE the QUERY head. // //////////////////////////////////////// $list = preg_split("[^SELECT]", "$list[0]"); // show_array($list); //////////////////////////////////////// // SPLIT the FIELD NAMES from the re- // // maining array section. // //////////////////////////////////////// $pieces = split(",",(string)$list[1]); $n = count($pieces); //echo "Count = $n<br /><br />\n"; echo "<table border=\"1\">\n"; echo "<tr>\n"; for ($i = 0; $i < $n; $i++) { echo "<th>$pieces[$i]</th>\n"; } echo "</tr>\n"; while ($row = mysql_fetch_array($data, MYSQL_NUM)) { echo "<tr>"; foreach ($row as $i => $value) { if ($value == "") { echo "<td> </td>"; } else { echo "<td>$value</td>"; } } echo "</tr>\n"; } echo "</tr></table><br />"; } This works although it bothers me that I still have the problem when all of the fields are selected. I realize this solution isn't very elegant but when you're up to your ass in alligators...
  6. Sorry, I made a mistake in what I wrote earlier. The first two function calls inside disp_query_results_HTML() execute correctly. $fld_names = extract_fld_names($data); disp_fld_names_HTML($fld_names); But disp_query_results() doesn't continue after the second function returns. Maybe I should try putting the remaining code into yet another function and try calling it?
  7. Immense apologies right up front because I know this topic has no doubt been cussed and discussed but I have attempted to do a search and I keep erroring out. The error page said to contact a moderator but I couldn't find a place to do that. Anyway... I am building some functions that I hope will reduce some of my typing. I have to files with functions in them and they are in my PATH. No problems there. One file contains functions to access my databases (my_db_func.php) and one that contains functions to help me display results (my_disp_func.php). I am attempting to build a generic function to display query results. I have a function that extracts the field names returned from a query. I then take those results and pass them to a function that starts building an HTML table and populates the table header cells with the field names. It doesn't close the HTML table but leaves it open so I can construct the remainder of the table with the results of a query to my database. Using these three functions I can execute a query and get a nice looking table display. So I got to thinking it would take things one step further and eliminate a couple of calls by executing the query once and passing the results to a function I call 'disp_query_results_HTML($data)'. So I attempted to place the calls to the 'extract_fld_names()' and 'disp_fld_names_HTML()' within my query results display function. Everything works beautifully if I make the calls individually but when I place a function call within a function it comes to a halt and refuses to continue with any code after the first function is called. After testing it appears that all of the data from my database query is still there. I read in the manual that PHP allows one function to call another. The display function file has a "require_once" command loading the file that contains the data manipulation functions so I know it is found. The field names are extracted. I don't get any error messages, the top field names part of the display functions correctly, but after the table header is displayed, the remainder of the calling function fails. I just can't seem to figure out why this isn't working. Here's the functions... From my_disp_func.php... [pre] function disp_query_results_HTML($data) { $fld_names = extract_fld_names($data); disp_fld_names_HTML($fld_names); $row_count = mysql_num_rows($data); $field_count = mysql_num_fields($data); while ($row = mysql_fetch_array($data, MYSQL_NUM)) { echo "<tr>"; for ($i = 0; $i < $field_count; ++$i) { if ($row[$i] == "") { echo "<td> </td>\n"; } else { echo "<td>$row[$i]</td>\n"; } } echo "</tr>\n"; } echo "</tr></table><br />"; } function disp_fld_names_HTML($header_list, $bgcolor = "#ffffdd") { $flds = count($header_list); echo "<table border=1 bgcolor=\"$bgcolor\" cellpadding=3><tr>"; for ($idx = 0; $idx <= $flds-1; ++$idx) { echo "<th>$header_list[$idx]</th>\n"; } echo "</tr>\n"; }[/pre] And from my_db_func.php... [pre] function extract_fld_names($data) { $count = count("$data"); $loop_count = 0; $list[0]= ''; while ($row = mysql_fetch_array($data, MYSQL_NUM)) { foreach ($row as $key => $value) { if ($key == 0) { $list[$loop_count] = "$value"; } } ++$loop_count; } return $list; }[/pre] I am sure this question has been asked before and again I apologise for my problems in searching the forums.
  8. wrave

    mass email

    I've just built my first real site. I finally decided on a hosting service in part because I found they provided a couple of tools to accomplish just this. My ISP doesn't provide anything but a connection and a small amount of space for my personal pages. If your hosting provider offers something like "Fantastico" you should be able to find a mass emailer. Look for "PHPlist" or something like the Perl mailer that has already been mentioned.
  9. Don't know about a "drop down menu" to do what you want to do but I have just built a scheduling package for my band that allows any band member to login and then schedule a gig date. My application requires a minimum of two tables. One for the schedule itself, date, times and a pointer field to the location (in your case it would probably be the the client) data. One for the client's info (could be used for login verification containing user id and password) so you'll know who's scheduled. I'm sure some of the old pros around here can tell you a better way but I'd present the person wanting to schedule an appointment with a display of what times are filled (quicker queries) and allow them to choose anything that isn't already scheduled if that's the way you want to do it. For my band's schedule I display the entire schedule in the form that allows the users to enter a new gig date. I don't build a check to insure that the new gig date isn't conflicting with one that has already been entered because my band members are smart enough to see if the time they're wanting us to perform is already scheduled. If not, I go in and fix their errors or they can use the management tools I built. This works well enough for a small site that doesn't have a lot of scheduling data. We normally play at the maximum, one gig per day. For a site like I think you are talking about, it's simply a matter of examining the schedule DB a bit more frequently, displaying a bit more detail and checking the input to insure no double bookings are inserted. From what you've written I am wondering if you've ever done any programming? If not, you may have only a couple of options since I don't know of any pre-packaged installable that you can just drop in to your site like the Calendar and BB packages. You could hire someone to build it for you or you can get your hands dirty with some code. In my opinion, the beauty of PHP is the fact that it's an easy language to learn and program in...even if you haven't done a lot of programming. I have been learning PHP for a couple of years in my spare time and it took me about four or five months to put the basics together enough to build my application. It was great, frustrating, fun!!! If you decide to attempt building this yourself, you'll find this is a great place to ask questions. I sure did! Good luck.
  10. I posted a topic that might be helpful. See http://www.phpfreaks.com/forums/index.php/topic,171265.0.html Good luck.
  11. I am not surprized to see that others have difficulties like those I encountered a couple of weeks ago when I first started looking into OOP. But the tutorial I presented when I started this topic has been the most enlightening one I've found so far. It was clear and concise and not written like I already knew what a constructor was or how a function could be of much use if it didn't have a return value. This tutorial is an excerpt from a book that, from what I can tell, is no longer being published, although I think they offer a PDF version of the PHP Anthology vol. 1. I have requested a PDF of the "Tips, Tricks and Hacks" book which contains three or four chapters (maybe just partial chapters) as examples of the book's contents. If it's as good as what I've seen so far I may have to get myself copies. I'm glad that some have found it useful.
  12. Last week I posted a request for help with my PHP coding style. Right away the discussion turned to MVC and OOP. I was lost. I am not sure that MVC should be introduced to a n00bie like me at the same time as OOP. I decided that I'd better find out more about OOP before tackling MVC. So I went on a search. There are probably hundreds of OOP tutorials on the web, maybe thousands and sifting my way through them was actually disturbing for me. I began to think I would never understand in a practical sense, what was going on. The fact is, many of them would lose me within the first paragraph or two. I had no mental hooks on which I could hang the terminology and it is aparently difficult for experienced PHP OOP coders to talk about this paradigm without drifting into rhapsodic passages that cannot be understood by the uninitiated. This isn't their fault, it's a difficult programming practice to comprehend for someone that is used to procedural programming. Well, I found this one, written by Harry Fuecks for his "The PHP Anthology, Volume 1: Foundations" that works for me... http://www.webreference.com/programming/phpanth2/ ...and maybe it'll work for you too. I hope this doesn't break any forum rules. If posting off site tutorials is allowed, I suggest anyone that is trying to comprehend OOP in PHP and who is new to the concept and struggling, take a look at this one. I've been using PHP for a while abd built a couple of web apps so I had some of the basics down. I wanted to see a tutorial that introduced PHP OOP in a way that reflected how it can be used to build web pages. Maybe this is you too. Give this one a try and see what you think. If I've broken some rule or posted to the wrong forum, I apologise and request one of the moderators to please move this to the proper place. Happy coding y'all!
  13. As "Carsoni the Great" I am about to make a prediction. Someday in the future, roopurt18 will be known for producing the worlds greatest OOP Tutorial!!!
  14. I see where it would be tempting to access a property directly, a very small reduction in the amount of code to be written. $a->a = 'Hello!'; versus $a->set_a('Hello'); plus what if you forget the exact name of the methods, then you've got to get into the file and look them up. But I do see where you would be invalidating the reusability and I'm grateful for the heads up. By interface, I am guessing you are referring to any method that accesses the properties found in the class. I spent the day at work today (I was off yesterday) where they just moved my desk and they still haven't connected me back to the network. But I had access to the web so I spent the day looking for information and tutorials on OOP. I found a couple of good ones, one here on PHPFreaks, that I will be studying in depth. I have no doubt that I will have a lot more questions as time goes along.
  15. roopurt18: You have successfully brought me back to reality. Somewhere along the way yesterday I got lost and was thinking exactly what you wrote. My application is fairly simple. I was thinking it so simple to cut-and-paste the code when there are only a few places in the system where it is used and I did exactly that. I think originally I was more interested in coding style than reuseability but of the two, reuseability is the more important. This is especailly true of large applications. Of course, style will make it easier to find the code snippet I want if I have to go in and make query changes in just a few files. But as you point out, this really becomes a major pain if this were a very large and complex system. I'm going back to look at the cakePHP site. Now that my head is straightened out a bit I see where cake can simplify creating multiple applications on the same DB. Where my query might now be used to provide a data display (view) for users, I might want to build a DB management application that would require the same display. And if I had to change the table structure, I'd have to make changes to the code for both applications. That could be very messy. I can't help but make the comment that I began using PHP and MySQL about a year and a half ago and it has been the most enjoyable experience in my computing career. I've never built an application so quickly nor had it turn out so well. But more importantly I see that learning can still be enjoyable and it is in a large part due to the helpfullness of the contributors to these forums. roopurt18 thanks again for your help. Your explanations are so clear that you should be teaching. And everyone else that has commented has helped me too. You folks are great! I think I can mark this thread solved.
×
×
  • 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.