Jump to content

proud

Members
  • Posts

    57
  • Joined

  • Last visited

    Never

Everything posted by proud

  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?
  15. Try this one: <?php echo "<p class='product_description'>" . "click image for bigger view</p>"; ?>
  16. Hello everyone, I want to code a Books Library management system using php and mysql, this book library should allow me to: 1- Search for books by name, category etc.. 2- Add new books to the library 3- Record books state, whether they are: present on the library or rented by a student 4- Record the date the book was out of the library and the date it was returned, 5- Finally, it should give a notification if a certain book was not returned for more than 2 days How many tables should I need to achieve the above goals? and how should the table structures and fields look like? Is there any ideas? Any help would be appreciated indeed..
  17. Yes its solved,the output looks like this: Array ( [0] => Array ( [0] => jack [1] => john ) [1] => Array ( [0] => jack [1] => Adam ) [2] => Array ( [0] => jack [1] => Mike ) [3] => Array ( [0] => john [1] => Adam ) [4] => Array ( [0] => john [1] => Mike ) [5] => Array ( [0] => Adam [1] => Mike ) ) just one last thing, I'm trying to get rid of the array keys => which appear in the output, so i tried something like this: <?php $names = array("jack","john","Adam","Mike"); $numNames = count($names); $combinations = array(); foreach ($names as $name1) { $n1 = array_shift($names); foreach ($names as $name2) { $combinations[] = array($n1, $name2); } } foreach ($combinations as $key => $combination) { if ($key > 0) { echo ', '; } echo $combination.' '; } ?> still couldn't solve the problem, any ideas?
  18. Need help generating all possible combination of names in an array Lets say i have the following array: $names = array("jack","john","Adam","Mike"); Now my goal is to find all possible combination of 2 names (first name and second name) e.g. Jack John , Jack Adam, Jack Mike etc... So how can I do this with PHP?
  19. $full_name="Mike Jerry Hanson"; I want to split this full name into 3 parts and assign each to a different variable Example: $first_name="Mike"; $mid_name="Jerry"; $last_name="Hanson"; Note that I don't know the $full_name string length, the only thing that separates first name, middle name and last name is the space between them. To elaborate: $full_name=$first_name." ".$mid_name." ".$last_name;
  20. <?php $settings['replace'] = array ("bastard" => "b******", "shit" => "s***", "sex" => "s**"); function filter_bad_words($text) { global $settings; foreach ($settings['replace'] as $k => $v) { $text = preg_replace("/\b$k\b/i",$v,$text); } return $text; } $answer="Essex sex"; $answer = filter_bad_words($answer); echo $answer; ?>
  21. The following script inserts photos to table (pic), and my images directory is (photos2). I just want help with resizing the photos so that they would have an equal width and length, is it possible? <?php include("connect.php"); // Where the file is going to be placed if(isset($_REQUEST['upload'])) { $target_path = "photos2/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name'])." has been uploaded"; } $f=basename($_FILES['uploadedfile']['name']); $rs=mysql_query("insert into pic (imgdata) values('$f')"); }
  22. I just got it! I never thought it was that simple. only - and _ need to be added between the brackets, like this: ret = TestInputType(objValue,"[^A-Za-z\\s-_]",strError, objValue.name+": Only alphabetic characters and space allowed ");
  23. This code is part of a function used to validate a text field input and accept only alphabetic characters and space: ret = TestInputType(objValue,"[^A-Za-z\\s]",strError, objValue.name+": Only alphabetic characters and space allowed "); My problem is that I want this function to accept dash and under score signs also e.g. (- _) in the above code, \\s refers to space, so how could I refer to those signs?
  24. I want to write a php code to validate a date string which has to be in the format:mmyy, for example (0308).. where 03 is (march) and 08 is (2008). months can range from 01 - 12, for example 13 is not acceptable: 1309.. Also months from january till september has to start with a 0: 0109,0209,0309 etc... finally i want to make sure that the provided string does not exceed the current year and month, for instance 0509 is accepted but 0609 or 0310 must be rejected. I don't know which php function can be used for such a validation, any help would be 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.