Jump to content

acmumph

Members
  • Posts

    16
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

acmumph's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks for the solution. Nice way to make each id unique. I was trying to figure out how to add the primary key ID for the unique id element....
  2. SO I have the attached code that produces a row of results from a db query. Instead of having a new window appear to make any edits to returned fields, I am trying to allow a dblclick on desired row and an editable row expands underneath it. Unfortunately, I get this to work for the first row returned, but any row below that does not acknowledge dblclick action...appreciate any help you can provide <!DOCTYPE html> <html> <head> <script type='text/javascript' src='jquery-2.0.3.js'></script> <script> $(document).ready(function(){ $("#flip").dblclick(function(){ $("#panel").slideToggle("slow"); }); }); </script> <style type="text/css"> #panel{ padding:5px; text-align:center; background-color:purple; border:solid 1px #c3c3c3; } #panel{ padding:10px; display:none; } #flip{ padding:5px; text-align:center; background-color:#e5eecc; border:solid 1px #c3c3c3; } </style> </head> <body> <div > <?php $con = mysqli_connect('localhost','root','','ajax_demo'); if (!$con) { die('Could not connect: ' . mysqli_error($con)); } mysqli_select_db($con,"ajax_demo"); $sql="SELECT * FROM user;"; $result = mysqli_query($con,$sql); echo "<table border='1'> <tr> <th>Firstname</th> <th>Lastname</th> <th>Age</th> <th>Hometown</th> <th>Job</th> </tr>"; while($row = mysqli_fetch_array($result)) { echo "<tr id='flip'>"; echo "<td>" . $row['FirstName'] . "</td>"; echo "<td>" . $row['LastName'] . "</td>"; echo "<td>" . $row['Age'] . "</td>"; echo "<td>" . $row['Hometown'] . "</td>"; echo "<td>" . $row['Job'] . "</td>"; echo "</tr>"; echo "<tr id='panel'>"; echo "<form action='#' method='GET'>"; echo "<td><input type='text' value='".$row['FirstName']."'></input></td>"; echo "<td><input type='text' value='".$row['LastName']."'></input></td>"; echo "<td><input type='text' value='".$row['Age']."'></input></td>"; echo "<td><input type='text' value='".$row['Hometown']."'></input></td>"; echo "<td><input type='text' value='".$row['Job']."'></input></td>"; echo "<td><input type='submit'></input></td>"; echo "</form>"; echo "</td>"; } echo "</table>"; mysqli_close($con); ?> </div> </body> </html>
  3. For some reason I couldn't seem to get that right. Something about single and double quotes screw me up.... Appreciate the solution..
  4. So I want to pass a php variable to the following line of code: echo '<script type="text/javascript">alert("Registration number already exist");history.back(); </script>'; I thought I could do this: $regnum="12345"; echo '<script type="text/javascript"> var regnum="<?php echo $regnum; ?>";alert("Registration number:"+regnum+" already exist");history.back(); </script>'; The alert displays "Registration number:<?php echo regnum;?> already exist"... Appreciate any feedback.
  5. Worked like a champ...There are times that certain machines I am responsible for are off-line and my webpage would hang up at the point a mysql connection was trying to be made to that off-line box. Once it was brought back on-line and page refreshed it would continue displaying rest of page...Your solution allowed me to by-pass the mysql connection/query that was unreachable.... Thanks for the help... <html> <head> </head> <body> <?php $mysql_conn=new mysqli('192.168.1.68','admin','password','monkey'); if (!$mysql_conn->connect_error) { $result=$mysql_conn->query("SELECT * from testtable"); echo "<table>"; echo "<th>Test Query</th>"; while ($row=$result->fetch_array(MYSQL_ASSOC)){ echo "<tr><td>"; echo $row['test1']; echo "</td></tr>"; } echo "</table>"; } $mysql_conn=new mysqli('192.168.1.126','admin','','monkey1'); if (!$mysql_conn->connect_error) { $result=$mysql_conn->query("SELECT * from demo"); echo "<table>"; echo "<th>Test Processor</th>"; while ($row=$result->fetch_array(MYSQL_ASSOC)){ echo "<tr><td>"; echo $row['name']; echo "</td></tr>"; } echo "</table>"; } ?> </body> </html>
  6. Below is some code I have that I would like to connect to databases that reside on different physical machines. The problem I can't seem to solve is how to ignore machines that are unreachable. <html> <head> </head> <body> <?php $mysql_conn=new mysqli('192.168.1.67','admin','password','monkey'); $result=$mysql_conn->query("SELECT * from testtable"); echo "<table>"; echo "<th>Test Query</th>"; while ($row=$result->fetch_array(MYSQL_ASSOC)){ echo "<tr><td>"; echo $row['test1']; echo "</td></tr>"; } echo "</table>"; $mysql_conn=new mysqli('192.168.1.126','admin','','monkey1'); $result=$mysql_conn->query("SELECT * from demo"); echo "<table>"; echo "<th>Test Processor</th>"; while ($row=$result->fetch_array(MYSQL_ASSOC)){ echo "<tr><td>"; echo $row['name']; echo "</td></tr>"; } echo "</table>"; $mysql_conn=new mysqli('192.168.1.127','admin','','monkey2'); $result=$mysql_conn->query("SELECT * from demo"); echo "<table>"; echo "<th>Test Processor</th>"; while ($row=$result->fetch_array(MYSQL_ASSOC)){ echo "<tr><td>"; echo $row['processor']; echo "</td></tr>"; } echo "</table>"; ?> </body> </html> If 192.168.1.126 is offline, the webpage doesn't go any further and display 192.168.1.127's info...Appreciate any insight...
  7. Awesome...worked like a champ
  8. So I'm trying to get a variable assigned by stepping through an array using the following code. $american=array("ABC","Beefmaster","Braford","Brahman","Brahmousin","Brangus","OARB","Red Brahman","Red Brangus","Santa Gertrudis","Simbrah","Star5"); $british=array("Angus","Hereford","Polled Hereford","Lowline Angus","Red Angus","Shorthorn"); $exotic=array("AOB","Braunvieh","Charolais","Chi","Limousin","Maine Anjou","ORB","Simmental"); if ($species==$american[]) { $division="American"; } else if ($species==$british[]){ $division="British"; } else if ($species==$exotic[]){ $division="Exotic"; } Appreciate your time
  9. I found a solution. I handled it in mysql using SELECT DATEDIFF(CURDATE(), dob) as days FROM table From there I just added my conditions.. $days=$row['days']; if ($days <=120) { $class =1; echo $class; } elseif ($days >120 && $days <=240) { $class=2; echo $class; } elseif ($days >240 && $days <=360) { $class=3; echo $class; } Appreciate the help..
  10. Seems the 1-120..121-240 would be the way to go...For some reason I can't get the logic to work out in my code attempt, but it sounds good when I say it out loud ..
  11. So I'm trying to assign classes based on date of birth(dob)..For example if born within last 4 months you are in class 1, if born between 8-12 months ago class 2 and 12-16 months ago class 3....Appreciate your time... <?php $dob=$row['dob']; $format='j-M-y'; $date=date($format); $classdate1= date ($format, strtotime('-4 month' .$date)); $classdate2= date ($format, strtotime('-8 month' .$date)); $classdate3= date ($format, strtotime('-12 month' .$date)); $classdate4= date ($format, strtotime('-16 month' .$date)); $classdate5= date ($format, strtotime('-20 month' .$date)); $classdate6= date ($format, strtotime('-24 month' .$date)); $classdate7= date ($format, strtotime('-28 month' .$date)); if ($dob < $classdate1) { $class = 1; echo $class; } elseif ( $dob > $classdate1 && $dob < $classdate2) { $class = 2; echo $class; } elseif ( $dob > $classdate2 && $dob < $classdate3) { $class = 3; echo $class;
  12. Thanks for the insight...I managed to get it working with following code: //Get data in local variable $first=$_POST['first']; $last=$_POST['last']; $street=$_POST['street']; $city=$_POST['city']; $zip=$_POST['zip']; $position=$_POST['position']; $committee=$_POST['committee']; $species=$_POST['animal_species']; $breed=$_POST['animal_breed']; $dob=$_POST['animal_dob']; $tag=$_POST['animal_tag']; $weight=$_POST['animal_weight']; // check for null values $query="insert into members(id, first, last, street, city, zip, position,committee) values(NULL,'$first','$last','$street','$city','$zip','$position','$committee')"; $query1="insert into animal(animal_id, exhibitor_id, animal_species, animal_breed, animal_dob, animal_tag, animal_weight) values(NULL, LAST_INSERT_ID(),'$species','$breed','$dob','$tag','$weight')"; mysql_query($query) or die(mysql_error()); mysql_query($query1) or die(mysql_error()); header("Location: members.php"); //echo "Your message has been received"; I'm relatively new at this and trying to learn as I go. I know just enough to hurt myself at this point but will be sure to think of how and where to add error checking. Thanks for the help!!
  13. Trying to utilize the LAST_INSERT_ID() feature but can't seem to get it right in my code: //Get data in local variable $first=$_POST['first']; $last=$_POST['last']; $street=$_POST['street']; $city=$_POST['city']; $zip=$_POST['zip']; $phone=$_POST['phone']; $position=$_POST['position']; $committee=$_POST['committee']; $species=$_POST['species']; $breed=$_POST['breed']; $dob=$_POST['dob']; $tag=$_POST['tag']; $weight=$_POST['weight']; $query="insert into members(id, first, last, street, city, zip, phone,position,committee) values(NULL,'$first','$last','$street','$city','$zip','$position','$committee')"; $query1="insert into animal(animal_id, exhibitor_id, animal_species, animal_breed, animal_dob, animal_tag, animal_weight) values(NULL, LAST_INSERT_ID(),'$species','$breed','$dob','$tag','$weight')"; mysql_query($query) or die(mysql_error()); mysql_query($query1) or die(mysql_error()); header("Location: members.php"); //echo "Your message has been received"; If I do the following from MySQL prompt it works: INSERT INTO members(id, first, last) VALUES (NULL, "Test", "Me"); INSERT INTO animal(animal_id, exhibitor_id,animal_species) VALUES (NULL, LAST_INSERT_ID(),"Heifer"); Appreciate your time
  14. Appreciate the info. You are correct in your assumptions. When you say I assume you mean they are Primary Keys in their respective table, correct? I'm trying to visualize the data input process and where/how the animal_show and show_winners table will be populated. My confusion is on the show_winners(show_id and winners_id) If those two are auto_incremented from their respective table, how do those auto_increment values get to the animal_show table? Below are the tables I created and am going to start throwing sample data into them to see if I can come up with some possible scenarios on extracting specific bits of info....(i.e. which exhibitor has most accumulated points and list the shows they won, etc...) CREATE TABLE `animal` ( `animal_id` int( 11 ) NOT NULL AUTO_INCREMENT , `animal_species` varchar( 50 ) NOT NULL COMMENT 'Wether, Angus, Brahma', `animal_tag` varchar( 20 ) NOT NULL COMMENT 'County Tag', `animal_weight` int( 5 ) NOT NULL , `exhibitor_id` int( 11 ) NOT NULL , PRIMARY KEY ( `animal_id` ) ) ENGINE = MyISAM DEFAULT CHARSET = latin1 AUTO_INCREMENT =1; CREATE TABLE `animal_show` ( `animal_id` int( 11 ) NOT NULL , `show_id` int( 11 ) NOT NULL ) ENGINE = MyISAM DEFAULT CHARSET = latin1; CREATE TABLE `exhibitor` ( `exhibitor_id` int( 11 ) NOT NULL AUTO_INCREMENT , `exhibitor_firstname` varchar( 50 ) NOT NULL , `exhibitor_lastname` varchar( 50 ) NOT NULL , `exhibitor_phone` varchar( 12 ) NOT NULL , `exhibitor_street` varchar( 60 ) NOT NULL , `exhibitor_city` varchar( 50 ) NOT NULL , `exhibitor_state` varchar( 2 ) NOT NULL , `exhibitor_zip` varchar( 12 ) NOT NULL , `exhibitor_organization` varchar( 70 ) NOT NULL , `exhibitor_points` int( 5 ) NOT NULL , PRIMARY KEY ( `exhibitor_id` ) ) ENGINE = MyISAM DEFAULT CHARSET = latin1 AUTO_INCREMENT =1; CREATE TABLE `show` ( `show_id` int( 11 ) NOT NULL AUTO_INCREMENT , `show_name` varchar( 70 ) NOT NULL COMMENT 'Wether, Angus, Brahma', `animal_tag` varchar( 20 ) NOT NULL COMMENT 'County Tag', `show_date` DATE NOT NULL , PRIMARY KEY ( `show_id` ) ) ENGINE = MyISAM DEFAULT CHARSET = latin1 AUTO_INCREMENT =1; CREATE TABLE `show_winners` ( `show_id` int( 11 ) NOT NULL , `winners_id` int( 11 ) NOT NULL ) ENGINE = MyISAM DEFAULT CHARSET = latin1; CREATE TABLE `winners` ( `winners_id` int( 11 ) NOT NULL AUTO_INCREMENT , `winners_ring` varchar( 4 ) NOT NULL , `winners_place` varchar( 6 ) NOT NULL , `winners_class` varchar( 4 ) NOT NULL , `winners_grand` tinyint( 1 ) NOT NULL , `winners_reserve` tinyint( 1 ) NOT NULL , `animal_id` int( 11 ) NOT NULL , PRIMARY KEY ( `winners_id` ) ) ENGINE = MyISAM DEFAULT CHARSET = latin1 AUTO_INCREMENT =1; Thanks again
  15. Recently got involved with local 4-H and wanted to improve animal/project tracking. I thought PHP/MYSQL would be just the thing to do it. With that, I've come up with the following table layout. exhibitor (exhibitor_id(P), exhibitor_firstname, exhibitor_lastname, exhibitor_phone,exhibitor_street, exhibitor_city, exhibitor_state, exhibitor_zip, exhibitor_organization, exhibitor_points, animal_id) show (show_id(P), show_name, show_date, winners_id) animal (animal_id(P), animal_species, animal_tag, animal_weight, show_id) winners (winners_id(P), winners_place, winners_class, winners_grand, winners_reserve ,animal_id) Rationale: 1. Each exhibitor can have multiple animals 2. Each animal can be in multiple shows but only has one exhibitor 3. Each show has multiple winners Question: How far off am I in establishing relationships between the tables? the first two rationales seem pretty straight forward, but the 3rd rationale (winners) is a little confusing for me...Appreciate any insight/info you could provide. Thanks, Aaron
×
×
  • 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.