Jump to content

myotch

Members
  • Posts

    37
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

myotch's Achievements

Newbie

Newbie (1/5)

0

Reputation

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