Jump to content

proud

Members
  • Posts

    57
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

proud's Achievements

Member

Member (2/5)

0

Reputation

  1. *Mysql version: 5.0.51a I have 3 tables: books, students, and book_loans. (books) contains the fields: (isbn, title, author, category) (students) contains the fields: (student_no, name, phone, email) (book_loans) contains the fields: (isbn, student_no, borrow_date, due_date) (isbn) and (student_no) are the primary keys of books and students tables respectively, and both are primary keys in the (book_loans) table. Now, what I want to do is to assign them as foreign keys in the (book_loans) table. When I delete or modify a record in the parent tables, the changes should be applied to the foreign key in the child table (book_loans). Here is the code for the three tables: books table: CREATE TABLE `books` ( `isbn` varchar( 13 ) NOT NULL , `title` varchar( 80 ) NOT NULL , `author` varchar( 50 ) NOT NULL , `category` varchar( 30 ) NOT NULL , PRIMARY KEY ( `isbn` ) ) ENGINE = INNODB; students table: CREATE TABLE `students` ( `student_no` varchar( 12 ) NOT NULL , `name` varchar( 50 ) NOT NULL , `phone` varchar( 20 ) NOT NULL , `email` varchar( 50 ) NOT NULL , PRIMARY KEY ( `student_no` ) ) ENGINE = INNODB; book_loans table: CREATE TABLE `book_loans` ( `isbn` varchar( 13 ) NOT NULL , `student_no` varchar( 12 ) NOT NULL , `borrow_date` date NOT NULL , `due_date` date NOT NULL , PRIMARY KEY ( `isbn` , `student_no` ) ) ENGINE = INNODB; Please add the foreign key code for the book_loans table.
  2. I'm trying to design a website that contains multiple languages (English, Arabic, French etc..) I haven't faced any problem with the English part, but when I tried to display strings containing Arabic letters to the screen using echo command I get ????? question marks or other symbols instead of the text that is supposed to be displayed. and I tried to display them using the HTML part of the code but it also led to the same result. Any idea how this problem can be solved? <html><head> <title>MultiLingual Website</title> </head> <body> <?php echo "Math"; //English echo"<br><br>"; echo"Matemáticas"; // French word meaning Math echo"<br><br>"; echo "رياضيات"; // Arabic word meaning Math echo"<br><br>"; ?> رياضيات </body> </html> Result: Math Matemáticas ??????? ???????
  3. $diffsecs = strtotime($current_date) - strtotime($due_date); $diffdays = floor($diffsecs / 60 / 60 / 24); Thankyou very much jl5501, this one did the job!
  4. I need help with subtracting two dates from each other and getting the result in days. $current_time= strtotime("now"); $current_date= date('Y-m-d',$current_time); $query = mysql_query("SELECT * FROM books where isbn='$isbn' and date_due < '$current_date' ") or die(mysql_error()); $fetch= mysql_fetch_array($query); $due_date=$fetch['date_due']; $diff_date=$current_date-$due_date; echo"This book has been delayed for ".$diff_date." days"; Where the value of $current_date is 2010-02-22 and the value of $due_date is 2010-02-20 So how can I get the value of $diff_date to be 2 days?
  5. I have a text field in which I'm supposed to enter the answer for the security question which is needed in case I forgot my password e.g (who is your best childhood friend?).. Now the problem is that when I enter a value in the first time, the second time I find a drop down box which contains my previous value, and of course this is a security breach. So isn't there someway to disable the history of this text field but besides it shouldn't repeat the same action in the future?
  6. Hello everyone, I have 2 tables: [books] with the fields (id, title,author,isbn) and another table called [book issue] with the fields (id, borrower_id, borrow_date, book_isbn).. Now the field (book_isbn) in the [book issue] table references (isbn) in the books table, which is a unique field but not a primary key. My questions: 1- Is it correct for a foreign key to reference a unique but non-primary key in another table? 2- Is it okay for the foreign key field to have a different name than the field it references in the other table? Your help is indeed appreciated..
  7. I have a table called time with 2 fields: id(Int), and date(Date).. Now when I use this query to insert the following date value to the table: <?php include( 'conn.php' ); $borrow_date = date("d-m-Y"); // current date echo $borrow_date; $sql= mysql_query("insert into time (id,date) values('','$borrow_date')") or die (mysql_error()); ?> The new value of id is (1), but the new value of date is (0000-00-00), when it is supposed to be (02-02-2010).. Does any one know why?
  8. I'm having a problem in retrieving a record from my books table, which is a book titled 'C++'.. The code below retrieved any (title,author) record from my books table except for the record which contains the book with the C++ title.. So has the '+' sign got anything to do with that? Any ideas on how I can solve this problem? <?php $book_title=$_GET['book_title']; $query = mysql_query("SELECT * FROM books where title='$book_title' ORDER BY id asc ") or die(mysql_error()); while($rows = mysql_fetch_array( $query )) { ?> <table> <tr> <td>Book Title</td> <td> <?php echo $rows['title']; ?> </td> </tr> <td>Book Author</td> <td> <?php echo $rows['author']; ?> </td> </tr> </table> <? } ?> By the way, just to add: In another query where I did not use $_GET to get the value of the book title from the URL, the C++ record was retrieved successfully.. So I might add that it also may have a problem with $_GET and '+' sign
  9. Yes that does the job! Thanks a lot co.ador
  10. Hello everyone, I want to use $_GET to retrieve a value from a URL. Now, the problem is that I have 2 values that I want to get from the following URL: http://localhost/library/title_info.php?book=My Book_student=mike The values that I want to get are: My Book, and mike .. Now, I know that its easy to get the last value by the following code for example: $get=$_GET['student']; which will give me the value: mike.. But the problem is how can i get the value of book which is: My Book? Because if I tried: $get=$_GET['book']; The value of $get would be: My Book_student=mike Put in consideration that I want "My Book" only and not the rest of the URL after it.. So is there someway to omit the rest of the string starting from the under score "_" , or is there any other way to accomplish this?
  11. I created a library management system using PHP.. Now, I want to create a search box in my system so that I can search for books by title, author.. What I want to do is to create a suggestions for my search box in case someone submitted a wrong value.. like for example if he entered anstein for the book author, it should provide him with something like: Did you mean einstein? It's similar to what you find in answers.com, wikipedia etc.. Any idea how I could do something like that?
  12. I have a table containing information about books in my library and this table has the following columns: id, title, category. What I want to do is to make a form that will allow me to sort these books according to one of these fields, its just like in you tube when you want to sort videos by date added, relevance, view count etc.. Both the form and the php code are in "view_books.php" Here is my form: <form method="POST" action="view_books.php"> Sort by: <select size="1" name="sort"> <option> id </option> <option> category </option> <option> Date Added </option> </select> <input type="submit" value="Go!"> </form> Here is my php code to sort the books in a table: $query = mysql_query ("SELECT * FROM books ORDER BY id asc ") or die (mysql_error()); ?> <table width="76%" border="0" align="center" > <? while($rows = mysql_fetch_array( $query )) { ?> <tr> <td> <font color="#696969" size=2> <?php echo $rows['id']; ?> </font></td> <td> <font color="#696969" size=2> <?php echo $rows['title']; ?> </font></td> <td> <font color="#696969" size=2> <?php echo $rows['category']; ?> </font></td> </tr> <? } ?> </table> Please apply the changes in my code so that it can perform the required function. Thanks, any help would be appreciated..
  13. Hello teamatomic, this post is helpful and shows me from where to start, Thank you very much indeed..
  14. can you be more specific? and what are the data fields for those tables? Don't you think that 10 tables is too much? I can imagine 3 tables: Admin, Books, and Students/Users what should the rest 7 tables be?
×
×
  • 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.