Jump to content

FoxRocks

Members
  • Posts

    45
  • Joined

  • Last visited

Posts posted by FoxRocks

  1. "basic debugging 101" , ok, I guess my error checking wasn't cutting it? I echo'd out everything you did, I just didn't label which line it was on.

     

    It's not that I don't appreciate getting helped in the right direction, or being taught how to troubleshoot instead of just being handed the answer...in fact I prefer that over just getting the answer...however the var_dump() and the "basic debugging 101" ideas didn't produce anything new that my already existing error checking didn't already have.

     

    Anyways, I've found the problem. It was a stupid one as I'm sure we all expected.

     

    Thanks for the help, I'm sorry if I sound unappreciative with my comment, don't take it personally.

     

    ~FOX~

     

    EDIT: I forgot to say what the problem was. I changed $date[$i] to just $date in the insert statement and it worked fine.

  2. OK, here is my form code, all of it, including the $_SESSION's. I've added some echo statements.

     

    <?php
    $_SESSION['tod_fromDate'] = "2013-01-01";
    $_SESSION['tod_toDate'] = "2013-01-01";
    $fromSTR = $_SESSION['tod_fromDate'];
    $toSTR = $_SESSION['tod_toDate'];
    $fromTIME = strtotime($fromSTR);
    $toTIME = strtotime($toSTR);
    $_SESSION['emp_id'] = "9078";
    $emp_id = $_SESSION['emp_id'];
    $tod_name = "Taken Days Off";
    $tod = 8;
    ?>
    <form method="post" action="">
    <table cellpadding="4" cellspacing="0" border="1" id="tod_tracking_form">
    <tr align="center">
    <td colspan="3"><?php echo $tod_name; ?> Tracking Form</td>
    </tr>
    <tr align="center">
    <td class="bold">Date Taken</td>
    <td class="bold">Notes</td>
    <td class="bold">Entered By</td>
    </tr>
    <?php
    for($i = $fromTIME; $i <= $toTIME; $i = strtotime('+1 day', $i))
    {
    echo "for i: " . $i . "<br>";//Error checking
    $adate = date('Y-m-d',$i);
    echo "for adate: " . $adate . "<br>";//Error checking
    $bdate = date('M jS Y',$i);
    echo "for bdate: " . $bdate . "<br>";//Error checking
    echo "<tr>";
    echo "<td align=\"center\"><input type=\"hidden\" name=\"tod_date[]\" value=\"" . $adate . "\">" . $bdate . "</td>";
    echo "<td><textarea name=\"tod_note[]\" style=\"resize:none;\" maxlength=\"255\" cols=\"25\" rows=\"3\"></textarea></td>";
    //Change the value below once the admin area has been created. Use the session admin id here.
    echo "<td align=\"center\"><input type=\"hidden\" name=\"tod_admin\" value=\"10845\">10845</td>";
    echo "</tr>";
    }
    ?>
    <tr align="center">
    <td colspan="3"><input type="submit" name="tod_submit" style="width:100px;" value="SUBMIT"></td>
    </tr>
    </table>
    </form>
    <?php
    if(isset($_POST['tod_submit']))
    {
    $tod_date = $_POST['tod_date'];
    $note = $_POST['tod_note'];
    $admin = $_POST['tod_admin'];
    $i = 0;
    
    foreach($tod_date as $date)
    {
    $sql = ("INSERT INTO tod_tracking (Emp_ID, TOD_Date, TOD_Note, TOD_Admin) VALUES ('$emp_id', '$date[$i]', '$note[$i]', '$admin')");
    echo "foreach i: " . $i . "<br>";//Error checking
    echo "foreach date[i]: " . $date[$i] . "<br>";//Error checking
    // if(!$result_sql = $mysqli->query($sql))
    // {
    // die ("There was a problem inserting the records into the tod_tracking table. mySQLI Error: " . $mysqli->error . "");
    // }
    echo "sql: " . $sql . "<br>";//Error checking
    
    $i++;
    }
    //unset($_SESSION['tod']);
    //redirect_to($url);
    }
    ?>
    

     

    Now, here is the page source once the code has run:

     

    <form method="post" action="">
    <table cellpadding="4" cellspacing="0" border="1" id="tod_tracking_form">
    <tr align="center">
    <td colspan="3">Taken Days Off Tracking Form</td>
    </tr>
    <tr align="center">
    <td class="bold">Date Taken</td>
    <td class="bold">Notes</td>
    <td class="bold">Entered By</td>
    </tr>
    for i: 1356998400<br>for adate: 2013-01-01<br>for bdate: Jan 1st 2013<br><tr><td align="center"><input type="hidden" name="tod_date[]" value="2013-01-01">Jan 1st 2013</td><td><textarea name="tod_note[]" style="resize:none;" maxlength="255" cols="25" rows="3"></textarea></td><td align="center"><input type="hidden" name="tod_admin" value="10845">10845</td></tr>
    <tr align="center">
    <td colspan="3"><input type="submit" name="tod_submit" style="width:100px;" value="SUBMIT"></td>
    </tr>
    </table>
    </form>
    foreach i: 0<br>foreach date[i]: 2<br>sql: INSERT INTO tod_tracking (Emp_ID, TOD_Date, TOD_Note, TOD_Admin) VALUES ('9078', '2', 'Here are the notes', '10845')<br>
    

     

    And finally, here is a screen shot of the form with the echo statements:

     

    post-130182-0-10780900-1357820271_thumb.png

     

    This makes NO sense to me, I can't believe I'm either missing something obvious, or that I can't get it to work...ugh.

  3. Thank you all for the replies.

     

    I should have included what the variable are set to, sorry.

     

    <?php
    $fromSTR = $_SESSION['tod_fromDate']; //Selected through the date picker
    $toSTR = $_SESSION['tod_toDate']; //Selected through the date picker. This is possibly the same value as $_SESSION['tod_fromDate']
    $fromTIME = strtotime($fromSTR);
    $toTIME = strtotime($toSTR);
    $emp_id = $_SESSION['emp_id']; //Set from the database
    ?>
    

     

    I have printed all of these out and they come out as expected:

     

    <?php
    $fromDate = 2013-01-01;
    $toDate = 2013-01-01;
    $emp_id = 9078;
    ?>
    

  4. Hi there,

     

    First, thank you for your interest in my problem, I appreciate your time.

     

    I have a small form that is populated with records from a mysql database using php. I have three <input>'s which have the name attribute set to an array in case there is more than one record. The problem I'm having is for some reason the $adate (which is === "2013-01-01") gets broken down into 10 parts of an array. I don't get it, I've used this exact same setup on 5 or 6 other pages and it doesn't do this.

     

    Just to be clear, when I echo out $date, it looks like this:

     

    $date[$i] = 2
    

     

    And when I run through it, it looks like this:

     

    $date[0] = 2
    $date[1] = 0
    $date[2] = 1
    $date[3] = 3
    $date[4] = -
    $date[5] = 0
    $date[6] = 1
    $date[7] = -
    $date[8] = 0
    $date[9] = 1
    

     

    What I'm expecting, and wanting, is this:

     

    $date[$i] = 2013-01-01
    

     

    Here is my form code:

     

    <form method="post" action="">
    <table cellpadding="4" cellspacing="0" border="1" id="wod_tracking_form">
    
    <tr align="center">
    <td colspan="3"><?php echo $wod_name; ?> Tracking Form</td>
    </tr>
    
    <tr align="center">
    <td class="bold">Date Worked</td>
    <td class="bold">Notes</td>
    <td class="bold">Entered By</td>
    </tr>
    
    <?php
    
    for($i = $fromTIME; $i <= $toTIME; $i = strtotime('+1 day', $i))
       {
       $adate = date('Y-m-d',$i);
       $bdate = date('M jS Y',$i);
       echo "<tr>";
       echo "<td align=\"center\"><input type=\"hidden\" name=\"wod_date[]\" value=\"" . $adate . "\">" . $bdate . "</td>";
       echo "<td><textarea name=\"wod_note[]\" style=\"resize:none;\" maxlength=\"255\" cols=\"25\" rows=\"3\"><textarea></td>";
       //Change the value below once the admin area has been created. Use the session admin id here.
       echo "<td align=\"center\"><input type=\"hidden\" name=\"wod_admin\" value=\"10845\">10845</td>";
       echo "</tr>";
       }
    
    ?>
    
    <tr align="center">
    <td colspan="3"><input type="submit" name="wod_submit" style="width:100px;" value="SUBMIT"></td>
    </tr>
    
    </table>
    </form>
    

     

    Here is my code for inserting it into the database:

     

    <?php
    if(isset($_POST['wod_submit']))
       {
       $wod_date = $_POST['wod_date'];
       $note = $_POST['wod_note'];
       $admin = $_POST['wod_admin'];
       $i = 0;
    
       foreach($wod_date as $date)
           {
           $sql = ("INSERT INTO wod_tracking (Emp_ID, WOD_Date, WOD_Note, WOD_Admin) VALUES ('$emp_id', '$date[$i]', '$note[$i]', '$admin')");
    
           if(!$result_sql = $mysqli->query($sql))
               {
               die ("There was a problem inserting the records into the wod_tracking table. mySQLI Error: " . $mysqli->error . "");
               }
    
           $i++;
           }
       die;
       //unset($_SESSION['wod']);
       //redirect_to($url);
       }
    ?>
    

     

    I don't know if this is because it's in a date format, or what, but it's causing me a lot of confusion, I would really appreciate some help on this one.

     

    Cheers!

    ~FOX~

  5. In case you're in the mood, I do have one other question. How would it work if I had a table that was reference by the "employee" table (not previously mentioned in my post) and I needed to get that info up to the "schedule" table? For example, the employees might have a drivers license of a certain class, so I've got a table called "license" that is linked to the "employee" table. The columns are called "Lic_ID" in both the "employee" table and the "license" table.

     

    Does that make sense? Hopefully.

     

    I want to be able to show the "license" class of the "employee" on the "schedule".

     

    Cheers,

     

    ~FOX~

  6. Funny, I was just coming back to let you know I found some answers and I see you've already replied! I was able to figure out the answer to if $row['Area_Name'] would work, and it does...brilliant!

    I hadn't found the answer to the other part about the alias, I'll have to do some more reading obviously, but thank you for that.

     

    In short, you were a huge help and I really appreciate it. Thank you so much!!

     

    ~FOX~

  7. Hi gristoi,

     

    Thank you for the reply, and for the example. So with the example you gave, would I call out the parameters as normal? Meaning, would

    $row['Area_Name']

    work? Also, I don't really understand everything you wrote, specifically, what is "schedule s" and "area a" all about?

     

    While I wait for a reply, I'll go and read up some more on JOINS to see if I can answer my own question :)

     

    Cheers!

     

    ~FOX~

  8. Good day,

     

    First, thank you for taking the time to look at my post, I appreciate it and I will try not to waste your time.

     

    I have recently been challenged to make an employee management database. I have some experience using mySQL and PHP and consider myself "comfortable" with how it works. This is however the first time I've used a relational db for anything. I am having a hard time getting my head around how it's all going to come together in the end, so I'm hoping that you can fill in some blanks for me and help me see the light, so to speak.

     

    Right now I have my tables set up and the primary and foreign keys set up in a database. This is the "schedule" :

     

    post-130182-0-55839700-1352984468_thumb.png

     

    And in the interest of keeping the post short, I'll include just on of the referenced tables, that is "area" :

     

    post-130182-0-66940200-1352984480_thumb.png

     

    So as you can see I've referenced the Area_ID in the schedule table and that is because I want to be able to assign an employee to a work area in the shop.

     

    Here is a screen shot of one record in the schedule table:

     

    post-130182-0-56127700-1352984487_thumb.png

     

    So as I mentioned I am having trouble seeing how it all comes together. Specifically I am having trouble seeing how "Area ID - 6" is going to translate into "Area_Name - Paint Shop" (record #6 = Paint Shop).

     

    Normally when I query the db for the information, I would do something like:

     

    $result = mysql_query("SELECT * FROM schedule");

     

    And then from there I would usually do something like:

     

    while($row = mysql_fetch_array($result))
    {
    echo "<tr>";
    echo "<td>" . $row['Emp_ID'] . "</td>";
    echo "<td>" . $row['Cal_Date'] . "</td>";
    echo "<td>" . $row['Area_ID'] . "</td>";
    echo "<td>" . $row['Shift_ID'] . "</td>";
    echo "<td>" . $row['Stat_ID'] . "</td>";
    echo "</tr>";
    }
    

     

    But in this case instead of "Paint Shop" I would, obviously get "6". This is my brick wall that I can't seem to get my head around. I have been reading about JOINS and still, for some reason, I just can't put two and two together.

     

    I would really appreciate any help and or constructive criticism you can give.

     

    Cheers,

     

    ~FOX~

  9. White_Lily,

     

    Thanks, that makes sense now, and after rereading what PFMaBiSmAd said, I see what he means.

     

    Do you happen to have a Live CMS model running that I could see? I hope that's not out of line to ask. The reason I ask is that I'm interested to know what the industry best practices are for managing content. I have a mixed bag of ideas in my head and I'm sure I'm missing some things that I should have. I apologize if I'm out of line.

     

    Cheers,

     

    ~FOX~

  10. Hi,

     

    I just wanted to drop in real quick to let you all know that I have seen the replies, but I've been busy at my day job and haven't had time to work on this.

     

    Also, in reply to PFMaBiSmAd, wouldn't that just make the database grow and grow and grow over time? I didn't really consider that option because I figured that would just make everything slow down.

     

    Thank you all for the replies, I hope to get to work on this very soon!

     

    Cheers,

     

    ~FOX~

  11. Hello,

     

    Thank you for taking a look at my question.

     

    I have a question about managing database entries with respect to a content management system. I am currently using one solution that I believe is a terrible way to handle things and my hope here is to find a better, more professional way to do things.

     

    So far I have tried different ways of coding a solution, but every time I just get a bunch of gibberish that doesn't make any sense. I've also tried to look for answers on the web, but I've had no luck, I suspect I don't know how to word my question properly.

     

    Anyways, let me explain what it is I am trying to accomplish.

     

    I have a Staff Page on a website that displays information for each staff member. Each entry includes a photo, biography and work location for each member. This information is stored in a MySQL database and is displayed on the web page using php.

     

    I want to be able to list all of the entries from the database and then choose which ones to delete or update as well as have the option to add a new staff member.

     

    Currently this is what I'm doing:

     

    On the CMS side of things I have an html form that has one section for each staff member (8 employees = 8 sections) that is populated with the entries in the database. To update any information I just edit the page and when I click submit, it updates the database.

     

    Now you know why I called it a terrible solution.

     

    To date this method has "done the trick" because I am the one managing all of the entries. If there is a new employee I just add another section to the page, or if an employee leaves I just clear the entry and hit submit. The main problem is that none of my customers could ever manage this part of their website, which prevents me from giving them a proper content management system.

     

    Right now I feel like I have all the pieces to the puzzle, but I just don't know how to put them all together.

     

    I would really appreciate some help with two things:

     

    1) Some direction to get me started on a solution, I like to work through things on my own as much as possible, I learn more that way.

     

    2) Help with wording the title of this thread properly, I like to try and make it so it's not misleading and also if someone has the same problem later on, they can find a solution.

     

    Thank you for your time,

     

    ~FOX~

  12. Oh, how very cool! The str_replace function did exactly what I wanted it to, thank you so much for helping me get pointed into the right direction.

     

    Here is what I did:

     

    $contact_link = "<a href=\"/contact-us/\" class=\"inline\" target=\"_parent\">Contact Us</a>";
    $answer = str_replace(array("contact us","Contact Us","Contact us") , array($contact_link , $contact_link , $contact_link), $row['answer']);
    echo "<td>" . $answer . "</td>";
    

     

    ...and it works just exactly as I had imagined it, I am so happy :)

     

    I would be interested to know if there is anything I missed, or if there is a cleaner way to run this...maybe in a function? Hmmm...I just thought of the function idea as I typed this, maybe I'll go work on that one next.

     

    Thanks again everyone, I appreciate the help!

     

    ~FOX~

     

    (not going to mark solved until I make sure it's complete)

  13. Hey! Thank you all so much, I appreciate you taking the time to reply!

     

    I re-read my question and I don't think I explained myself very well, I remember being sort of fragmented at the time I wrote it. I think the str_replace function might be the ticket (magic) I was looking for, but I want to try to re-write the question again so I can make sure I'm being clear with what I'm trying to do. So...

     

    Let's say I've got a web page for Frequently Asked Questions that I want to allow my customer to add new FAQ's to. With that in mind, I've made a CMS form that inserts new data into the database. The FAQ page then queries that database and prints the information out accordingly.

     

    So far so good, easy peasy.

     

    So let's say my customer, through the CMS form, inserts this text into the database:

     

    "Yes, we can do that, please Contact Us for a quote."

     

    What I want to do is make it so when the FAQ page queries the database, and prints out the text above, it replaces the words "Contact Us" with <a href="/contact-us/">Contact Us</a>. So it creates a link to the contact page without my customer having to enter any html into the CMS form.

     

    There, I think that sounds a lot better. However I do believe the str_replace function will be the answer I was looking for, so I'm going to go and give that a try.

     

    Thanks again for the help :)

     

    ~FOX~

  14. Hello,

     

    First, I'm sorry my title probably doesn't make sense, I couldn't think of a better way to put it.

     

    Basically I came up with an idea in my head that I now want to make happen. Here it is.

     

    Let's say I enter some data into a database table using a regular html form, for example like the text below:

     

    Here is some text, for more information, Contact Us!
    

     

    What I want to do is somehow (magic?) make it so when I retrieve this same text out of the database, it makes Contact Us into a link to the contact page.

     

    Crazy, right?

     

    I know, I just thought it would be really cool if when my customer adds another item to their websites FAQ page, that any time they say "Contact Us" it would display as a link to their contact page.

     

    Thoughts?

     

    ~FOX~

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