Jump to content

myotch

Members
  • Posts

    37
  • Joined

  • Last visited

Everything posted by myotch

  1. Well, marked this "solved"! #6 was the key. It was very much user error, and the fact that I still don't know what I did wrong probably speaks volumes. But a cut&paste into a different HTML editor worked perfectly and the three columns displayed as wanted. I really am sorry for being a pain in the butt. This little site is my current project, but it means a lot more. Thanks again!
  2. My heartfelt apologies. There was no change in the source. I do recognize the considerable work you and jcbones put into this, and I am grateful. Do you think it would be better to get this code right and then use the correct php code as the reference to convert to pdo? Maybe because of my frustration, my thinking at this point is, if I need to change to PDO anyway, maybe I need to focus on that. I've got a PDO testing file now and saved my working index using pdo connection. There's tutorials about using pdo to get a 3 column html table in echoing db data.
  3. OK, narrowing it down.... The sandbox page's problem area is using this source: <div class="row"> <div class="span5"> <h2>Counties of Virginia</h2> <table width=100%> <tr> <a href='defendant_services.php?county=3214'>Accomack</a><br /> </td> <a href='defendant_services.php?county=3215'>Albemarle</a><br /> </td> <a href='defendant_services.php?county=3216'>Alleghany</a><br /> </td>... And the original code is diplaying this source code: <div class="row"> <div class="span5"> <h2>Counties of Virginia<h4>Click on a county link below to view more information on Defendant Services in that area.</h4><hr> <p></p> <table width=100%><tr><td valign=top width=33%> <a href="defendant_services.php?county=3214">Accomack</style></a><br /> <a href="defendant_services.php?county=3215">Albemarle</style></a><br /> <a href="defendant_services.php?county=3216">Alleghany</style></a><br /> So it seems the problem would be with this line of PHP not being called: $output .= "<tr>\n"; nor this one: if($recCount%$recPerCol==1) { $output .= "<td valign='top' width='{$colWidth}%'>\n"; } since neither are being called.
  4. It doesn't here: http://defbail.com/sandbox/counties.php?state=46 (with Psycho's code) But it does here: http://defbail.com/counties.php?state=46 (with the original code) I really do appreciate you putting eyeballs on this. It's a lot of work.
  5. Here's how the old code from the OP renders: Here's how the new code renders (note: single column): And the New Code, for the state of Virginia (which does not render in the old code): Try for yourself live at www.defbail.com and www.defbail.com/sandbox Domain is the old code, sandbox is the new code. As soon as the wrinkle is ironed, I'll delete the non-sandbox files. Here's the print-r: Array( [0] => Array ( [id] => 1 [name] => Alexandria ) [1] => Array ( [id] => 2 [name] => Bristol ) [2] => Array ( [id] => 3 [name] => Buena Vista ) [3] => Array ( [id] => 4 [name] => Charlottesville ) [4] => Array ( [id] => 5 [name] => Chesapeake ) [5] => Array ( [id] => 6 [name] => Colonial Heights ) [6] => Array ( [id] => 7 [name] => Covington ) [7] => Array ( [id] => 8 [name] => Danville ) [8] => Array ( [id] => 9 [name] => Emporia ) [9] => Array ( [id] => 26 [name] => etersburg ) [10] => Array ( [id] => 10 [name] => Fairfax ) [11] => Array ( [id] => 11 [name] => Falls Church ) [12] => Array ( [id] => 12 [name] => Franklin ) [13] => Array ( [id] => 13 [name] => Fredericksburg ) [14] => Array ( [id] => 14 [name] => Galax ) [15] => Array ( [id] => 15 [name] => Hampton ) [16] => Array ( [id] => 16 [name] => Harrisonburg ) [17] => Array ( [id] => 17 [name] => Hopewell ) [18] => Array ( [id] => 18 [name] => Lexington ) [19] => Array ( [id] => 19 [name] => Lynchburg ) [20] => Array ( [id] => 20 [name] => Manassas ) [21] => Array ( [id] => 21 [name] => Manassas Park ) [22] => Array ( [id] => 22 [name] => Martinsville ) [23] => Array ( [id] => 23 [name] => Newport News ) [24] => Array ( [id] => 24 [name] => Norfolk ) [25] => Array ( [id] => 25 [name] => Norton ) [26] => Array ( [id] => 27 [name] => Poquoson ) [27] => Array ( [id] => 28 [name] => Portsmouth ) [28] => Array ( [id] => 29 [name] => Radford ) [29] => Array ( [id] => 30 [name] => Richmond ) [30] => Array ( [id] => 31 [name] => Roanoke ) [31] => Array ( [id] => 32 [name] => Salem ) [32] => Array ( [id] => 33 [name] => Staunton ) [33] => Array ( [id] => 34 [name] => Suffolk ) [34] => Array ( [id] => 35 [name] => Virginia Beach ) [35] => Array ( [id] => 36 [name] => Waynesboro ) [36] => Array ( [id] => 37 [name] => Williamsburg ) [37] => Array ( [id] => 38 [name] => Winchester ) [38] => )
  6. Oh crap! Forgot to include this with the code above. It's in there, just didn't cut and paste properly. //Function to create output for counties/cities of a state function createEntityOutput($stateName, $headerFormat, $entityData, $entityFormat, $columns) { //If no records, return empty string if(!count($entityData)) { return ''; } //Create the output $output = "<h2>" . sprintf($headerFormat, $stateName) . "</h2>\n"; $output .= "<table width='100%'>\n"; //Create needed variables $recTotal = count($entityData); $recPerCol = ceil($recTotal / $recCols); $colWidth = floor(100 / $columns); $recCount = 0; //Create entity output $output .= "<tr>\n"; foreach($entityData as $data) { $countyCount++; //Open new column, if needed if($recCount%$recPerCol==1) { $output .= "<td valign='top' width='{$colWidth}%'>\n"; } //Create output for single entitiy $output .= sprintf($entityFormat, $data['id'], $data['name']); //Close column, if needed if($recCount%$recPerCol==0 || $recCount==$recTotal) { $output .= "</td>\n"; } } $output .= "</tr>\n"; $output .= "</table>\n"; return $output; } //Run query to get state data //$cmt = $dhb->prepare('SELECT * FROM state WHERE st_id=$statecode'); //$cmt->execute(); //$data = $cmt->fetchAll(); $query = "SELECT * FROM state WHERE st_id=$statecode"; $result = mysql_query($query) or die("Query $query failed : " . mysql_error()); $state = mysql_fetch_assoc($result); $stateName = $state['st_name']; $stateNote = $state['state_notes']; //Run query to get county data //$cqt = $dhb->prepare('SELECT county_id AS id, county_name AS name FROM counties WHERE st_id=$statecode and visible=1 ORDER BY county_name ASC'); //$cqt->execute(); //$data = $cq->fetchAll(); $query = "SELECT county_id AS id, county_name AS name FROM counties WHERE st_id=$statecode AND visible=1 ORDER BY county_name ASC"; $result = mysql_query($query) or die("Query $query failed : " . mysql_error()); Create county output $countyData = array(); while($countyData[] = mysql_fetch_assoc($result)) {} $countyTable = createEntityOutput($stateName, "Counties of %s", $countyData, "<a href='services.php?county=%d'>%s</a><br />\n", 3); //Run query to get state data $query = "SELECT city_id AS id, city_name AS name FROM cities WHERE st_id=$statecode AND visible=1 ORDER BY city_name ASC"; $result= mysql_query($query) or die("Query $query failed : " . mysql_error()); //Create city output $cityData = array(); $cityTable = NULL;if(mysql_num_rows($result) > 0) { while($cityData[] = mysql_fetch_assoc($result)) {} $cityTable = createEntityOutput($stateName, "Independent cities of %s", $cityData, "<a href='services.php?city=%d'>%s</a><br />\n", 3);} ?> <?php echo $countyTable; ?> <br> <?php echo $cityTable; ?> </div> <div class="span4"> <h3>Defendant Services in <?php echo $stateName; ?></h3> <?php echo $stateNote; ?>
  7. When I get the sandbox done, I'll post some links if you need, or just screenshots if that will do.
  8. Sure! I've started the process of udating to PDO....I'll move it over to a sandbox and revert back to it's older self. Here's the code (with the incomplete updates commented out): //Function to create output for counties/cities of a state function createEntityOutput($stateName, $headerFormat, $entityData, $entityFormat, $columns) { //If no records, return empty string if(!count($entityData)) { return ''; } //Create the output $output = "<h2>" . sprintf($headerFormat, $stateName) . "</h2>\n"; $output .= "<table width='100%'>\n"; //Create needed variables $recTotal = count($entityData); $recPerCol = ceil($recTotal / $recCols); $colWidth = floor(100 / $columns); $recCount = 0; //Create entity output $output .= "<tr>\n"; foreach($entityData as $data) { $countyCount++; //Open new column, if needed if($recCount%$recPerCol==1) { $output .= "<td valign='top' width='{$colWidth}%'>\n"; } //Create output for single entitiy $output .= sprintf($entityFormat, $data['id'], $data['name']); //Close column, if needed if($recCount%$recPerCol==0 || $recCount==$recTotal) { $output .= "</td>\n"; } } $output .= "</tr>\n"; $output .= "</table>\n"; return $output; } //Run query to get state data //$cmt = $dhb->prepare('SELECT * FROM state WHERE st_id=$statecode'); //$cmt->execute(); //$data = $cmt->fetchAll(); $query = "SELECT * FROM state WHERE st_id=$statecode"; $result = mysql_query($query) or die("Query $query failed : " . mysql_error()); $state = mysql_fetch_assoc($result); $stateName = $state['st_name']; $stateNote = $state['state_notes']; //Run query to get county data //$cqt = $dhb->prepare('SELECT county_id AS id, county_name AS name FROM counties WHERE st_id=$statecode and visible=1 ORDER BY county_name ASC'); //$cqt->execute(); //$data = $cq->fetchAll(); $query = "SELECT county_id AS id, county_name AS name FROM counties WHERE st_id=$statecode AND visible=1 ORDER BY county_name ASC"; $result = mysql_query($query) or die("Query $query failed : " . mysql_error()); Create county output $countyData = array(); while($countyData[] = mysql_fetch_assoc($result)) {} $countyTable = createEntityOutput($stateName, "Counties of %s", $countyData, "<a href='services.php?county=%d'>%s</a><br />\n", 3); //Run query to get state data $query = "SELECT city_id AS id, city_name AS name FROM cities WHERE st_id=$statecode AND visible=1 ORDER BY city_name ASC"; $result= mysql_query($query) or die("Query $query failed : " . mysql_error()); //Create city output $cityData = array(); $cityTable = NULL;if(mysql_num_rows($result) > 0) { while($cityData[] = mysql_fetch_assoc($result)) {} $cityTable = createEntityOutput($stateName, "Independent cities of %s", $cityData, "<a href='services.php?city=%d'>%s</a><br />\n", 3);}
  9. I copied and pasted the code as supplied here. The only, and I mean only difference is creating variables for thestate_name and a field called state_note, for which I call in other parts of the page - sidebar, specifically. (psycho, it really is superior code to what I had originally had). jcbones's tweak made the heading disappear when there are no cities within the called state code. In the database, there are currently, absolutely no references to any other indexed state other than Virginia, so testing on this is rather easy. Thanks to you both! I mean, a whole bunch! Today is dedicated to fixing the column problem. It's still showing up in a single and very long column for both county and city. Cheers!
  10. The problem is that it is echoing the header for the independent cities section when the table cities doesn't have cities for the indexed state. That's the main problem, for which the OP was posted. Intention: if (cities for the called state is not empty) echo heading; echo list of states in a three-column table; else (if cities for the called state is populated) don't echo anything; The actual result for a state with no independent cities: HEADING (no list) The actual result for a state with independent cities: HEADING (list, in a single column)
  11. Thanks, Psycho. I tried your code as is, and it calls all the information flawlessly. It doesn't put the results in a 3 column table, and in states where there are no cities, it still displays the heading for the cities section. I'll use your code as a base and try to tweak it through. Again, thanks - this is a big improvement over the antiquated code I'm working with.
  12. I am working on a project that involves providing details for county government, and if applicable, cities independent of county oversight. Virginia is a state with a lot of independent cities, so I wanted to echo them in a separate list underneath the county governments. This code works fine when displaying Virginia information. However, I would like to hide the Independent Cities heading in every other state. For some reason, this code still echoes the Independent Cities heading in states without independant cities in the database. Any thoughts or wisdom? (sorry for pasting the whole bulky code) $query = "SELECT * FROM state WHERE st_id=$statecode"; $result = mysql_query($query) or die("Query $query failed : " . mysql_error()); $row = mysql_fetch_assoc($result); $state_name=$row["st_name"]; $state_note=$row["state_notes"]; echo "<h2>Counties of " . $state_name; "</h2>\n"; $query = "SELECT * FROM counties WHERE st_id=$statecode AND visible=1 ORDER BY county_name ASC"; $result = mysql_query($query) or die("Query $query failed : " . mysql_error()); echo "<table width=100%><tr><td valign=top width=33%>\n"; $count = 1; $col = 0; $rowcount = (int)(mysql_num_rows($result) / 3) + 1; $remainder = mysql_num_rows($result) - ($rowcount - 1) * 3; /* ********************************************************* */ while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<a href=\"services.php?county=".$row["county_id"]."\">".$row["county_name"] . "</style></a><br />\n"; $count = $count + 1; if ((($remainder > 0) && ($count == ($rowcount + 1))) || (($remainder <= 0) && ($count == $rowcount))) { $col = $col + 1; if ($col!=3) { echo "</td><td valign=top width=33%>\n"; $count = 1; if ($remainder > 0) $remainder = $remainder - 1; } } } /* ********************************************************* */ echo "</td></tr></table><br>\n"; mysql_free_result($result); /* ********************************************************* */ $query2 = "SELECT * FROM cities WHERE st_id=$statecode AND visible=1 ORDER BY city_name ASC"; $result2= mysql_query($query2) or die("Query $query failed : " . mysql_error()); $city_id = $row['city_id']; $city_name = $row['city_name']; if ($city_id!="") { echo "<h3>Independent cities of " . $state_name; "</h3>\n"; echo "<table width=100%><tr><td valign=top width=33%>\n"; $count2 = 1; $col2 = 0; $rowcount2 = (int)(mysql_num_rows($result2) / 3) + 1; $remainder2 = mysql_num_rows($result2) - ($rowcount2 - 1) * 3; /* ********************************************************* */ while ($row = mysql_fetch_array($result2, MYSQL_ASSOC)) { echo "<a href=\"services.php?county=".$row["city_id"]."\">".$row["city_name"] . "</style></a><br />\n"; $count2 = $count2 + 1; if ((($remainder2 > 0) && ($count2 == ($rowcount2 + 1))) || (($remainder2 <= 0) && ($count2 == $rowcount2))) { $col2 = $col2 + 1; if ($col2!=3) { echo "</td><td valign=top width=33%>\n"; $count2 = 1; if ($remainder2 > 0) $remainder2 = $remainder2 - 1; } } } /* ********************************************************* */ echo "</td></tr></table><br>\n"; mysql_free_result($result2); /* ********************************************************* */ } ?>
  13. Excellent, it worked! I knew it was something small, but I'm code blind and sleepy.
  14. Took Skoglund's Lynda course on creating a CMS for a project I am doing for a customer. I was extremely careful to set up the database, and pretty much copying everything he was doing in the course. So, I try to create a user in the database, and....crickets. Name and password don't come up. No error messages from the site. Just, nothing. So I'm sure it's pretty simple to fix, otherwise, there would have been chaos, right? For the page: hawcreekrenovations.com/new_user.php We know the page is correctly connecting to the MySQL because the drop down in the form is populated by the user-types in the database. So, I guess, you need the pertinent code: // START FORM PROCESSING if (isset($_POST['submit'])) { //Form has been submitted $errors = array(); // perform validations on the form data $required_fields = array('username', 'password', 'user_type_id' ); $errors = array_merge($errors, check_required_fields($fields_with_lengths, $_POST)); $fields_with_lengths = array('username' => 30, 'password'=> 30); $errors = array_merge($errors, check_max_field_lengths($fields_with_lengths, $_POST)); $username = trim(mysql_prep($_POST['username'])); $password = trim(mysql_prep($_POST['password'])); $hashed_password = sha1($password); $user_type_id = trim(mysql_prep($_POST['user_type_id'])); if ( empty($errors) ) { $query = "INSERT INTO users ( username, hashed_password, user_type_id ) VALUES ( '{$username}', '{$hashed_password}', '{$user_type_id}' )"; $result = mysql_query($query, $connection); if ($result) { $message = "The user was successfully created."; } else { $message = "The user could not be created."; $message .= "<br />" . mysql_error(); } } else { if (count($errors) == 1) { $message = "There was 1 error in the form."; } else { $message = "There were " . count($errors) . " erros in the form."; } } } else { // Form has not been submitted. $username = ""; $password = ""; } ?> And the form: <form action="new_user.php" method "post"> <table> <tr> <td>Username:</td> <td><input type="text" name="username" maxlength="30" value="<?php echo htmlentities($username); ?>" /></td> </tr> <tr> <td>Password:</td> <td><input type="password" name="password" maxlength="30" value="<?php echo htmlentities($password); ?>" ? /></td> </tr> <tr> <td>User Type:</td> <td><?php // 3. Perform database query $result = mysql_query("SELECT * FROM user_type", $connection); if (!$result) { die("Database query failed: " . mysql_error()); } // 4. Use returned data (if any) echo "<select name='type'>"; while ($row = mysql_fetch_array($result)) { echo "<option value=\"".$row["user_type_id"]."\">".$row["type"] . "</option>"; } echo "</select>"; ?></td> </tr> <tr> <td colspan="2"><input type="submit" name="submit" value="Create user" /></td> </tr> </table> </form>
  15. I'll walk you first through what is working: <?php echo($user['biz_site'] != '' ? "<h4>Web Site</h4>" . $user['biz_site'] : ""); ?> In a results page, the code renders something that looks like: What I'd like instead is something like this: ...where the "visit site" links to the site. I'm trying to address a problem of some sites, especially government sites, having 75+ character-long addresses, which messes up the finite space I have allotted for site addresses. Everything I've tried thus far has rendered blank white pages. (the original code posted up top does not produce a hyperlink)
  16. OK, it is fixed now. I took the reservation form, and had it go to a confirmation page. The confirmation page's form action is to the form mailer script (gdform.php), and a hidden redirect to the thankyou page sending the called echoed values from a hidden table within the form upon the click of the submit button labeled "Confirm". Workin' pretty charmy. If you want to see it in action, it is at http://www.artisanrestaurants.com. Did a similar thing with http://www.minidoss.com last year.
  17. There's a hidden input redirect on line 2 of the code supplied.
  18. My form values are not posting on my thankyou.php page. I'm sure it's a simple fix. Here's some code from reservation.php . form action="CGI/gdform.php" method="post" enctype="application/x-www-form-urlencoded" name="formres" id="formres"> <input type="hidden" name=" redirect" value="ThankYou.php"> <label><span class="style12">Your Name: <input type="text" name="txtName" id="Name" /> </span></label> ... <p class="style12"><span id="sprytextfield10"> <label>Date of Special Event: <input type="text" name="DateReq" id="DateReq" /> </label> <?php $txtName = $_GET[txtName]; ... $DateReq = $_GET[DateReq]; ?> </form> On my thankyou.php: <body> <?php $txtName = $_POST[txtName]; ... $DateReq = $_POST[DateReq]; ?> and a little lower down... <?php echo $txtName ?> ... <?php echo $DateReq ?> Any reason why the thank you page isn't calling the values? I exhaustively checked it against a working form I have on another site, and the code seems to be, well, identical. Not getting an error, just get empty space where the values should be.
  19. I looked for and found a similar thread, but the resulting bunny trail was specific to that OP's situation. I'll jump right to it. I've seen this done on another site, and I want to implement it the same way on another site I'm doing. Any typical page of the site will have includes files, quite a few of them nested like those little russian dolls. For instance, the about us page calls includes/header.php... <?php include("includes/header.php") ?> ...and the header.php file calls the meta information... <?php include("includes/site_titles.php") ?> <?php include("includes/site_keywords.php") ?> <?php include("includes/site_descriptions.php") ?> ...and those files have arrays... <?php $SITE_TITLES = array(); $SITE_TITLES['about_us'] = $SITE_TITLE . " About Us"; $SITE_TITLES['page2'] = $SITE_TITLE . " page2"; $SITE_TITLES['page3'] = $SITE_TITLE . " page3"; ?> ...and going back to our header.php, in the appropriate place, we echo the title and meta... <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title><?=$SITE_TITLES[$page]?></title> <meta name="description" content="<?php echo $SITE_DESCRIPTIONS[$page]?>" /> <meta name="keywords" content="<?php echo $SITE_KEYWORDS[$page]?>" /> ...which, when uploaded, *should* display in "view source" the correct title tag, keywords, and description. However, when I do this, I get empty tags. Am I supposed to define the site variable ($SITE)? Or am I doing something else wrong? I have the original source where I first saw this in Dreamweaver, but am unable to find a file where $SITE and all it's little buddies are defined to correspond with a file name ('about' = ("about.php"). Any help or advice is greatly appreciated. Myotch
  20. BEAUTIFUL! SIMPLE! PERFECT! SOLVED!
  21. Having a time of this. Currently, I have a called string from the MYSQL db which echos all the customer contact information. Here is the line I'm having problems with. echo "Website: <a href=\"" .$row["biz_site"]. "\" target=_blank>" .$row["biz_site"]. " </a><br />\n"; Because some of our listers have vulgarly long URL's, I'd like to change the visible link to something short and sweet: Click here for website. However, when I change it to this: echo "Website: <a href=\"" .$row["biz_site"]. "\" target=_blank>" Click here for website " </a><br />\n"; I get errors, such as "Expecting ';" or '.'" Any advice?
  22. ...and mark this one as "SOLVED!". Write the tutorial! Hurrah! Hazzah! Thorpe, you are awesome! Put yourself in for a raise and your band MM9 rocks, too! Now I can getting back to what I do best....the art stuff.
  23. double post - sorry, my 'puter's slow
×
×
  • 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.