Jump to content

averagejoe77

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Everything posted by averagejoe77

  1. Ok, I need some serious help here. I have a jQuery .load method that retrieves a single users name from a database. However... I also need to incorporate error checking into the script that the .load method access, so that, if the user enters a name in the field that is not in the database, it will insert it into the database, and then then pull it back out again to be returned by the ajax call. This is the jQuery that performs the call: $('#submit').click(function(e) { var user = $('#user').val(); var checkurl = "indexData.php"; $('#username').load(checkurl, 'user=' + user); e.preventDefault(); }); This is the script form indexData.php: <?php $db = mysql_pconnect('localhost', 'joeme0', 'Galatians2'); if (!$db) { die('Could not connect: ' . mysql_error()); } mysql_select_db('joeme0_brave'); $name = $_POST['name']; $checkQuery = "select name from users where name='$name'"; $checkResult = mysql_query($checkQuery); if ($checkResult > 1) { $insQuery = "insert into users (id, name) values ("", '$name')"; $insResult = mysql_query($insQuery); if ($insResul 0) { $query="select name from users where name='$name'"; $result=mysql_query($query); while($row=mysql_fetch_array($result)) { echo $row['name']; } } else { echo "Cold not insert your name into the database"; } } else { $query="select name from users where name='$name'"; $result=mysql_query($query); while($row=mysql_fetch_array($result)) { echo $row['name']; } } ?> So far I can get it to pull out a name that is manually entered into the database no problem. But I can't get it to insert a name that isn't in the database, and then query the database a second time to pull that same name back out again. The page is pretty simple. The user comes to the page, enters their name in the text field, either clicks the submit button or presses the enter key. The scripts fire off the ajax call to the database, check to see if the name exists, if not enter it and pull it back out (this is where I have the problem), if so, pull it out and display it back on the page.
  2. I am using SMF on my clans website to handle their forums, but I want to create a roster on the main website using the members table from SMF. I can successfully connect to the database and loop through all the names in the table, sorting them by membergroup in descending order. the code is as follows: <?php do { echo '<table border="1" width="90%" style="margin:0 auto 20px auto;" cellspacing="10"> <tr>'; // create a heading based on the member group that a member or members belong too. // i.e. For the Commanding Officer, Unit Staff, Enlisted Personnel, Recruits, and Public Members. // This is where I am lost !!!! echo '</tr> <tr> <th>Rank</th> <th>Name</th> <th></th> </tr> <tr> <td width="10%" valign="middle" align="center">'; $ranks = $row_roster['stars']; $grade = explode("/", $ranks); if ($grade[1] != "") echo '<img src="forums/Themes/25ID20/images/ranks/'.$grade[1].'" /><br />'; echo' </td> <td style="padding-left:30px;">'.$row_roster['member_name'].'</td> <td> </tr> </table>'; } while ($row_roster = mysql_fetch_assoc($roster));?> and the output can be viewed here: As you can see, it creates a separate table for each person in the list. What I want to do is have separate tables for each member group, with all members of one member group in the same table . Currently my member groups are based on the US Army ranking structure, the lower your rank, the lower your member group ID. I cannot for the life of me figure out how to create multiple tables with multiple member names in some tables, and only one member name in other tables. I suppose I could do multiple DB queries, but isn't that a little too redundant? Is what I want possible or am I only hoping? Thanks. Joe.
×
×
  • 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.