Jump to content

jefffan24

Members
  • Posts

    18
  • Joined

  • Last visited

    Never

Everything posted by jefffan24

  1. I wasn't quite sure what to put as a title but I need a script that can do this: I have a question regarding JavaScript. I need a script that will act like a small airline computer system (really basic). You are to write a program to assign seats on each flight of the airline’s only plane (capacity: 10 seats). Your program should display the following menu of alternatives: Please type 1 for "First Class" and Please type 2 for "Economy” If the person types 1, your program should assign a seat in the first-class section (seats 1–5). If the person types 2, your program should assign a seat in the economy section (seats 6–10). Your program should print a boarding pass indicating the person’s seat number and whether it is in the first-class or economy section of the plane. Use a one-dimensional array to represent the seating chart of the plane. Initialize all the ele¬ments of the array to 0 to indicate that all the seats are empty. As each seat is assigned, set the cor¬responding elements of the array to 1 to indicate that the seat is no longer available. Your program should, of course, never assign a seat that has already been assigned. When the first-class section is full, your program should ask the person if it is acceptable to be placed in the economy section (and vice versa). If yes, then make the appropriate seat assignment. If no, then print the message "Next flight leaves in 3 hours.” I don't expect somebody to write this script for me, but I don't even know where to start Any help would be greatly appreciated, I don't know JavaScript. I do know PHP and XHTML and CSS so no need to dumb it down just give it to me as it is.
  2. So nobody has anything else? I'm not trying to push the issue too much its just the faster I get this figured out the better :/
  3. ok but how do I get that into my for loop? I can't do a while loop within a for loop can I? Also how does that delete without telling it where delete from like DELETE FROM feedback WHERE ID= whatever... Sorry I'm kind of new to the whole php thing I might be missing something, but it isn't working for me :/
  4. in front of the ; put a \ to ignore the ;. i don't know if this the error but it might be considering the line to end when it sees the ; even though it is in the '.
  5. When he says use those without the spaces he means like: [code=php:0]put your code here [/code] and then you put code were it says "put your code here".
  6. So what I'm trying to do is I have a "feedback" section on a website i'm working on. It shows 5 records at a time. What I want to do is add a Delete button/link where it will delete only that row that is being shown: http://i53.photobucket.com/albums/g52/jefffan24/plaster.png[/img] So when a person clicks Delete Feedback it will only delete the feedback for that row/record. What I have currently is this: $row2 = mysql_fetch_array($result); for($counter = 1; $counter <= 5; $counter += 1) { $id = $_GET[iD]; $delete = mysql_query("DELETE FROM feedback WHERE ID = $id"); echo "<a href=\"editphpfeedback.php?$delete$ \">Delete Feedback?</a><br />"; echo "<font face='comic sans ms' size='-1'>Subject: <b><font color='red'> " . $row2['Subject'] . "</font></b>"; echo "<br />Message: <b>" . $row2['Message'] . "</b><br /><br />"; echo "<hr color='#EEEEEE' /></font>"; echo "</form>"; $row2 = mysql_fetch_array($result); } If you can fix that or if you think something else would work please let me know and I will try it. Ok so now for my second question, I currently have my script to show 5 results at a time and pull 5 results from my database at a time. Right now these 2 process do not work with each other so I my script shows the Subject:, Message: 5 times even if there are no records to be shown. Is there any way I can control how many times (Subject:, Message:) is shown based on how many rows there are, but still only show 5 at a time? I have my script doing? pagination so that when there is more then 5 results it will go to the next page. Any help here would be greatly appreciated. Currently what I have: $sql = "SELECT COUNT(*) FROM feedback"; $result = mysql_query($sql) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 5; // find out total pages $totalpages = ceil($numrows / $rowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if ########## // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if ########### // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; ########## // get the info from the db $sql = "SELECT * FROM feedback ORDER BY ID DESC LIMIT $offset, $rowsperpage"; $result = mysql_query($sql) or trigger_error("SQL", E_USER_ERROR); ######### //Number fetch array for $result $row2 = mysql_fetch_array($result); for($counter = 1; $counter <= 5; $counter += 1) { $id = $_GET[iD]; $delete = mysql_query("DELETE FROM feedback WHERE ID = $id"); echo "<a href=\"editphpfeedback.php?$delete$ \">Delete Feedback?</a><br />"; echo "<font face='comic sans ms' size='-1'>Subject: <b><font color='red'> " . $row2['Subject'] . "</font></b>"; echo "<br />Message: <b>" . $row2['Message'] . "</b><br /><br />"; echo "<hr color='#EEEEEE' /></font>"; echo "</form>"; $row2 = mysql_fetch_array($result); } ######## /****** build the pagination links ******/ // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } //End IF ######### // range of num links to show $range = 5; // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for //Show next page link even if page is 1 if ($currentpage <= $totalpages - 1) { //get next page num $nextpage = $currentpage + 1; //show > to go to next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; //show >> to go to last page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if
  7. I'm new to the whole php/mysql thing...thanks for letting me know about the security flaw And helping me fix my problem.
  8. Don't see how my code will help in this situation as it doesn't really do anything beside enter an input into a field in a database, but what ever here it is. $sql="INSERT INTO emails (Email) VALUES ('$_POST[email]')"; if (mysql_query($sql,$con)) { echo ""; } else trigger_error("SQL", E_USER_ERROR); mysql_close($con)
  9. So I don't know if I should put this here or in mysql, but what my script is for is for people to add their emails to our mailing list. Pretty simple, I got that working. But what I want it do now is that if somebody puts their email in and their email is already added to our database then it doesn't do anything. but if their email isn't in our database then it will add it. So basically stop duplicate records. Is there any way to do this php? I'm sure there is, its just not coming to me.
  10. I forgot about the remote connection thing. Thanks that fixed it.
  11. Ok so I got the ODBC connector and I go to Add a data source using MySQL ODBC 5.1 Driver. My MySQL Database is version 5.0.86 (Its hosted on Godaddy). Could this be a reason why I am having problems connecting? I know I have the server location, username and password right. But the only thing that doesn't match the ODBC driver and my version. Let me know if you need to know anything else.
  12. Do you have your method in your form set to post? <form method="post">
  13. I know it hasn't been long since my last post but the quicker I can get this the better. If somebody doesn't understand what I'm asking please let me know. I know I can be difficult to understand sometimes. Thanks.
  14. Ok so I have gotten the pagination script to work somewhat now I need help with that :/ I've got it to show how many pages there are based on the results but when I go to the next page it is only changing 1 result. Like I have my primary key auto incrementing. And I have the field descending. So on the first 5 it shows 20-16. Then I go to page 2, and its showing 19-15. Any help would be greatly appreciated. //Get how many rows there are: $sql = "SELECT COUNT(*) FROM testtable"; $result = mysql_query($sql) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 5; // find out total pages $totalpages = ceil($numrows / $rowsperpage); ########## // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if ########## // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if ########### // the offset of the list, based on current page $offset = ($currentpage - 1); ########## // get the info from the db $sql = "SELECT * FROM testtable LIMIT $offset, $rowsperpage"; $result = mysql_query($sql) or trigger_error("SQL", E_USER_ERROR); ######### //Number fetch array for $result $row2 = mysql_fetch_array($result); for($counter = 1; $counter <= 5; $counter += 1) { echo $row2['ID'] . "<br />"; echo " Subject:<b><font color='red'> " . $row2['Subject'] . "</font></b>"; echo "<br />Message: <b>" . $row2['Message'] . "</b><br /><br />"; $row2 = mysql_fetch_array($result); } ######## /****** build the pagination links ******/ // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } //End IF ######### // range of num links to show $range = 3; // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for //Show next page link even if page is 1 if ($currentpage <= $totalpages - 1) { //get next page num $nextpage = $currentpage + 1; //show > to go to next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; //show >> to go to last page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if mysql_close($con); ?>
  15. Well I mean onlick is just what I had now, I'm willing to try anything. I was just giving my current failed attempt at it.
  16. So I'm making a feedback sort of section on a website with MySQL and PHP, I've gotten the script to do everything I want except for this. I want the script to only show 5 at a time (which i have accomplished no problem), but I'm also trying to make it so that when the user clicks a button it will show the next 5 records in the database so they can view all records, but only 5 at a time. (I hope this makes sense). So I need the button to add 5 to my $start variable, and then re-run my for loop. $start = 0; echo $start . "<br /><br />"; $result2 = mysql_query("SELECT * FROM testtable LIMIT $start,5") or die(mysql_error()); $row2 = mysql_fetch_array($result2); for($counter = 1; $counter <= 5; $counter += 1) { echo $row2['ID'] . "<br />"; echo " Subject:<b><font color='red'> " . $row2['Subject'] . "</font></b>"; echo "<br />Message: <b>" . $row2['Message'] . "</b><br /><br />"; $row2 = mysql_fetch_array($result2); } mysql_close($con) ?> <br /> <form> <input type="button" value="submit" onclick="<?php $start += 5; ?>" /> </form> <?php echo $start; ?> Any help would be greatly appreciated!
×
×
  • 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.