Jump to content

jay7981

Members
  • Posts

    175
  • Joined

  • Last visited

Everything posted by jay7981

  1. Thank you so much for breaking this down for me and thanks to you i now understan a bit better and that is all i was asking for. You have helped me tremendosly and i have learned alot from this.
  2. ok so i tried that query inplace of mine and am getting a blank page do i need to stop using the function with it? i'm sorry as i do not know much about this type of logic as i am still learning. and i think that is where me and Jess got off on the wrong foot, i did not mean to come across as ungreatful because i am greatful that sites like this exsist to help people like me. what i did was simply changed my query to yours, was there something else i missed or did not do?
  3. anyways your "solution" although broken (== instead of =) i had already corrected and am getting a blank page.
  4. yea so that didnt work, getting syntax errors .... anyone else got a solution that is actually going to work ?
  5. Table has Name Class hide John Option A 0 bob Option B 0 chris Option C 0 tom None 0 sam Option A 1 Output should be Option A John Option B bob Option C chris None tom sam Currently Getting Option A John sam Option B bob Option C chris None tom
  6. Ok so how do i fix it to do what i am wanting? obviously i dont know
  7. $class1 is being used at the end of the while because of the function being ran on the loop gathering names based on the class, i dont see how this would impair me forcing a class on users that have a hide of 1. **Desired OutPut** in the db there are 4 classes (Option A, Option B, Option C, None) and 2 Hide (0 , 1) If john has Option A and Hide of 1 i am wanting him listed with the rest that have None in thier class but if john has Option A and Hide of 0 he should be with the rest of Option A's ** End Desired OutPut** **What I'm Getting** The script works fine minus me trying to force a class on someone with hide set to 1 **End What I'm Getting**
  8. i tried this as well and got the same results if ($row['hide'] == "1") { $class1 = "None"; } //end $class1 = $row['class_1']; $users = array(); to if ($row['hide'] == "1") { $class1 = "None"; }else{ //end $class1 = $row['class_1']; } $users = array();
  9. Hey guys/gals, I have a table, and i am listing all names with thier associated class the problem i am having is i need to force a users class to "None" if thier hide field is "1" this is what i have done and its not working ... i have commented the code that is not working, as for the rest it is working great. <?php include("./sql-conn.php"); function outputClassList($class1, $users) { if (!$class1) { return false; } $userCount = count($users); $output = "<br>\n<b>{$class1}</b> ({$userCount})"; $output .= "<br>\n"; $output .= implode("<br>\n", $users); $output .= "<br>\n"; return $output; } $db = mysql_connect($hostname, $username, $password) or die('Failed to connect to database: ' . mysql_error()); mysql_select_db($database); $query = "SELECT class_1, name, hide FROM class ORDER BY class_1, name ASC" or die('Failed to Query: ' . mysql_error()); $result = mysql_query($query) or die('Failed Getting Results: ' . mysql_error()); $class1 = false; while ($row = mysql_fetch_assoc($result)) { if ($class1 != $row["class_1"]) { echo outputClassList($class1, $users); //this isn't working if ($row['hide'] == "1") { $class1 = "None"; } //end $class1 = $row['class_1']; $users = array(); } $users[] = ucfirst($row['name']); } //print_r ($users); echo outputClassList($class1, $users); mysql_free_result($result); mysql_close($db); ?>
  10. Dude You Rock!! Thanks so much that has been driving me crazy for hours ... Worked like a charm!
  11. your assumtion is correct, you can have any variation of the 3 in the same field, as for the implode i am joining the checkbox data together and then setting $actdata to that data as a comma seperated list and that is what is stored in the table. this is going to be an edit page, so i will need to have all 3 boxes statically in place and i will have a query pull the data from table and check the boxes accordingly so that the user could either add a selection or remove then re submit the form
  12. Hey all i am trying to select checkboxes using MySQL data that is in an array i have 3 checkboxes Open Close Break in the database i have a field "action" in the field is the data "Open,Close,Break" i know i can use <?= ($action=='Open')? 'checked="checked"' : '' ?> but i need to have all boxes that match the data in the field selected ... how do i go about doing this ? here is the form code for the specific field i am working with. $action= $res['action']; $actdata= implode(",", $action); <tr> <td>Action</td> <td><input type="checkbox" name="action[]" value="Open" /> Open <input type="checkbox" name="action[]" value="Close" /> Close <input type="checkbox" name="action[]" value="Break" /> Break</td> </tr>
  13. I Guess you were right i just needed to look a bit harder ... so after a shot of whiskey and a smoke ... This works <?php include_once("./pages/membership/config.php"); $count=mysql_query("SELECT COUNT(*) FROM botb_members"); $r = mysql_fetch_row($count); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 15; // find out total pages $totalpages = ceil($numrows / $rowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; ?> <?php $result=mysql_query("SELECT * FROM botb_members ORDER BY LName ASC LIMIT $offset, $rowsperpage"); ?> <table align="center" width="100%" border="0" cellspacing="2" cellpadding="2"> <td><p>There are <?php echo $numrows ; ?> Members</p></td> </tr> <tr> <td><?php if ($loggedInUser->checkPermission(array(5))) { ?> <button onclick="window.location.href='member-db.php?add'">Add Member</button> <?php } ?></td> </tr> </table> <br/> <table width="75%" align="center" border=1 style="white-space:nowrap"> <tr bgcolor='#CCCCCC'> <td><div align="center">Action</div></td> <td><div align="center">MemberID</div></td> <td><div align="center">Name</div></td> <td><div align="center">Department</div></td> <td><div align="center">Status</div></td> </tr> <?php while($res=mysql_fetch_array($result)){ $status = "Active"; if ($res['Revoked_Removed']=="x"){ $status = "Revoked"; } if ($res['Deceased']=="x"){ $status = "Deceased"; } if ($res['Inactive']=="x"){ $status = "Inactive"; } ?> <tr> <td><a href="member-db.php?viewid&ID=<?php echo $res['ID']; ?>">View</a> <?php if ($loggedInUser->checkPermission(array(5))) { ?> | <a href="member-db.php?edit&ID=<?php echo $res['ID']; ?>">Edit</a> | <a href="member-db.php?delete&ID=<?php echo $res['ID']; ?>">Delete</a> <?php } ?> </td> <td><?php echo $res['mID']; ?></td> <td><?php echo $res['FName']; ?> <?php echo $res['LName']; ?> <?php echo $res['Suffix']; ?></td> <td><?php echo $res['Department']; ?></td> <td><?php echo $status; ?></td> <?php } $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?view&currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?view&currentpage=$prevpage'><</a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?view&currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?view&currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?view&currentpage=$totalpages'>>></a> "; } // end if /****** end build pagination links ******/ ?> </table>
  14. please dont take this the wrong way as i am sick and dopped up on all sorts of meds at the moment, i cant see any error from my point of view as i have already stated i dont know anything about pagination, i cant learn from a mistake if i cannot identify the mistake and all i really want to do is learn, so if you would kindly point out the mistake and help me through this without being cyrptic it would be much appreciated.
  15. isn't that what $total_rows = mysql_num_rows($result); $r = mysql_fetch_row($result); $numrows = $r[0]; does?
  16. ok lets start over... i have found a slightly better tutorial (here on Freaks) so i am attempting to use that instead of above code so please disreguard previous posts.... I have the pagination implemeted and now my query is no longer displaying results... i get a blank table i take COUNT(*) away and maek it just * and i get my results back but no pagination ... here is the code <?php include_once("./pages/membership/config.php"); $result=mysql_query("SELECT COUNT(*) FROM botb_members ORDER BY LName ASC"); $total_rows = mysql_num_rows($result); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 15; // find out total pages $totalpages = ceil($numrows / $rowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; ?> <table align="center" width="100%" border="0" cellspacing="2" cellpadding="2"> <td><p>There are <?php echo $total_rows ; ?> Members</p></td> </tr> <tr> <td><?php if ($loggedInUser->checkPermission(array(5))) { ?> <button onclick="window.location.href='member-db.php?add'">Add Member</button> <?php } ?></td> </tr> </table> <br/> <table width="75%" align="center" border=1 style="white-space:nowrap"> <tr bgcolor='#CCCCCC'> <td><div align="center">Action</div></td> <td><div align="center">MemberID</div></td> <td><div align="center">Name</div></td> <td><div align="center">Department</div></td> <td><div align="center">Status</div></td> </tr> <?php while($res=mysql_fetch_array($result)){ $status = "Active"; if ($res['Revoked_Removed']=="x"){ $status = "Revoked"; } if ($res['Deceased']=="x"){ $status = "Deceased"; } if ($res['Inactive']=="x"){ $status = "Inactive"; } ?> <tr> <td><a href="member-db.php?viewid&ID=<?php echo $res['ID']; ?>">View</a> <?php if ($loggedInUser->checkPermission(array(5))) { ?> | <a href="member-db.php?edit&ID=<?php echo $res['ID']; ?>">Edit</a> | <a href="member-db.php?delete&ID=<?php echo $res['ID']; ?>">Delete</a> <?php } ?> </td> <td><?php echo $res['mID']; ?></td> <td><?php echo $res['FName']; ?> <?php echo $res['LName']; ?> <?php echo $res['Suffix']; ?></td> <td><?php echo $res['Department']; ?></td> <td><?php echo $status; ?></td> <?php } $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?view&currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?view&currentpage=$prevpage'><</a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?view&currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?view&currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?view&currentpage=$totalpages'>>></a> "; } // end if /****** end build pagination links ******/ ?> </table>
  17. see my edit sorry was posting as you did
  18. i know, thats why i am here looking for help. i just for some reason cannot grasp the pagination concept... of course i am down with the flu and have a major bacterial infection of the lung so this could be contributing to my demise.... but this is the code i have been fighting with... $page = isset($_GET['page']) ? (int) $_GET['page'] : 1; $pages = implode(mysql_fetch_assoc(mysql_query("SELECT COUNT(key) FROM table"))); $pages = ceil($pages / 6); foreach ($_GET as $key => $value) { if ($key != "page") $querystring .= "$key=$value&"; } for ($i = 1; $i <= $pages; $i++) { echo "<a " . ($i == $page ? "class=\"selected\" " : ""); echo "href=\"?{$querystring}page=$i"; echo "\">$i</a> "; } $result = mysql_query("SELECT * FROM table LIMIT " . (($page - 1) * 6) . ", 6");
  19. Hey all, I am trying to understand pagination and how the best way to implement but i am getting very very confused and my head is about to burst@... and cant seem to get any various ways to work with the code i currently have.. im trying to get 15 row to show per page Any help with this would be GREAT! Thanks in advance. <?php include_once("./pages/membership/config.php"); $result=mysql_query("SELECT * FROM members ORDER BY LName ASC"); $total_rows = mysql_num_rows($result); ?> <table align="center" width="100%" border="0" cellspacing="2" cellpadding="2"> <td><p>There are <?php echo $total_rows ; ?> Members</p></td> </tr> <tr> <td><?php if ($loggedInUser->checkPermission(array(5))) { ?> <button onclick="window.location.href='member-db.php?add'">Add Member</button> <?php } ?></td> </tr> </table> <br/> <table width="75%" align="center" border=1 style="white-space:nowrap"> <tr bgcolor='#CCCCCC'> <td><div align="center">Action</div></td> <td><div align="center">MemberID</div></td> <td><div align="center">Name</div></td> <td><div align="center">Department</div></td> <td><div align="center">Status</div></td> </tr> <?php while($res=mysql_fetch_array($result)){ $status = "Active"; if ($res['Revoked_Removed']=="x"){ $status = "Revoked"; } if ($res['Deceased']=="x"){ $status = "Deceased"; } if ($res['Inactive']=="x"){ $status = "Inactive"; } ?> <tr> <td><a href="member-db.php?viewid&ID=<?php echo $res['ID']; ?>">View</a> <?php if ($loggedInUser->checkPermission(array(5))) { ?> | <a href="member-db.php?edit&ID=<?php echo $res['ID']; ?>">Edit</a> | <a href="member-db.php?delete&ID=<?php echo $res['ID']; ?>">Delete</a> <?php } ?> </td> <td><?php echo $res['mID']; ?></td> <td><?php echo $res['FName']; ?> <?php echo $res['LName']; ?> <?php echo $res['Suffix']; ?></td> <td><?php echo $res['Department']; ?></td> <td><?php echo $status; ?></td> <?php } ?> </table>
  20. also when print_r($res) i get what i am expecting just not with the echo print_r($res['Department']); returns My Favorite Department but echo ($res['Department']); returns My ive figured it out ... for some reason i had to double quote the echos in the value ... <input type="text" name="Department" size="55" value="<?php echo ($res['Department']); ?>">
  21. the posted code was simply an example to show you all what i was running into, and yes the info in the database is what i want but is not being displayed correctly Edit to answer, i use escape_string because i dont trust user input, i will be adding sql error checks later as the code works perfectly with the exception of the current issue i have. i have $ID well defined for both the update and select statement before it is used. error reporting is on (ALL) within my ini again here is the code with minor mods done edit.php
  22. ive moved the closing bracket to the end of the echo and still the echo stops at teh first space, ive also editied the first post and attached the full code.
  23. hey all, I have a text field that is populated with a mysql field however it is not populating with all of the info in that field it stops at the first space of any info in the mysql field ... why would this be happening ? i am using this type of setup info in the mysql field of name is: John Doe Mercer while($res=mysql_fetch_array($result)) { $name = mysql_real_escape_string($res['name']); } echo $name; Only output i get is John edit.php
  24. Thank you Barand, I must have looked over that 500 times by now ... ok so here is the code i had to make a couple of formatting changes but it is working great now! Thank you all so much! <?php include("./includes/sql-conn.php"); function outputDepartmentList($currentDept, $users) { if(!$currentDept) { return false; } $userCount = count($users); $output = "<br>\n{$currentDept} ({$userCount})"; $output .= "<br>\n"; $output .= implode("<br>\n", $users); $output .= "<br>\n"; return $output; } $db = mysql_connect ($hostname, $username, $password) or die ('Failed to connect to database: ' . mysql_error()); mysql_select_db($database); $query = "SELECT Department, FName, LName FROM botb_members ORDER BY Department, LName ASC" or die ('Failed to Query: ' . mysql_error()); $result = mysql_query($query) or die ('Failed Getting Results: ' . mysql_error()); $currentDept = false; while($row = mysql_fetch_assoc($result)) { if($currentDept != $row["Department"]) { echo outputDepartmentList($currentDept, $users); $users = array(); $currentDept = $row['Department']; } $users[] = ucfirst($row['FName']) . ' ' . ucfirst($row['LName']); } //print_r ($users); echo outputDepartmentList($currentDept, $users); mysql_free_result($result); mysql_close($db); ?>
×
×
  • 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.