jbrill Posted July 25, 2007 Share Posted July 25, 2007 hey, just need to get this last question solved and my project is done!! Basically what i need to do is get the last entry from table "job_part" WHERE quote_id=$quoteid It will pull a digit, if there was one in the database. I would then like to have text field that is given the value that we just got from the database, and add 1 to it. so if it pulled a "1" it would " + 1" and set the value of the text box to "2" quite simple probably. I just need to have someone show me how it is done. I need to present this to my client today and this is the final step to have it working!. Heres the code for the page. <?php include 'admin_header.php'; $jobid = $_GET['jobid']; if($_SESSION['type'] != "admin") { echo "You are either not logged in, or logged in but with no authority to access this page.<br>please visit the log in page <a href=index.php>here</a>."; } else { // execute the real stuff if the login is valid include 'admin_jobmenu.php'; ?> <div align="center"> <!-- end header --> <?php if($_POST['drawing_number']!="") { // process the data load scheme $update = 'INSERT INTO job_part (quote_id, step_id, drawing_number, quantity, material, purchased_by, supplier, status) VALUES ("'.$_GET['jobid'].'","'.$_POST['step_id'].'","'.$_POST['drawing_number'].'","'.$_POST['quantity'].'","'.$_POST['material'].'","'.$_POST['purchased_by'].'","'.$_POST['supplier'].'","'.$_POST['status'].'")'; echo $update."<br>"; $check = mysql_query($update); $lastid = mysql_insert_id(); echo "<table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"tableoutline\"> <tr> <td>"; echo "New Job Part Created<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=admin_findparts.php?idr=$jobid\"></td></tr></table>"; } // data load scheme ends here else {// if no data loaded, run this.. ?> <br> <form name="createpart" method="post"> <br> <table border="0" width="100%" align="center"> <td align="center"> <?php if ($msg == "") { echo(" "); } else { echo($msg); } ?> </td> </tr> </table> <input type="text" name="stepid" value="<? // This is where the new number will go, this will be a hidden field eventually ?>"/> <table align="center" border="0" cellpadding="0" cellspacing="0" class="tableoutline"> <tr> <td> <table align="center" border="0" cellpadding="10" cellspacing="0" bgcolor="#ffffff" style="border:1px solid #000000"> <tr class="colorheader"> <td align="center" colspan="2" class="colorhedr"><font class="section">Create A New Job Part</font></td> </tr> <tr class="tablelight"> <td align="right" class="editpdL"><strong>Drawing Number</strong></td> <td class="editpdR"><input type="text" name="drawing_number" size="20"></td> </tr> <tr class="tablelight"> <td align="right" class="editpdL"><strong>Quantity</strong></td> <td class="editpdR"><input type="text" name="quantity" size="20"></td> </tr> <tr class="tabledark"> <td align="right" class="editpdL"><strong>Material</strong></td> <td class="editpdR"> <select name="material"> <option selected value=''>-- Select Category --</option> <? $statussql = "SELECT * FROM materials ORDER BY cat"; $cats = mysql_query($statussql); $status = mysql_fetch_array($cats); do { echo "<option value='".$status["material"]."'>".$status["cat"]." - ".$status["material"]."</option>"; } while ($status = mysql_fetch_array($cats)); ?> </select> </td> </tr> <tr class="tabledark"> <td align="right" class="editpdL"><strong>Purchased By</strong></td> <td class="editpdR"> <input type="Checkbox" name="purchased_by" value="MGM"> MGM<br> <input type="Checkbox" name="purchased_by" value="Customer"> Customer </td> </tr> <tr class="tabledark"> <td align="right" class="editpdL"><strong>Supplier</strong></td> <td class="editpdR"> <select name="supplier"> <option selected value=''>-- Select Supplier --</option> <? $supplysql = "SELECT * FROM suppliers ORDER BY name"; $supplier = mysql_query($supplysql); $supply = mysql_fetch_array($supplier); do { echo "<option value='".$supply["name"]."'>".$supply["name"]."</option>"; } while ($supply = mysql_fetch_array($supplier)); ?> </select> </td> </tr> <tr class="tabledark"> <td align="right" class="editpdL"><strong>Status</strong></td> <td class="editpdR"> <select name="status"> <option selected value=''>-- Select Supplier --</option> <? $statussql = "SELECT * FROM complete"; $status = mysql_query($statussql); $stat = mysql_fetch_array($status); do { echo "<option value='".$stat["status"]."'>".$stat["status"]."</option>"; } while ($stat = mysql_fetch_array($status)); ?> </select> </td> </tr> <tr class="tabledark"> <td class="editfootSingle" colspan="2" align="center"> <input type="submit" name="Create" value="Create Job Part" class="inputsubmit"> </td> </tr> </table> </td> </tr> </table> </form> <br> <!-- begin footer --></div> <? } } include 'admin_footer.php'; ?> Link to comment https://forums.phpfreaks.com/topic/61719-adding-a-single-digit-to-a-previous-one/ Share on other sites More sharing options...
jbrill Posted July 25, 2007 Author Share Posted July 25, 2007 anyone? i REALLY need to get this figured out in the next hour or so! PLEEEEAAASSEEE Link to comment https://forums.phpfreaks.com/topic/61719-adding-a-single-digit-to-a-previous-one/#findComment-307271 Share on other sites More sharing options...
sasa Posted July 25, 2007 Share Posted July 25, 2007 echo mysql_result(mysql_query('SELECT field_name FROM table_name WHERE condition ORDER BY field_name DESC LIMIT 0, 1'),0,0)+1; Link to comment https://forums.phpfreaks.com/topic/61719-adding-a-single-digit-to-a-previous-one/#findComment-307357 Share on other sites More sharing options...
jbrill Posted July 25, 2007 Author Share Posted July 25, 2007 ddint work, any more solutions? Link to comment https://forums.phpfreaks.com/topic/61719-adding-a-single-digit-to-a-previous-one/#findComment-307420 Share on other sites More sharing options...
redarrow Posted July 25, 2007 Share Posted July 25, 2007 i dont get this at all you select the current field you need and then do a if == 1 then a update to update the database adding 1 to it like set whatever=whatever+1 where whatever='$what_ever' that it. Link to comment https://forums.phpfreaks.com/topic/61719-adding-a-single-digit-to-a-previous-one/#findComment-307437 Share on other sites More sharing options...
jbrill Posted July 25, 2007 Author Share Posted July 25, 2007 similar to what i want yes, but no "update" all i need to do is echo the highest number in that field and then add 1 to it. then echo that in a hidden field as the value so when the whole form is submitted, that gets inserted into the proper place. Link to comment https://forums.phpfreaks.com/topic/61719-adding-a-single-digit-to-a-previous-one/#findComment-307441 Share on other sites More sharing options...
trq Posted July 25, 2007 Share Posted July 25, 2007 echo $row['value']++; Link to comment https://forums.phpfreaks.com/topic/61719-adding-a-single-digit-to-a-previous-one/#findComment-307454 Share on other sites More sharing options...
jbrill Posted July 25, 2007 Author Share Posted July 25, 2007 i think we are getting closer, this is what i have put in now... <? $partquery="SELECT * FROM job_part WHERE quote_id=$jobid"; $partinfo = mysql_query($partquery); $row = mysql_fetch_array($partinfo); ?> <input type="text" name="step_id" value="<? echo $row['step_id']+1;?>"> however, now it is only displaying a "1" and it is not adding up with every new part Link to comment https://forums.phpfreaks.com/topic/61719-adding-a-single-digit-to-a-previous-one/#findComment-307471 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.