Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts

    get catagory and extra feild and insert into DB

    hi guys, basically, what I have is a help desk system, its got javascript in it to change feilds and select different radio buttons, my question is, as the extra feilds change depending on the catagory the user chooses, what would be the best way to add that extra feild to the database, as i dont think it would be very benificial to create a lot of different coloumns for each extra feild, and I think that would be a lot of coding just to insert it into the database, I will post the actual code for the system below and you can veiw a live html/javascript display page of it at the link listed below the code.

    PHP Code:
    <td width=99background="http://www.bootleggers.us/game-new/site/innerbg.gif" bgcolor="#222222" valign=top>
    <
    br>
    <
    center>
    <
    table border="0" cellspacing="0" cellpadding="10" width="100%" class="cat">
    <
    tr>
    <
    td>
    <
    p style="font-size: 4pt;">&nbsp;</p>
    <
    table border=0 cellpadding=2 cellspacing=0 width=75align=center>
    <
    tr>
    <
    td width=52valign=top class="insideTables">
    <
    form action="/helpdesk.php" method=POST>
    <
    table border=1 cellpadding=2 cellspacing=0 width=100bordercolor=black class=sub2 align=center>
    <
    tr>
    <
    td colspan=class=header>Create a help ticket</td>
    </
    tr>
    <
    tr>
    <
    td style="width: 30%;">Category:</td>
    <
    td style="width: 70%;"><select name=cat id=selCat style="width: 100%;" onChange="document.getElementById('td_1').innerHTML=(null==topic[document.getElementById('selCat').value]['1']?'Field 1':topic[document.getElementById('selCat').value]['1'])+':'; document.getElementById('tr_1').style.display=(null==topic[document.getElementById('selCat').value]['1']?'none':(document.all?'':'table-row')); document.getElementById('td_2').innerHTML=(null==topic[document.getElementById('selCat').value]['2']?'Field 2':topic[document.getElementById('selCat').value]['2'])+':'; document.getElementById('tr_2').style.display=(null==topic[document.getElementById('selCat').value]['2']?'none':(document.all?'':'table-row')); document.getElementById('td_3').innerHTML=(null==topic[document.getElementById('selCat').value]['3']?'Field 3':topic[document.getElementById('selCat').value]['3'])+':'; document.getElementById('tr_3').style.display=(null==topic[document.getElementById('selCat').value]['3']?'none':(document.all?'':'table-row')); document.getElementById('tr_3a').style.display=(null==topic[document.getElementById('selCat').value]['3']?'none':(document.all?'':'table-row')); if (document.getElementById('selCat').value == 0) { document.getElementById('data_4a').disabled=false; document.getElementById('data_4a').checked=true; document.getElementById('tr_4').style.display='none'; }; if (topic[document.getElementById('selCat').value]['0'] > 0) { document.getElementById('data_4b').checked=true; document.getElementById('data_4a').disabled=true; document.getElementById('tr_4').style.display=(document.all?'':'table-row'); }; if (topic[document.getElementById('selCat').value]['0'] == 0) { document.getElementById('data_4a').disabled=false; document.getElementById('data_4a').checked=true; document.getElementById('tr_4').style.display=(document.all?'':'table-row'); }; return true;"><option value=0 id=opt_0 selected>--- Choose category ---</option><option value=6 id=opt_6>Arm Wrestling</option><option value=4 id=opt_4>Auto Burglary</option><option value=10 id=opt_10>Bank</option><option value=27 id=opt_27>Bootleggers Bootcast</option><option value=9 id=opt_9>Bootleggers Buzz</option><option value=16 id=opt_16>Bootlegging Booze Runs</option><option value=2 id=opt_2>Casino Poker</option><option value=24 id=opt_24>Crew Issues</option><option value=3 id=opt_3>Crimes</option><option value=25 id=opt_25>Escrow</option><option value=29 id=opt_29>Establishment</option><option value=15 id=opt_15>Feature Suggestion</option><option value=23 id=opt_23>Forums</option><option value=7 id=opt_7>General Game Play</option><option value=26 id=opt_26>Hacked!</option><option value=13 id=opt_13>Help Desk</option><option value=8 id=opt_8>Jail</option><option value=12 id=opt_12>Missions</option><option value=1 id=opt_1>Organized Crime</option><option value=17 id=opt_17>Other Miscellaneous</option><option value=28 id=opt_28>Photo Album</option><option value=14 id=opt_14>Points Purchase</option><option value=30 id=opt_30>Problem with Staff HDO</option><option value=20 id=opt_20>Report a Dupe</option><option value=21 id=opt_21>Report Bug Glitch</option><option value=22 id=opt_22>Report Exploit Cheat</option><option value=19 id=opt_19>Report Forum Infraction</option><option value=11 id=opt_11>Report TOS Violation</option><option value=5 id=opt_5>Stock Market</option><option value=18 id=opt_18>TOS Rules Question</option></select></td>
    </
    tr>
    <
    tr id=tr_1 style="display: none;">
    <
    td id=td_1 style="vertical-align: top; white-space: nowrap;">Field 1</td>
    <
    td><input type=text name=data_1 style="width: 100%;" value=""></td>
    </
    tr>
    <
    tr id=tr_2 style="display: none;"><td id=td_2 style="vertical-align: top; white-space: nowrap;">Field 2</td><td><input type=text name=data_2 style="width: 100%;" value=""></td></tr>
    <
    tr id=tr_3 style="display: none;"><td colspan=2 id=td_3 style="vertical-align: top; white-space: nowrap;">Field 3</td></tr>
    <
    tr id=tr_3a style="display: none;"><td colspan=2 style="vertical-align: top; white-space: nowrap;"><textarea name=data_3 style="width: 100%; height: 200px;"></textarea></td></tr>
    <
    tr id=tr_4 style="display: none;"><td><input type=radio name=data_4 id=data_4a value=0 checked> <label for=data_4a>Let HDOs help</label><br><input type=radio name=data_4 id=data_4b value=1>  <label for=data_4b>Elite Guard only</label></td><td align=right><input type=submit value="Submit ticket!"></td></tr>
    </
    table></span>
    <
    script type="text/javascript">
    var 
    topic = new Array();
     
    topic['0']=new Array();
     
    topic['0']['0']=0;
     
    topic['0']['1']=null;
     
    topic['0']['2']=null;
     
    topic['0']['3']=null;
     
    topic['6']=new Array();
     
    topic['6']['0']=0;
     
    topic['6']['1']=null;
     
    topic['6']['2']='Level';
     
    topic['6']['3']='Question';
     
    topic['4']=new Array();
     
    topic['4']['0']=0;
     
    topic['4']['1']=null;
     
    topic['4']['2']='Plate';
     
    topic['4']['3']='Question';
     
    topic['10']=new Array();
     
    topic['10']['0']=0;
     
    topic['10']['1']=null;
     
    topic['10']['2']=null;
     
    topic['10']['3']='Question';
     
    topic['27']=new Array();
     
    topic['27']['0']=0;
     
    topic['27']['1']=null;
     
    topic['27']['2']=null;
     
    topic['27']['3']='Question';
     
    topic['9']=new Array();
     
    topic['9']['0']=0;
     
    topic['9']['1']='Issue';
     
    topic['9']['2']=null;
     
    topic['9']['3']='Question';
     
    topic['16']=new Array();
     
    topic['16']['0']=0;
     
    topic['16']['1']=null;
     
    topic['16']['2']=null;
     
    topic['16']['3']='Question';
     
    topic['2']=new Array();
     
    topic['2']['0']=0;
     
    topic['2']['1']=null;
     
    topic['2']['2']=null;
     
    topic['2']['3']='Question';
     
    topic['24']=new Array();
     
    topic['24']['0']=0;
     
    topic['24']['1']=null;
     
    topic['24']['2']='Crew';
     
    topic['24']['3']='Question';
     
    topic['3']=new Array();
     
    topic['3']['0']=0;
     
    topic['3']['1']=null;
     
    topic['3']['2']=null;
     
    topic['3']['3']='Question';
     
    topic['25']=new Array();
     
    topic['25']['0']=0;
     
    topic['25']['1']=null;
     
    topic['25']['2']=null;
     
    topic['25']['3']='Question';
     
    topic['29']=new Array();
     
    topic['29']['0']=0;
     
    topic['29']['1']=null;
     
    topic['29']['2']='State';
     
    topic['29']['3']='Question';
     
    topic['15']=new Array();
     
    topic['15']['0']=1;
     
    topic['15']['1']=null;
     
    topic['15']['2']='Feature';
     
    topic['15']['3']='Suggestion';
     
    topic['23']=new Array();
     
    topic['23']['0']=0;
     
    topic['23']['1']=null;
     
    topic['23']['2']='Forum';
     
    topic['23']['3']='Question';
     
    topic['7']=new Array();
     
    topic['7']['0']=0;
     
    topic['7']['1']=null;
     
    topic['7']['2']=null;
     
    topic['7']['3']='Question';
     
    topic['26']=new Array();
     
    topic['26']['0']=1;
     
    topic['26']['1']=null;
     
    topic['26']['2']='Who hacked you?';
     
    topic['26']['3']='Information';
     
    topic['13']=new Array();
     
    topic['13']['0']=0;
     
    topic['13']['1']=null;
     
    topic['13']['2']=null;
     
    topic['13']['3']='Question';
     
    topic['8']=new Array();
     
    topic['8']['0']=0;
     
    topic['8']['1']=null;
     
    topic['8']['2']='State';
     
    topic['8']['3']='Question';
     
    topic['12']=new Array();
     
    topic['12']['0']=0;
     
    topic['12']['1']='Mission';
     
    topic['12']['2']=null;
     
    topic['12']['3']='Question';
     
    topic['1']=new Array();
     
    topic['1']['0']=0;
     
    topic['1']['1']=null;
     
    topic['1']['2']=null;
     
    topic['1']['3']='Question';
     
    topic['17']=new Array();
     
    topic['17']['0']=0;
     
    topic['17']['1']=null;
     
    topic['17']['2']='Feature';
     
    topic['17']['3']='Question';
     
    topic['28']=new Array();
     
    topic['28']['0']=0;
     
    topic['28']['1']=null;
     
    topic['28']['2']=null;
     
    topic['28']['3']='Question';
     
    topic['14']=new Array();
     
    topic['14']['0']=5;
     
    topic['14']['1']=null;
     
    topic['14']['2']='Tranction ID';
     
    topic['14']['3']='Question';
     
    topic['30']=new Array();
     
    topic['30']['0']=4;
     
    topic['30']['1']=null;
     
    topic['30']['2']='Admin/Mod/HDO Name';
     
    topic['30']['3']='Information';
     
    topic['20']=new Array();
     
    topic['20']['0']=1;
     
    topic['20']['1']=null;
     
    topic['20']['2']='Username';
     
    topic['20']['3']='Information';
     
    topic['21']=new Array();
     
    topic['21']['0']=1;
     
    topic['21']['1']=null;
     
    topic['21']['2']='Feature/Page';
     
    topic['21']['3']='Information';
     
    topic['22']=new Array();
     
    topic['22']['0']=1;
     
    topic['22']['1']=null;
     
    topic['22']['2']='Feature/Page';
     
    topic['22']['3']='Information';
     
    topic['19']=new Array();
     
    topic['19']['0']=0;
     
    topic['19']['1']='Username';
     
    topic['19']['2']='Link to Topic';
     
    topic['19']['3']='Information';
     
    topic['11']=new Array();
     
    topic['11']['0']=1;
     
    topic['11']['1']=null;
     
    topic['11']['2']='Username';
     
    topic['11']['3']='Information';
     
    topic['5']=new Array();
     
    topic['5']['0']=0;
     
    topic['5']['1']=null;
     
    topic['5']['2']='Company';
     
    topic['5']['3']='Question';
     
    topic['18']=new Array();
     
    topic['18']['0']=0;
     
    topic['18']['1']=null;
     
    topic['18']['2']=null;
     
    topic['18']['3']='Question';
     
    </script>
     </form>


    </td>
    <td width=3%>&nbsp;</td><td width=45% valign=top class="insideTables"><table border=1 cellpadding=2 cellspacing=0 width=100% bordercolor=black class=sub2 align=center><tr><td colspan=3 class=header>Help Desk Operators</td></tr></table></td></tr></table></span>

    </tr>
    </table>
    </td> 
    http://crimewave.360-tactics.co.uk/hdtest.php

    if you look at the link, and change the drop down box, it will display new feilds, whats the best way to place them into a database, instead of in different coloumns?

    cheers guys
    Last edited by Dan13071992; 01-28-2012 at 05:08 PM.
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #2
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    0
    Thanked 1 Time in 1 Post
    Hi Dan,

    You are correct, storing this all in 1 column as a pose to multiple columns is a much better idea.

    I'd use the function called "implode". Have a look at php.net/implode

    Basically, you'll be able to assign each piece of data to an array.

    PHP Code:
    $array = ('Hacked''Who Hacked You?');
    $data implode(',' $array); 
    You then store $data in your column.

    When you want to access the data, use another function called "explode". php.net/explode

    PHP Code:
    $array explode(',' $data);
    $array[0] = 'Hacked;'
    $array[1] = 'Who Hacked You'
    That's the way i'd do it anyway :-)

  • #3
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    that sounds like a good idea, however how would i collect each different part to put it into the array?
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #4
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    0
    Thanked 1 Time in 1 Post
    Hi Dan,

    You just use the name of the each form area.

    e.g
    main = Hacked
    sub = Who Hacked You?

    Pass the data through to your handling page, and then combine them.

    PHP Code:
    $main mysql_escape_string(strip_tags($_POST['main']));
    $sub mysql_escape_string(strip_tags($_POST['sub']));

    $array $main .= ',' $sub// This creates our array of data and seperates each bit with a comma "," 
    Then just insert $array in to your db column.

    If you use this method you will not need "Implode". You can still use "Explode" when you want to get the data back out of the db.

  • #5
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    ok, so far ive got this:

    PHP Code:
    if (strip_tags($_POST['submitticket'])){
    $cat mysql_escape_string(strip_tags($_POST['cat']));
    $data1 mysql_escape_string(strip_tags($_POST['data_1']));
    $data2 mysql_escape_string(strip_tags($_POST['data_2']));
    $data3 mysql_escape_string(strip_tags($_POST['data_3']));
    $data4 mysql_escape_string(strip_tags($_POST['data_4']));

    $array $cat .= ',' $data1 .= ',' $data2 .= ',' $data3 .= ',' $data4;

    echo 
    "$array";

    this gives me the results:

    Code:
    19,Bob,topic id is 1,in forum 1,0
    19 = id number of to catagory
    bob = name i put in data1
    topic id is 1 = input into data2
    in forum 1 = input into data3
    0 = data4 input, however this wont be in this array as i will have a seperate coloumn for this in the db.


    my problem, is how can i change it so that it lists the feild instead of the id from the coding ive got?

    or a better way, (i think) would be collecting this part:

    PHP Code:
    <select name=cat id=selCat 
    how do i collect the id that is selected? because using name=cat, i can call the cat as $cat above, and that just gives me an id number, so i was wondering if i could actually collect the selCat instead?
    Last edited by Dan13071992; 01-28-2012 at 03:04 PM.
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #6
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    0
    Thanked 1 Time in 1 Post
    Hi Dan,

    I might be wrong but i'm pretty sure you can't. Defining the "id" of an element within HTML is usually to either style it via CSS or for JavaScript purposes.

    If it were me doing it and i was using the code you have already written, i'd develop a little script include to find the name of the category based on the ID.

    Insert the ID (19) in your example, into the database as normal. When you want to pull data from the DB, just use something along the lines of following:

    PHP Code:
    if($catid == 19) {
       
    $catname 'nameofcategory';

    You'd need to write a new line for every ID you have in your Javascript. Save it as an external file and then just include it below your MYSQL query.

    It's a bit messy, but it will do what you want it to do.

    If further down the line you wanted to really clean up your code, i'd reprogram your support system with a small interface to add/edit/remove categories and subcategories. Each one would have an "id" and a "title" so they'd be no need for an external script to find out which one related to which ID when it was pulled from the DB.

    Just a thought anyway :-)

    ** Note, if i am wrong about pushing through the ID of a form element and the "name", can someone let me know!

  • #7
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    thanks ive got it all working now thanks for your help
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •