Jump to content

Strangen

New Members
  • Posts

    6
  • Joined

  • Last visited

Everything posted by Strangen

  1. Thank you so much for the help mac_gyver! I really appreciate your input. I will give it a try and post back if I run into any other trouble!
  2. Hi Guys, I am currently working on a simple project for myself and I am a bit stuck. I've searched google for days and can not get a straight answer. I am setting up a sort of roster site where I manually add members (no user accounts, just for statistics) and I want to be able to add stats to those members. I've got everything else pretty much setup, but I am having trouble figuring out checkboxes. When I add a member I want to be able to select multiple "divisions" for the member. These will be listed on the stats page, and I want each of them to be listed. So down to the actual issue I am having. I have (for the time being, will be adding upto 50) 4 divisions, on the form I have the division name with a checkbox beside it to add/remove this member from that division. I have two tables setup in my database. I have one table for the member and their profile or stats. The other table I setup for the actual division names/description. The purpose for setting up two tables was because I've setup another script to add more divisions and descriptions. My page to add a division to a certain member acts in the following manner: link contains the member id, and page uses GET to serach the member by ID. The form on this page will UPDATE the MEMBER where ID is $_GET['ID'] So I have two queries going at this time, one to get the member's id to update, and another to list all the available divisions and list them in a table with a checkbox for each. All this works fine, my problem is getting the checkbox values. I want to be able to store and update this data in the members table. The best way I can figure to do this is to store an integer corresponding to the ID number in the division table. So is there a way that each checkbox would have a value and these values are stored in an array on a single column of the members table? And then how would I go about checking for this value on each checkbox using the WHILE function? Here is the code I have so far (I am still new at PHP so I know there is probably syntax errors) <?php if(isset($_POST['update'])) { include "dbinfo.php"; $id = $_POST['id']; $sql = "UPDATE members SET WHERE id=$id"; $retval = mysql_query( $sql ); if(! $retval ) { die('Could not update data: ' . mysql_error()); } echo "Updated data successfully\n"; mysql_close($db); } else { ?> <?php include "dbinfo.php"; $id=$_GET['id']; $query = "SELECT * FROM members WHERE id='$id'"; $result = mysql_query($query); if($result === FALSE) { die(mysql_error()); } $record = mysql_fetch_array($result); $query2 = "SELECT * FROM divisions"; $result2 = mysql_query($query2); if($result2 === FALSE) { die(mysql_error()); } ?> <h3>Updating divions for member: <?php echo $record ['member'];?></h3> user's id: <?php echo $record ['id'];?> <br> <form method="post" action="<?php $_PHP_SELF ?>"> <table width="60%" border="1" align="left"> <th width="5%">id</th><th width="45%">division</th><th width="45%">image</th><th width="5%">status</th> <?PHP while ($record2 = mysql_fetch_array($result2)){ echo "<tr><td>" . $record2 ['id'] . "</td>"; echo "<td>" . $record2 ['divname'] . "</td>"; echo "<td>" . $record2 ['divimg'] . "</td>"; echo '<td><input type="checkbox" name="' . $record2 ['divname'] . '" id="' . $record2 ['divname'] . '" value="' . $divstatus . '" /></td>'; echo '</tr>'; ///$divstatus will be my checked/unchecked value once I figure out how to fetch this }?> </table> <input name="update" type="submit" id="update" value="Update"> </form> <?php } ///End Else ?> Any help you could give would be much appreciated. Thank you for your time reading all of this!
  3. Hey guys, I am a distributor for a parts company and I am looking to start a site for dealers to re-order products. I only have maybe 10 products so I planned on using a ecommerce script. The only thing is that I don't want the prices to be open to the public (or easily found via hacking) I started using some free e-commerce scripts, but I can't find any plugins that are made already for this purpose and I am having a hard time finding it on google. So pretty much I just want to have an ecommerce site where you have to be a member to either see the site or see the prices, and I want to manually create accounts so that I can better control the site. I am looking for something fairly cheap or free. Would prefer to use Wordpress but I can't find a plugin Does anyone have any suggestions?
  4. Thank you for you help! I will give this a try. I am still learning. Also the table does continue and I am running queries from other tables, but the code is not as a big of a mess as the code i posted here (Well atleast in my opinion) This is just a simple script for personal offline use only so I am not too worried about my code being a little screwy, but I did want it easier to read. So thanks again for your help!
  5. Thanks for the quick reply. Ok I only have 4 values in that table, which I plan to keep only 4 at all times. So if I use the first query you provided how do I echo the value for each of the categories? I would like to keep $cat1,$cat2,$cat3, and $cat4 as my category variables
  6. I am new to PHP and was wondering what I could do to cleanup my code? Seems like I have a lot of unecessary code. <?php include "dbinfo.php"; $sql1 = "SELECT `category` FROM `categories` WHERE `id`=1"; $sql2 = "SELECT `category` FROM `categories` WHERE `id`=2"; $sql3 = "SELECT `category` FROM `categories` WHERE `id`=3"; $sql4 = "SELECT `category` FROM `categories` WHERE `id`=4"; $catid1 = mysql_query($sql1,$db); $catid2 = mysql_query($sql2,$db); $catid3 = mysql_query($sql3,$db); $catid4 = mysql_query($sql4,$db); $row1 = mysql_fetch_array($catid1); $cat1 = $row1['category']; $row2 = mysql_fetch_array($catid2); $cat2 = $row2['category']; $row3 = mysql_fetch_array($catid3); $cat3 = $row3['category']; $row4 = mysql_fetch_array($catid4); $cat4 = $row4['category']; echo "<table width='100%' border='1'>"; echo "<tr>"; echo"<th width='25%' scope='col'><div align='center'>" . $cat1 ." </div></th>"; echo"<th width='25%' scope='col'><div align='center'>" . $cat2 ." </div></th>"; echo"<th width='25%' scope='col'><div align='center'>" . $cat3 ." </div></th>"; echo"<th width='25%' scope='col'><div align='center'>" . $cat4 ." </div></th>"; echo "</tr><tr><td>"; 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.