Antonio Conte
Members-
Posts
1084 -
Joined
-
Last visited
-
Days Won
126
Everything posted by Antonio Conte
-
A little CSS-hacking perhaps? HTML: &<span class="hide">.</span>lt; CSS: span.hide { display: none; // possibly more code. } < will always be encoded to < by the browser I think. This method might work because it's split up by punctuation. Not tested though Edit: If the text does not need to be markable by mouse/etc, you might just use a picture?
-
Foreign Key Coffee Question
Antonio Conte replied to nomadsoul's topic in Effortless E-Commerce with PHP and MySQL
Did not know that, Larry. Will check it out. -
Foreign Key Coffee Question
Antonio Conte replied to nomadsoul's topic in Effortless E-Commerce with PHP and MySQL
Hey, I'm not sure how T-SQL works. In MySqli, we don't define foreign keys in the table structure - we do it in our queries. I don't know how the structure for table "non_coffee_products" is. The columns in the SELECT statement is just made up by me. SELECT product.id, product.name, category.name FROM non_coffee_products AS product INNER JOIN non_coffee_categories AS category ON (product.category_id = category.id) I don't know if T-SQL has Inner Joins, but I'm guessing they do. Hope it makes sense. Several FROM tables and a WHERE clause might also work if you don't need category names etc. -
I like to use three different HTML inputs for dates. It just makes it easier to prevent date mistakes in my head. I also like to use jQuery to dispay DD / MM / YYYY in the field before click. Use the function checkdate. It will not accept anything but integers and correct dates. (30. february is giving faluire.) This function is relying on it. <?php function dateCheck($day, $month, $year) { if ( checkdate((int)$_POST[$month], (int)$_POST[$day], (int)$_POST[$year]) ) { return $date = $_POST[$year].-$_POST[$month].-$_POST[$day]; } else { // error handling } } ?> To work with numbers FROM the database, use something like substring. $day = substr("$row['dato']", 8, 2); $month = substr("$row['dato']", 5, 2); $year = substr("$row['dato']", 0, 4);
-
Error Msg
Antonio Conte replied to jibaba's topic in PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (1st Edition)
Jibaba: Use mysql_real_escape_string() instead of mysql_real_string() The function needs two parameters: One is your database connection. The other is the string you want to clean. Example: <?php $wash-me = "I might have dangerous data inside me!"; $clean = mysql_real_escape_string($wash-me, $database-connection); ?> Now you can use $clean to put data safe into a database. -
Q About Multiple Inner Joins
Antonio Conte replied to HartleySan's topic in Effortless E-Commerce with PHP and MySQL
I've seen that many struggles with more advanced SQL-queries. I've thought about writing a long post about queries, but where does one start? Mysqli is so full of functionality, but very little of it is normally used by PHP users. We like to manipulate data with PHP, often making things a lot harder for ourselves. Thank you for the nice words, Jonathon. I've written on UK and English board since I was 12-13 years old, and it's been great practice for me. -
Q About Multiple Inner Joins
Antonio Conte replied to HartleySan's topic in Effortless E-Commerce with PHP and MySQL
I'm not 100% sure of this. It matters in how the data is presented to you in SQL. It does not matter with PHP, as you specify which columns you would like to display, and how you would like to display them. Yes, you are absolutely right. Inner joins does not filter data. It connects data. That is how you would want to look at it. Regarding your question: Think of the columns vertically. Another Inner Join will add columns to the right of the column that you are joining on. Coffee_id: 13 / Size: 0.5 (kilo) / Height: 17 (cm) / etc. Are you following? And I did not read this before I answered your last quote. English is not my primary language, but this sounds more like the correct explanation of what happens. Arrest me if I'm wrong. As stated earlier, I think this will produce the same result. I cannot absolutely guarantee it, but why not do a test in phpMyAdmin or something? Correctamento. ORDER BY, order by, order BY, ORDER by... It does not matter. But you should really make it easier to write your queries. Larry has limited space, but you should make it easy to read. Look at something like this: Isn't this just WAAAY more simple to read? I've changed you names a lot here, but have tried to keep it logical. Hope you are get something from this. A second time: Write queries in something like phpMyAdmin to check your results! -
"appears saying the page has been accessed in error". The problem at least start in this code: // Add the message to the database: $r = mysqli_query($dbc, "INSERT INTO page_posts (user_id, page_id, message) VALUES ({$_SESSION['user_id']}, {$_GET['id']}, '$m')"); if (mysqli_num_rows($r) != 1) { // Problem! $page_title = 'Error!'; include ('./includes/header.html'); echo '<p class="error">This page has been accessed in error.</p>'; include ('./includes/footer.html'); exit(); } The query is obviously not what you wanted - thus mysqli_num_rows is not 1. (It's likely zero) Do some checks against PhpMyAdmin to check if the query is right when used manually. (Use values instead of get, session and variables.) Often, the errors can be small and hard to catch like "page_posts" should really be "page_post". Hope you figure it out.
-
I had that too. It's actually very simple. // A normal variable containing a number $a-number = 10; // This is 10 because it's before we use the function echo $a-number; // Now we use our function (see bottom) on this variable add_ten($a-number); // This is now 20 because of the function below echo $a-number; // This is a function that adds ten to the value function add_ten($function-variable) { return $function-variable + 10; } It does not matter what variable you put into the "use" part of the function. It can be named anything. That is why it's great. You could have a variable called "$another-number" and add ten to that as well.
-
It's because of the sorting before the echo statements. // NORMAL SORTING // Print the array as is: echo '<h3>Array As Is</h3><pre>' . print_r($students, 1) . '</pre>'; // Sort by name: uasort ($students, 'name_sort'); // Print the array now: echo '<h3>Array Sorted By Name</h3><pre>' . print_r($students, 1) . '</pre>'; // Sort by grade: uasort ($students, 'grade_sort'); // Print the array now: echo '<h3>Array Sorted By Grade</h3><pre>' . print_r($students, 1) . '</pre>';
-
How To Make One Database Query From Two?
Antonio Conte replied to Terry's topic in Effortless E-Commerce with PHP and MySQL
Mysqli have functions called mysqli_multi_query mysqli_more_results: http://php.net/manua...ore-results.php $query = "SELECT count(*) as count FROM posts"; $query .= "SELECT * FROM posts WHERE posts.status='publish' AND posts.level='".$access_level."' ORDER BY id LIMIT $pageNum, $totalRows"; More than that, I cannot help you really. I haven't played with these functions yet. The thought is to use the first query to store the number of rows in the database, and the second one to get results. Hope this help, with the thought process at least. -
You should take a look at the CodeIgniter framework as well, Larry. I've had trouble just installing YII, so I've haven't got around to try it.
-
You don't need mysql*_real_escape_string() with Prepared Statement. I absolutely see your point though // Set Mysqli or Mysqli $MySQLI == TRUE; if ($MySQLI == true) { // do Prepared statements } else { self::sanitize_values($input); // do things with $value } private function sanitize_values($value) { // Only remove if magic quotes are enabled if ( get_magic_quotes_gpc() ) { $value = stripslashes($value); } // Then use mysql*_real_escape_string $value = mysql_real_escape_string($value); return $value; }
-
When writing database structures, the normal way to do it is like this: table (primary_key, foreign key*, other_rows) It just makes it easier to read. I also like to name foreign keys with tablename_id. Adding fk after the name id_fk is also used to see that it's a foreign key.