Jump to content

Skatecrazy1

Members
  • Posts

    126
  • Joined

  • Last visited

Everything posted by Skatecrazy1

  1. well here's the sql data in xml form, read the html i posted above for the values of the numbers in the priority, group, & type columns [code] <?xml version="1.0" encoding="utf-8" ?> <!-- - - phpMyAdmin XML Dump - version 2.9.0.1 - http://www.phpmyadmin.net - - Host: localhost - Generation Time: Nov 09, 2006 at 05:38 PM - Server version: 5.0.24 - PHP Version: 5.1.6 --> <!-- - Database: 'project' --> <project>   <!-- Table project_general -->     <project_general>         <rec_num>1</rec_num>         <notes>demo exterior window system and install new hollowcore door and frame.</notes>         <name>Demo restaurant opening</name>         <start_date>11/3/2006</start_date>         <end_date>11/5/2006</end_date>         <finish_date>11/8/2006</finish_date>         <amount>1500.00</amount>         <manager>ron</manager>         <priority>3</priority>         <type>4</type>         <group>3</group>     </project_general>     <project_general>         <rec_num>2</rec_num>         <notes>adding sunroom to client's house, need 2000 sq. footage to accomplish</notes>         <name>Sun Room Addition</name>         <start_date>2/31/05</start_date>         <end_date>2/13/06</end_date>         <finish_date>2/15/06</finish_date>         <amount>1500.00</amount>         <manager>Dakota</manager>         <priority>1</priority>         <type>3</type>         <group>2</group>     </project_general> </project> [/code]
  2. No, I'm not off by one, because in some cases it's off by two or three values. [code] <form method="url" action="/select/index.php"> <select name="type"> <option selected></option> <option value="1">Site Work</option> <option value="2">Concrete</option> <option value="3">Masonry</option> <option value="4">Metal Work</option> <option value="5">Drywall</option> </select> | <select name="priority"> <option selected></option> <option value="1">Urgent</option> <option value="2">High</option> <option value="3">Normal</option> <option value="4">Low</option> </select> | <select name="group"> <option selected></option> <option value="1">Contractural</option> <option value="2">Owner</option> <option value="3">Subcontractor</option> <option value="4">General Condition</option> <option value="5">Rental</option> <option value="6">Administrative</option> </select> | <input type="hidden" value="track" name="hidden" /> <input type="submit" value="Find"> </form> <table cellpadding="4" border="1"> <tr> <th>Manager</th> <th>Name</th> <th>Start Date</th> <th>End Date</th> <th>Finish Date</th> <th>Amount</th> <th>Notes</th> </tr> <tr> <td>ron</td> <td>Demo restaurant opening</td> <td>11/3/2006</td> <td>11/5/2006</td> <td>11/8/2006</td> <td>1500.00</td> <td>demo exterior window system and install new hollowcore door and frame.</td> </tr> <tr> <td>Dakota</td> <td>Sun Room Addition</td> <td>2/31/05</td> <td>2/13/06</td> <td>2/15/06</td> <td>1500.00</td> <td>adding sunroom to client's house, need 2000 sq. footage to accomplish</td> </tr> </table> [/code]
  3. Well, I posted a topic on this before and got an answer, but now I'm having an entirely new problem: my priority levels, (urgent, high, medium, low) are assigned to numbers in my database, and i have a dropdown populated by the table priority_level everything seems to work alright with this: [code] <?php  $self = $_SERVER['PHP_SELF']; function echoSpacer() {   $space = " | ";   echo $space; } $conn = @mysql_connect("localhost", "root", "") or die(mysql_error()); $type_rs = @mysql_select_db("type"); /*---------------------------------------------------*/ /*---------------PROJECT TYPE SELECT BOX-------------*/ $type_sql = "SELECT * FROM `selection_type` order by `rec_id`"; $type_rs = @mysql_query($type_sql, $conn) or die(mysql_error()); //start building selector echo("<form method=\"url\" action=\"$self\">"); $type .= "<select name=\"type\">"; $type .= "<option selected></option>"; while($row = mysql_fetch_array($type_rs)) {   $type .= "<option value=\"".$row['rec_id']."\">".$row['name']."</option>"; } $type .= "</select>"; echo $type; echoSpacer(); /*-------------END PTYPE SELECT---------------------*/ /*--------------------------------------------------*/ /*--------------PRIORITY SELECT BOX-----------------*/ $priority_rs = @mysql_select_db("priority") or die(mysql_error()); $priority_sql = "SELECT * FROM `priority_value`"; $priority_rs = @mysql_query($priority_sql, $conn) or die(mysql_error()); $priority = "<select name=\"priority\">"; $priority .= "<option selected></option>"; while($pr_row = mysql_fetch_array($priority_rs)) {   $priority .= "<option value=\"".$pr_row['rec_id']."\">".$pr_row['name']."</option>"; } $priority .= "</select>"; echo $priority; echoSpacer(); /*-------------END PRIORITY SELECT------------------*/ /*--------------------------------------------------*/ /*-----------GROUP SELECT BOX-----------------------*/ $group_rs = @mysql_select_db("group") or die(mysql_error()); $group_sql = "SELECT * FROM `group_name`"; $group_rs = @mysql_query($group_sql, $conn) or die(mysql_error()); $group = "<select name=\"group\">"; $group .= "<option selected></option>"; while($group_row = mysql_fetch_array($group_rs)) {   $group .= "<option value=\"".$group_row['rec_id']."\">".$group_row['name']."</option>"; } $group .= "</select>"; echo $group; echoSpacer(); /*-------------END GROUP SELECT--------------------*/ echo("<input type=\"hidden\" value=\"track\" name=\"hidden\" />"); echo("<input type=\"submit\" value=\"Find\">"); echo("</form>"); /*-------------------------------------------------*/ /*--------------START DISPLAY RESULTS--------------*/ //write new values for the variables $group_val = $_GET['group']; $priority_val = $_GET['priority']; $type_val = $_GET['type']; //we don't want the vars to exist if they're null, it'll screw up our //sql querying, so unset them if they're null $rs = @mysql_select_db("project") or die(mysql_error()); //write true/false value $add_where = false; //write the basic SQL that will always be there $sql = "SELECT * FROM `project_general`"; //begin writing dynamic sql query if(!empty($group_val)){   $sql .= " WHERE `group`=\"$group_val\"";   $add_where = true;   } elseif(!empty($priority_val)){   if($add_where == true){     $sql .= " OR ";     } else {     $sql .= " WHERE ";     $add_where = true;     }   $sql .= "`priority`=\"$priority_val\"";   }     elseif(!empty($type_val))   {     if($add_where == true){     $sql .= " OR ";     } else {     $sql .= " WHERE ";     $add_where = true;     }     $sql .= "`type`=\"$type_val\"";     } $result = "<table cellpadding=\"4\" border=\"1\">"; $result .= "<tr><th>Manager</th><th>Name</th><th>Start Date</th><th>End Date</th><th>Finish Date</th> <th>Amount</th><th>Notes</th></tr>"; $rs = @mysql_query($sql, $conn) or die(mysql_error()); while($row = mysql_fetch_array($rs)) {   $result .= "<tr><td>".$row['manager']."</td><td>".$row['name']."</td>";   $result .= "<td>".$row['start_date']."</td>";   $result .= "<td>".$row['end_date']."</td>";   $result .= "<td>".$row['finish_date']."</td>";   $result .= "<td>".$row['amount']."</td>";   $result .= "<td>".$row['notes']."</td>";   $result .= "</tr>"; } $result .= "</table>"; echo $result; ?> [/code] except for the fact that the input from the dropdown doesn't match the values it's calling. for example, when I call something with the form with a low priority level, it gives me the result of something with a medium priority level. help is appreciated, as always -dakota
  4. nope, same result; all i'm passing is numbers (1, 2, 3, 4, & 5) so i was just using get
  5. if you're using cookies whatever cookie is keeping the user logged in, set it empty: [code] setcookie("cookie_logged_in", "", time()+36000); [/code] if you're using sessions, which I hope you are, look up [url=http://www.php.net/session_destroy]session_destroy()[/url] and [url=http://www.php.net/session_unset]session_unset()[/url]
  6. copy is easier the other method is more foolproof, however.
  7. okay, well the bool is just empty($var) the problem now is: when you specify the method="url" in the form, it automatically passes the variables into the URL. i want to stop any emtpy variables from being passed. that's what I was getting at.
  8. very messy here: [code] (:mem_id:,:pho_id:,':comment:',NOW(),".$info["fname"].")"; [/code]
  9. Okay now I get the problem of, when a user doesn't select anything, the GETs get sent as emtpy variables, but they're still set variables, so the SQL basically still doesn't work because of this.  any way to not set the $_GET variables if the select input is emtpy?
  10. list of data from db table: [code] <?php $conn = @mysql_connect("server", "username", "password") or die(mysql_error()); $rs = @mysql_select_db("database_name") or die(mysql_error()); $sql = "SELECT * FROM `table`"; $rs = @mysql_query($sql, $conn) or die(mysql_error()); while($row = mysql_fetch_array($rs)) {    $list .= "List values as ".$row['column_name']." here"; } echo $list; ?> [/code] Populating Dropdown from array: [code] <?php $arr = array("Option 1", "option 2", "option 3"); $sel = "<select name=\"dropdown\">"; $sel .= "<option selected>Select An Option</option>"; foreach($arr as $menu) {   $sel .= "<option>$menu</option>"; } $sel .= "</select>"; echo $sel; ?> [/code]
  11. Yeah basically PHP passes data through the server's PHP installation which processes what HTML to output.
  12. Can you have more than one WHERE clause?
  13. Well I haven't put much effort into finding a way around this, but here's my code, if you can understand php well enough you'll see it's a form that filters out mySQL results and shows the pertinent ones [code] <?php  $self = $_SERVER['PHP_SELF']; function echoSpacer() {   $space = " | ";   echo $space; } $conn = @mysql_connect("localhost", "root", "") or die(mysql_error()); $type_rs = @mysql_select_db("type"); /*---------------------------------------------------*/ /*---------------PROJECT TYPE SELECT BOX-------------*/ $type_sql = "SELECT * FROM `selection_type` order by `rec_id`"; $type_rs = @mysql_query($type_sql, $conn) or die(mysql_error()); //start building selector echo("<form method=\"url\" action=\"$self\">"); $type .= "<select name=\"type\">"; $type .= "<option selected value=\"\">-=Work Type=-</option>"; while($row = mysql_fetch_array($type_rs)) {   $type .= "<option value=\"".$row['rec_id']."\">".$row['name']."</option>"; } $type .= "</select>"; echo $type; echoSpacer(); /*-------------END PTYPE SELECT---------------------*/ /*--------------------------------------------------*/ /*--------------PRIORITY SELECT BOX-----------------*/ $priority_rs = @mysql_select_db("priority") or die(mysql_error()); $priority_sql = "SELECT * FROM `priority_value`"; $priority_rs = @mysql_query($priority_sql, $conn) or die(mysql_error()); $priority = "<select name=\"priority\">"; $priority .= "<option selected value=\"\">-=Priority Level=-</option>"; while($pr_row = mysql_fetch_array($priority_rs)) {   $priority .= "<option value=\"".$pr_row['rec_id']."\">".$pr_row['name']."</option>"; } $priority .= "</select>"; echo $priority; echoSpacer(); /*-------------END PRIORITY SELECT------------------*/ /*--------------------------------------------------*/ /*-----------GROUP SELECT BOX-----------------------*/ $group_rs = @mysql_select_db("group") or die(mysql_error()); $group_sql = "SELECT * FROM `group_name`"; $group_rs = @mysql_query($group_sql, $conn) or die(mysql_error()); $group = "<select name=\"group\">"; $group .= "<option selected value=\"\">-=Group=-</option>"; while($group_row = mysql_fetch_array($group_rs)) {   $group .= "<option value=\"".$group_row['rec_id']."\">".$group_row['name']."</option>"; } $group .= "</select>"; echo $group; echoSpacer(); /*-------------END GROUP SELECT--------------------*/ echo("<input type=\"hidden\" value=\"track\" name=\"hidden\" />"); echo("<input type=\"submit\" value=\"Find\">"); echo("</form>"); /*-------------------------------------------------*/ /*--------------START DISPLAY RESULTS--------------*/ $group = $_GET['group']; $priority = $_GET['priority']; $type = $_GET['type']; $rs = @mysql_select_db("project") or die(mysql_error()); if(isset($_GET['hidden'])) {   $sql = "SELECT * FROM `project_general` WHERE `group`=\"$group\" OR `priority`=\"$priority\"     OR `type` =\"$type\" ORDER BY `rec_num` ASC"; } else {   $sql = "SELECT * FROM `project_general` ORDER BY `rec_num` ASC"; } $result = "<table cellpadding=\"4\" border=\"1\">"; $result .= "<tr><th>Manager</th><th>Name</th><th>Start Date</th><th>End Date</th><th>Finish Date</th> <th>Amount</th><th>Notes</th></tr>"; $rs = @mysql_query($sql, $conn) or die(mysql_error()); while($row = mysql_fetch_array($rs)) {   $result .= "<tr><td>".$row['manager']."</td><td>".$row['name']."</td>";   $result .= "<td>".$row['start_date']."</td>";   $result .= "<td>".$row['end_date']."</td>";   $result .= "<td>".$row['finish_date']."</td>";   $result .= "<td>".$row['amount']."</td>";   $result .= "<td>".$row['notes']."</td>";   $result .= "</tr>"; } $result .= "</table>"; echo $result; ?> [/code] my only problem is that when a user only selects one category, all of my values are set to null, and this doesn't match the where clause in the query, so i get no results, even though the condition the user selected matched one of the results. please help.
  14. this is really an inefficient and unsecure way to go about an authentication script use a database, trust me you'll enjoy it much more all you have to do is query up a row that matches your user's user and pass input if one exists, then the user is authenticated if one doesn't then the user isn't
  15. I agree w/ober smartftp will serve any purpose you really use it for. i use it to upload to my server AND to hack my xbox  ;D
  16. once you have the query in a variable like say, $rs, do this: [code] <?php while($row = mysql_fetch_array($rs)){   $msg .= "the format for each individual row's data here";   $msg .= "using the array we just called like so";   $msg .= "Comment Posted by ".$row['name'];   $msg .= "or whatever column name you're using, for whatever"; } //after you've done that just echo $msg echo $msg; ?> [/code]
  17. Alright so now you know how to display the data, once it's in the table. but how do you put data into the table? very simple. [code] <?php //here we'll create the variables based on the post values from the form   $name = $_POST['name'];   $body = $_POST['body']; //now the timestamp will be different; we'll use the date() function to make a string of the date //that will be entered into the database, all nice and formatted.   $timestamp = date("F j, Y"); //now do all the connection stuff we did in the last script   $conn = @mysql_connect("localhost", "username", "password") or die("Connection Error");   $rs = @mysql_select_db("database_name") or die("DB Selection Error"); //now the sql we write will be different, we'll use an INSERT INTO query //we'll use the variables from above to insert the data from the form into the db   $sql = "INSERT INTO `comments` (name, body, timestamp) VALUES(     '$name',     '$body',     '$timestamp'     )"; /* now since this form's action is itself, we dont want to execute a query that has empty values, so we'll make sure the post values are set before we do anything */   if(isset($name) && isset($body)){     @mysql_query($sql, $conn) or die(mysql_error()); //send user back to see comment they just posted   header("location:show_comments.php"); } //set the $self variable to give our form an action $self = $_SERVER['PHP_SELF']; //write the form in HTML ?> <form method="post" action="<?php echo $self; ?>"> Your Name:  <input type="text" name="name" /><br /> Comment<br /> <textarea rows="10" cols="25"></textarea><br /> <input type="submit" value="Post Comment" /> </form> [/code] that should get you started.
  18. okay, this is what I'll show you. okay first, if you have phpMyAdmin, go in and execute the following query: [code] CREATE TABLE `comments` ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR NOT NULL, body TEXT NOT NULL, timestamp VARCHAR NOT NULL ) [/code] then, open a text or php editor and start something like this: [code] <?php /* alright, so now use the mysql_connect() function to make a resource link to your database arguments are: mysql_connect("server", "username", "password") also, the @ sign is so that php does not show an error, allowing us to show custom errors if we so desire by using "or die()" */ $conn = @mysql_connect("localhost", "username", "password") or die("Connection Error"); /* now, you need to select a database you should have already created this db in phpMyAdmin again use the @ sign to avert long annoying error messages */ $rs = @mysql_select_db("database_name_here") or die("DB Selection Error"); /* now for the MySQL query. this is the heart of the script that actually selects the data from the database so you can use it on your comments page. note that in this case, at the end of the query, the LIMIT can be set to however many comments you want to be displayed at once.  also the ORDER BY `id` DESC makes it so that the newest comments are shown at the top. */ $sql = "SELECT * FROM `comments` ORDER BY `id` DESC LIMIT 5"; /* now that you have everything else you need, execute the query, but in a variable. note that you're reassigning the mysql_select_db variable, because the db has already been selected */ $rs = @mysql_query($sql, $conn) or die(mysql_error()); /* now for the part your user see's: the data as an array. since you want a list of these comments, the data will be echoed inside a while loop */ while($row = mysql_fetch_array($rs)){ //this is where you can format how each comment is shown on the page $msg .= "<p>".$row['body']."</p>"; $msg .= "<p><i>Posted by ".$row['name']." on ".$row['timestamp']."</i></p>"; $msg .= "<hr width=\"100%\" />"; } //after you've looped through the array, echo what results echo $msg; //this is basically how you can show a list of row data in mysql through PHP. ?> [/code] now that code, coupled with the mysql query i gave you to create the table, should show the data in the table, after you insert some, which I'll show you in my next post to make the query work, make sure where it says "localhost", "username", "password" inside the connect resource link that you replace that with your host, (usually just localhost, but sometimes different) your username, and your password for your MySQL server.
  19. Well, I sort of get what you're saying, but not really; so I'll show you how I do it sometimes. this is the file that lists the rows with links to edit/delete them [code] <?php //connect and stuff $conn = @mysql_connect("server", "user", "pass") or die(mysql_error()); $rs = @mysql_select_db("database") or die(mysql_error()); //write sql $sql = "SELECT * FROM `table` ORDER BY `id` DESC"; //execute the sql query $rs = @mysql_query($sql, $conn) or die(mysql_error()); //prepare table to echo data $msg = "<table cellspacing=\"0\" cellpadding=\"3\" border=\"1\">"; $msg .= "<h3>Row Information</h3>"; //loop thru the array to echo the data in table rows while($row = mysql_fetch_array($rs)){ $msg .= "<tr><td>".$row['field_name']."</td>"; $msg .= "<td><a href=\"delete.php?id=".$row['id']."\">Delete Row</a>"; $msg .= " <a href=\"edit.php?id=".$row['id']."\">Edit Row</a>"; $msg .= "</td></tr>"; } $msg .= "</table>"; echo $msg; ?> [/code] then, as far as deleting a row, follow this kind of layout for delete.php; remember we passed a get value with the id of the row we want to delete by clicking on the link generated by our loop [code] <?php //delete.php //this is important; this is the GET value passed from the link which will //tell us which row to delete in the SQL $id = $_GET['id']; $conn = @mysql_connect("server", "user", "pass") or die(mysql_error()); $rs = @mysql_select_db("database") or die(mysql_error()); //write deleting query $sql = "DELETE FROM `table` WHERE `id`=\"$id\" LIMIT 1; //execute query @mysql_query($sql, $conn) or die(mysql_error()); ?> [/code] come back l8r for the edit code; i have to go pick someone up @ the airport
  20. also put your connection in a variable so you can use it as a resource link in your queries, it helps sometimes. (just a backup I'm saying) like $conn = @mysql_connect("server", "user", "pass") or die(mysql_error()); then when you need to execute a query: @mysql_query("sql here", $conn); you just use it as the second argument.
  21. no, it wouldn't mean having to change the database field as a string.... it's simple, just make it a string in PHP, say a variable, then just put the variable into  your INSERT INTO query
  22. well, this all depends on your preferences if you want to use MySQL, it's an entirely different approach than say if you wanted to just store the comments in a text file. I would suggest the latter if you don't have a MySQL server with a user and pass, and at least one database.
  23. okay first of all get the row value  into an array echo what you need into a textarea then in the action file of that form, say something like UPDATE `table` SET `field1`='$field_new_text', `field2`='$otherfield_new_text' to delete it, list all of your row data out (assuming you know how to do this already) and have a link similar to this: delete.php?id=$row['id'] then, on the next file (delete.php), create a get variable, $id = $_GET['id']; the SQL should look like DELETE FROM `table` WHERE `id`="$id" LIMIT 1 and that should get you started. if you need code examples say so
×
×
  • 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.