Daniel0 Posted February 14, 2009 Share Posted February 14, 2009 And as a side-note, it's generally considered good practice to make name all variables, functions, classes, methods, properties, database tables, table fields, etc. in English regardless of what the output language is going to be like. I partly agree on that. I also write everything in English but it is a matter of cosistency. If you write one thing in Dutch the other functions tables ect should also be Dutch. It's too confusing using multiple language so stick with one instead. Right, but English is a de facto standard in programming. It's fair to assume that programmers know English, but it isn't fair to assume that people know another language. Furthermore, variables must for instance match the pattern ^[a-zA-Z_][a-zA-Z0-9_]*$ and many non-English languages contain other characters. Spanish as ñ, German has ß, Danish has æ and in many languages you use various forms of (other) diacritical marks. Then there are the languages which doesn't even use ASCII characters such as Arabic or Japanese. The code should always be written in English and then you can do stuff like i18n in your template files. Besides, all the library functions/classes and the keywords are in English as well. Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted February 14, 2009 Author Share Posted February 14, 2009 Yes that's logic. but that doesn't help me. I don't know why I used some word in dutch and the most in English, but I will change them all to english all right? Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted February 14, 2009 Share Posted February 14, 2009 Right, but English is a de facto standard in programming. It's fair to assume that programmers know English, but it isn't fair to assume that people know another language. Furthermore, variables must for instance match the pattern ^[a-zA-Z_][a-zA-Z0-9_]*$ and many non-English languages contain other characters. Spanish as ñ, German has ß, Danish has æ and in many languages you use various forms of (other) diacritical marks. Then there are the languages which doesn't even use ASCII characters such as Arabic or Japanese. The code should always be written in English and then you can do stuff like i18n in your template files. Besides, all the library functions/classes and the keywords are in English as well. I do agree with the fact the using only English is a better practice and looks tidier. Many times I've frowned by looking at some other Dutch programmers code thinking to myself ugh Dutch functions and variables, thats ugly. How ever if someone written a complete application using only a western language(which exclude Arabic, Chinese etc) Sometimes it can be handy to write that in the native language, for example to explain students how something works. I do wish English was the agreed upon language for coding. And there are many reasons more to use English for coding over any other language. It's also true that someone that doesn't know English will not come very far coding in any language. Just when coding at least be consistent and preferably all English. now back to the topic. this is how a better database design would look like. I also think you'd be better of using more tables Poems poem_id (int) user_id (int) foreign key category_id (int) foreign key book_id (int) foreign key poem_name (varchar) poem_text (text) poem_added (date) categories category_id (int) category_name (varchar) authors author_id (int) author_name (varchar) books book_id (int) author_id (int) foreign key book_name (varchar) users user_id (int) user_name (varchar) Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted February 14, 2009 Author Share Posted February 14, 2009 I dunno, First off all I don't use a user system, maybe it's better, but because it's for school I don't wanna to make it to complicated. Second, How can I make in this system a link that poem1 is from user2 and poem2,poem3 are from user2 or something? Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted February 14, 2009 Share Posted February 14, 2009 I dunno, First off all I don't use a user system, maybe it's better, but because it's for school I don't wanna to make it to complicated. Just because it's for a school doesn't mean it shouldn't be properly designed. How can I make in this system a link that poem1 is from user2 and poem2,poem3 are from user2 or something? Using Dj Kat's db schema: SELECT p.*, u.*, c.* FROM poems p INNER JOIN users u USING (user_id) INNER JOIN categories c USING (category_id) WHERE poem_id = ?; Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted February 14, 2009 Author Share Posted February 14, 2009 And what should it become whith: <?php require_once 'config.php'; // our database settings $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die('Error connecting to mysql'); mysql_select_db($dbname); if (isset($_GET['test'])) { $test = (int)$_GET['test']; }else { $test = 0; } if(isset($test)) { if($test = 0) { $PText = "THIS PAGE DOESN'T EXIST OR IS UNDER CONSTRUCTION"; $PName = "ERROR"; } else { $str = "test="; $test = "{$str}" . "{$test}"; $query = sprintf("SELECT PText from gedichten WHERE (category = 'test') AND (URL = '{$test}')", mysql_real_escape_string($_GET['test'])); $result = mysql_query($query); list($PText) = mysql_fetch_row($result); $query = sprintf("SELECT PName from gedichten WHERE (category = 'test') AND (URL = '{$test}')", mysql_real_escape_string($_GET['test'])); $result = mysql_query($query); list($PName) = mysql_fetch_row($result); } } ?> <html> <head> <title><?php echo $PName; ?></title> </head> <body> <?php echo $PText; ?> </body> </html> and <html> <head><title>Gedichten</title> <link href='../../standard.css' type='text/css' rel='stylesheet' /> <link href='natuur.css' type='text/css' rel="stylesheet" /> </head> <body> <table class='look' height='100%' width='100%' border='1'> <tbody> <tr> <td width='10%' height='100%'><iframe class='frames' src='../../functieknoppen/functieknoppennatuur.htm' frameborder='0' width='100%' height='100%' scrolling='no'></iframe> </td> <td><center> <?php require_once 'config.php'; // our database settings $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die('Error connecting to mysql'); mysql_select_db($dbname); $query = sprintf("SELECT COUNT(DISTINCT URL) FROM gedichten WHERE category='TEST'"); $result = mysql_query($query); list($url) = mysql_fetch_row($result); $url = $url + 1; print "<form action='' method='POST'> Jou Naam: <input type='text' maxlength='35' Name='UName'><br> Gedicht Naam: <input type='text' maxlength='35' Name='PName'><br> Auteur Naam: <input type='text' maxlength='35' Name='Auteur'><br> bundel: <input type='text' maxlength='35' Name='bundel'><br> Jaartal: <input type='text' maxlength='35' Name='jaartal'><br> Poem Text: <textarea COLS='60' ROWS='5' Name='PText'></textarea> <input type='hidden' name='URL' Value='{$url}'><br> <input type='submit' Value='Add!' name='submit'> <input type='reset'> </form>"; $query = sprintf("SELECT COUNT(DISTINCT id) FROM gedichten"); $result = mysql_query($query); list($id) = mysql_fetch_row($result); $id = $id + 1; $pname = $_POST['PName']; $uname = $_POST['UName']; $ptext = $_POST['PText']; $auteur = $_POST['Auteur']; $bundel = $_POST['bundel']; $jaartal = $_POST['jaartal']; $ip = $_SERVER['REMOTE_ADDR']; $added = date("d/m/y : H:i:s", time()) ; $str = "test="; $url = "{$str}" . "{$_POST['URL']}"; if($_POST['submit']) { if(empty($_POST['PName'])) { print "<script type='text/javascript'>alert('Je hebt geen gedichten naam geschreven!');</script>"; } elseif(empty($_POST['UName'])) { print "<script type='text/javascript'>alert('Je hebt je naam niet geschreven!');</script>"; } elseif(empty($_POST['PText'])) { print "<script type='text/javascript'>alert('je hebt geen gedicht geschreven!');</script>"; } elseif(empty($_POST['Auteur'])) { print "<script type='text/javascript'>alert('Je hebt geen Auteur ingevuld, als je het niet weet, schrijf dan Onbekend of UnKnown!');</script>"; } else { $query = sprintf("INSERT INTO gedichten(id,PName,UName,PText,URL,category,Auteur,bundel,jaartal,ip,added) VALUES ('$id','$pname','$uname','$ptext','$url','test','$auteur','$bundel','$jaartal','ip','added')"); $result = mysql_query($query); print "<script type='text/javascript'>alert('Je gedicht is toegevoegd aan de 'Natuur' categorie);</script><a href='test.php'>Zie alle gedichten</a>"; } } ?> </center></td> </tr> </tbody> </table> </body> </html> Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted February 14, 2009 Share Posted February 14, 2009 but because it's for school I don't wanna to make it to complicated. It might look more complicated but you are making tasks a lot simpler for future buildings. If you use a better relational database design things as selecting all authors and all poems from authors etc will be a lot easier. Just give it a try. earlier you mentioned you wanted poems in a category if you want then you can use Daniel's query with just one minor change SELECT p.*, u.*, c.* FROM poems p INNER JOIN users u USING (user_id) INNER JOIN categories c USING (category_id) WHERE category_id = ?; You also might want to try and do your queries in mysql query browser or phpmyadmin first to see if the selection is correct. After that it's easier to implement in your php code Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted February 14, 2009 Author Share Posted February 14, 2009 so it should be: <html dir="ltr"> <head> <title>TEST</title> <link href="../../standard.css" type="text/css" rel="stylesheet" /> <link href='dichtkunst.css' type='text/css' rel="stylesheet" /> </head> <body> <table class="look" height="100%" width="100%" border="1"> <tbody> <tr> <td width="10%" height="100%"><iframe class="frames" src="../../functieknoppen/functieknoppendichtkunst.htm" frameborder="0" width="100%" height="100%" scrolling="no"></iframe> </td> <td><center> <?php //database settings $query = sprintf("SELECT SELECT p.*, u.*, c.* FROM poems p INNER JOIN users u USING (user_id) INNER JOIN categories c USING (category_id) WHERE category_id = 7; ORDER BY p.poem_name DESC"); $result = mysql_query($query); while($urlgedicht = mysql_fetch_array($result)) { print "<ul><li><a href=testgedicht.php?{$urlgedicht['p.poem_id']}>{$urlgedicht['p.poem_name']} | {$urlgedicht['u.user_name']}</a></li></ul>"; } ?> <p> <p><a href="ADD.php">Voeg een gedicht omtrent dichtkunst toe.</a> </center></td> </tr> </tbody> </table> </body> </html> Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted February 14, 2009 Share Posted February 14, 2009 I'd make it more readable above your html tags for better sepration of logic and html output <?php $categoryId=(int)$_GET['category_id']; $query = "SELECT SELECT p.*, u.*, c.* FROM poems p INNER JOIN users u USING (user_id) INNER JOIN categories c USING (category_id) WHERE category_id = {$categoryId}; ORDER BY p.poem_name DESC"; $result = mysql_query($query): ?> inside your html <ul> <?php while($row = mysql_fetch_array($result)) : ?> <li> <a href="testgedicht.php?poem_id=<?php echo $row['p.poem_id']; ?>"> <?php echo $row['p.poem_name']." | ".$row['u.user_name']; ?> </a> </li> <?php endwhile; ?> </ul> Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted February 14, 2009 Author Share Posted February 14, 2009 If I do it this way, I get Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /www/zoombrowse.com/4/a/d/4ade/htdocs/gedichten/test/test.php on line 32 : <?php //DATABASE SETTINGS (4 lines) $categoryId='7'; $query = "SELECT SELECT p.*, u.*, c.* FROM poems p INNER JOIN users u USING (user_id) INNER JOIN categories c USING (category_id) WHERE category_id = {$categoryId}; ORDER BY p.poem_name DESC"; $result = mysql_query($query); ?> <html dir="ltr"> <head> <title>TEST</title> <link href="../../standard.css" type="text/css" rel="stylesheet" /> <link href='dichtkunst.css' type='text/css' rel="stylesheet" /> </head> <body> <table class="look" height="100%" width="100%" border="1"> <tbody> <tr> <td width="10%" height="100%"><iframe class="frames" src="../../functieknoppen/functieknoppendichtkunst.htm" frameborder="0" width="100%" height="100%" scrolling="no"></iframe> </td> <td><center> <ul> <?php while($row = mysql_fetch_array($result)) : ?> <li> <a href="testgedicht.php?poem_id=<?php echo $row['p.poem_id']; ?>"> <?php echo $row['p.poem_name']." | ".$row['u.user_name']; ?> </a> </li> <?php endwhile; ?> </ul> <p> <p><a href="ADD.php">Voeg een gedicht omtrent dichtkunst toe.</a> </center></td> </tr> </tbody> </table> </body> </html> Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted February 14, 2009 Share Posted February 14, 2009 Did you change your db schema? Try to run the query manually and check it's output (using e.g. phpMyAdmin). Also, <a href="testgedicht.php?poem_id=<?php echo $row['p.poem_id']; ?>"> <?php echo $row['p.poem_name']." | ".$row['u.user_name']; ?> should be <a href="testgedicht.php?poem_id=<?php echo $row['poem_id']; ?>"> <?php echo $row['poem_name']." | ".$row['user_name']; ?> Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted February 14, 2009 Share Posted February 14, 2009 Did you change your db schema? Try to run the query manually and check it's output (using e.g. phpMyAdmin). Also, <a href="testgedicht.php?poem_id=<?php echo $row['p.poem_id']; ?>"> <?php echo $row['p.poem_name']." | ".$row['u.user_name']; ?> should be <a href="testgedicht.php?poem_id=<?php echo $row['poem_id']; ?>"> <?php echo $row['poem_name']." | ".$row['user_name']; ?> my bad Daniel is right change the following to see if you get errors $result = mysql_query($query); to $result = mysql_query($query)or die(mysql_error()); also try to echo your query like so echo $query; then you see if that query has errors. if you don't see any errors try to run that query in mysql query browser or phpmyadmin to see what errors that produces. and did you change your db like the suggested. If so does it have data in the database? Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted February 14, 2009 Author Share Posted February 14, 2009 Yes I changed the db like you said and I've put something in it to try it, but I get this error, when I changed $result with a die(error()) Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted February 14, 2009 Share Posted February 14, 2009 Ah... you added an ORDER BY clause... Remove the semi-colon in WHERE category_id = {$categoryId}; ORDER BY p.poem_name DESC Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted February 14, 2009 Author Share Posted February 14, 2009 hace changed it, but still gives the error.. this is the code right now: <?php require_once 'config.php'; // our database settings $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die('Error connecting to mysql'); mysql_select_db($dbname); $categoryId='7'; $query = "SELECT SELECT p.*, u.*, c.* FROM poems p INNER JOIN users u USING (user_id) INNER JOIN categories c USING (category_id) WHERE category_id = {$categoryId} ORDER BY p.poem_name DESC"; $result = mysql_query($query) or die(mysql_error()); ?> <html dir="ltr"> <head> <title>TEST</title> <link href="../../standard.css" type="text/css" rel="stylesheet" /> <link href='dichtkunst.css' type='text/css' rel="stylesheet" /> </head> <body> <table class="look" height="100%" width="100%" border="1"> <tbody> <tr> <td width="10%" height="100%"><iframe class="frames" src="../../functieknoppen/functieknoppendichtkunst.htm" frameborder="0" width="100%" height="100%" scrolling="no"></iframe> </td> <td><center> <ul> <?php while($row = mysql_fetch_array($result)) : ?> <li> <a href="testgedicht.php?poem_id=<?php echo $row['poem_id']; ?>"> <?php echo $row['poem_name']." | ".$row['user_name']; ?> </a> </li> <?php endwhile; ?> </ul> <p> <p><a href="ADD.php">Voeg een gedicht omtrent dichtkunst toe.</a> </center></td> </tr> </tbody> </table> </body> </html> Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted February 14, 2009 Share Posted February 14, 2009 What version of MySQL are you using? Maybe it doesn't like the USING notation... Try this instead: SELECT SELECT p.*, u.*, c.* FROM poems p INNER JOIN users u ON u.user_id = p.user_id INNER JOIN categories c ON c.category_id = p.category_id WHERE category_id = {$categoryId} ORDER BY p.poem_name DESC Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted February 14, 2009 Author Share Posted February 14, 2009 Now it saids: Parse error: syntax error, unexpected T_STRING in /www/zoombrowse.com/4/a/d/4ade/htdocs/gedichten/test/test.php on line 9 <?php require_once 'config.php'; // our database settings $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die('Error connecting to mysql'); mysql_select_db($dbname); $categoryId='7'; SELECT SELECT p.*, u.*, c.* FROM poems p INNER JOIN users u ON u.user_id = p.user_id INNER JOIN categories c ON c.category_id = p.category_id WHERE category_id = {$categoryId} ORDER BY p.poem_name DESC $result = mysql_query($query) or die(mysql_error()); ?> <html dir="ltr"> <head> <title>TEST</title> <link href="../../standard.css" type="text/css" rel="stylesheet" /> <link href='dichtkunst.css' type='text/css' rel="stylesheet" /> </head> <body> <table class="look" height="100%" width="100%" border="1"> <tbody> <tr> <td width="10%" height="100%"><iframe class="frames" src="../../functieknoppen/functieknoppendichtkunst.htm" frameborder="0" width="100%" height="100%" scrolling="no"></iframe> </td> <td><center> <ul> <?php while($row = mysql_fetch_array($result)) : ?> <li> <a href="testgedicht.php?poem_id=<?php echo $row['poem_id']; ?>"> <?php echo $row['poem_name']." | ".$row['user_name']; ?> </a> </li> <?php endwhile; ?> </ul> <p> <p><a href="ADD.php">Voeg een gedicht omtrent dichtkunst toe.</a> </center></td> </tr> </tbody> </table> </body> </html> Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted February 14, 2009 Share Posted February 14, 2009 No offense, but you might want to check up on the Language Reference chapter in the manual. The query still needs to be a string. Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted February 14, 2009 Author Share Posted February 14, 2009 Yes ofcourse, I made a query from it and now it saids: Column 'category_id' in where clause is ambiguous <?php require_once 'config.php'; // our database settings $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die('Error connecting to mysql'); mysql_select_db($dbname); $categoryId='7'; $query= "SELECT p.*, u.*, c.* FROM poems p INNER JOIN users u ON u.user_id = p.user_id INNER JOIN categories c ON c.category_id = p.category_id WHERE category_id = {$categoryId} ORDER BY p.poem_name DESC"; $result = mysql_query($query) or die(mysql_error()); ?> <html dir="ltr"> <head> <title>TEST</title> <link href="../../standard.css" type="text/css" rel="stylesheet" /> <link href='dichtkunst.css' type='text/css' rel="stylesheet" /> </head> <body> <table class="look" height="100%" width="100%" border="1"> <tbody> <tr> <td width="10%" height="100%"><iframe class="frames" src="../../functieknoppen/functieknoppendichtkunst.htm" frameborder="0" width="100%" height="100%" scrolling="no"></iframe> </td> <td><center> <ul> <?php while($row = mysql_fetch_array($result)) : ?> <li> <a href="testgedicht.php?poem_id=<?php echo $row['poem_id']; ?>"> <?php echo $row['poem_name']." | ".$row['user_name']; ?> </a> </li> <?php endwhile; ?> </ul> <p> <p><a href="ADD.php">Voeg een gedicht omtrent dichtkunst toe.</a> </center></td> </tr> </tbody> </table> </body> </html> I'm now gone till tomorow Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted February 14, 2009 Share Posted February 14, 2009 it means there are more then one category_id fields to select. if you assign the table name on it then it might work change: WHERE category_id = {$categoryId} to: WHERE c.category_id = {$categoryId} Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.