Jump to content
Larry Ullman's Book Forums

TeddyKGB

Members
  • Posts

    8
  • Joined

  • Last visited

TeddyKGB's Achievements

Newbie

Newbie (1/14)

1

Reputation

  1. Thanks HartleySan, that did lead me to the answer I was looking for. I just needed to change the original code from this; // Display the item: echo "<li>$todo"; To either this; // Display the item task: echo "<li>".$todo['task']; Or this; // Display the item answer: echo "<li>".$todo['answer']; I had tried this right at the beginning, but I had done the basic syntax wrong, I was trying to do this; // Display the item: echo "<li>$todo['answer']"; I clearly didn't pay attention to the error properly and I think that was why I was getting so confused about the whole thing! Started to doubt my fundamental understanding. Cheers Jon
  2. Hi HartleyStan, Thanks. The Step 1 part was just a typo on here, but good spot. In the foreach part of the previously mentioned function, the value of the current element is set to $todo, then it can just be printed (essentially it is just printing $task). echo '<ol>'; // Start an ordered list. // Loop through each subarray: foreach ($parent as $task_id => $todo) { // Display the item: echo "<li>$todo"; I just want to do the same thing, which from your previous response would suggest I just need to echo $tasks[$task_id]['task']. That makes sense and is what I had tried earlier. However, I am just getting error's when I try to use it. Notice: Array to string conversion in C:\xampp\htdocs\view_tasks.php on line 42 Array['task']. I put this in place of $todo, should I be putting it somewhere else? I guess I am also confused about the whole foreach functionality now it is an associative array.... I don't know how setting the element to $todo can be used. Regards Jon
  3. Hi Larry, I have been playing around with the scripts in Chapter 1, but I am stumped as to how to achieve something. I won't bore you with the end goal, but if I take the following from Script 1.3 (view_tasks.php). while (list($task_id, $parent_id, $task) = mysqli_fetch_array($r, MYSQLI_NUM)) { // Add to the array: $tasks[$parent_id][$task_id] = $task; } I want to add another variable (answer) that is going to change the array to look like this; Array ( [parent_id] => Array ( [task_id] => Array ( [task] => Test [answer] => Yes ) [task_id] => Array ( [task] => New Test [answer] => No ) ) ) Step 1 - To achieve this, I have done the following. Is this correct? while (list($task_id, $parent_id, $task) = mysqli_fetch_array($r, MYSQLI_NUM)) { // Add to the array: $tasks[$parent_id][$task_id] = array ('task' => $task, 'answer' => $answer); } If it is, I am really stumped as to how to now change the function to echo the variables $task and $answer. I have been reading in the PHP manual, and trying different things, but ultimately I am completely lost. Your help would be much appreciated! function make_list($parent, $all = null) { // Need the main $tasks array: static $tasks; if (isset($all)) { $tasks = $all; } echo '<ol>'; // Start an ordered list. // Loop through each subarray: foreach ($parent as $task_id => $todo) { // Display the item: echo "<li>$todo"; // Check for subtasks: if (isset($tasks[$task_id])) { // Call this function again: make_list($tasks[$task_id]); } echo '</li>'; // Complete the list item. } // End of FOREACH loop. echo '</ol>'; // Close the ordered list. } // End of make_list() function. Regards Jon
  4. Hi Larry, I used the SQL script on the downloads page, but noticed a number of the columns were inserted in the wrong order. The below SQL has them in the correct column order (seeing as I bothered to update it thought I would share)..... INSERT INTO words VALUES (NULL,1, 'PHP and MySQL for Dynamic Web Sites: The Forum!', '<p>Welcome to our site....please use the links above...blah, blah, blah.</p>\r\n<p>Welcome to our site....please use the links above...blah, blah, blah.</p>', 'Home', 'Forum Home', 'Language', 'Register', 'Login', 'Logout', 'New Thread', 'Subject', 'Body', 'Submit', 'Posted on', 'Posted by', 'Replies', 'Latest Reply', 'Post a Reply'), (NULL,4, 'PHP og MySQL for Dyaniske Websider: Forumet!', '<p>"Velkommen til denne siden. Introduksjonstekst."</p>\r\n<p>"Velkommen til denne siden. Introduksjonstekst."</p>', 'Hjem', 'Forumet Hjem', 'Språk', 'Registrer deg', 'Logg inn', 'Logg ut', 'Ny tråd', 'Emne', 'Kropp', 'SUBMIT', 'Lagt til', 'Lagt til av', 'REPLIES', 'LATEST REPLY', 'POST A REPLY'), (NULL,5, 'Forumul PHP si MySQL pentru site-uri web dinamice', 'Bine ati venit pe acest site. Text introductiv. Bine ati venit pe acest site. Text introductiv. Bine ati venit pe acest site. Text introductiv.', 'Acasa', 'Forumul Acasa', 'Limba', 'Inregistrare', 'Conectare', 'Deconectare', 'Discutie noua', 'Subiect', 'Continut', 'SUBMIT', 'Afisat pe', 'Afisat de', 'REPLIES', 'LATEST REPLY', 'POST A REPLY'), (NULL,3, 'Sites internet dynamiques avec PHP et MySQL : le forum!', 'Bienvenue sur ce site. Texte d''introduction. Bienvenue sur ce site. Texte d''introduction. Bienvenue sur ce site. Texte d''introduction.', 'Accueil', 'Le Forum Accueil', 'Langue', 'S''enregistrer', 'Se connecter', 'Déconnexion', 'Nouvelle discussion', 'Sujet', 'Contenu', 'Soumettez', 'Posté le', 'Posté par', 'Réponses', 'La Plus défunte Réponse', 'Signalez une réponse'), (NULL,7, 'PHP en MYSQL voor Dynamische Websites: Het Forum!', 'Welkom op deze site! Inleidingstekst. Hier vind je alles op het gebied van php!', 'Index', 'Forum Index', 'Taal', 'Registreer', 'Uitloggen', 'Inloggen', 'Nieuw onderwerp', 'Onderwerp', 'Body', 'SUBMIT', 'Geplaatst op', 'Geplaatst door', 'REPLIES', 'LATEST REPLY', 'POST A REPLY'), (NULL,9, 'PHP とMySqlでのだいなみっくなウエブサイト:フォラムです!', 'ようこそこのウエブサイトにおいでくださいました。紹介文。 ようこそこのウエブサイトにおいでくださいました。紹介文。', '話題', '返答を提示', '新しい スレツド ', 'ホーム', 'フォラムのホウムペイジ', '言語', 'レジスター', ' ログイン', 'ログアウト', '本文', 'サブミット', '掲示日', ' 掲示者', '返答数', '最新の返答'); Regards Jon
  5. Problem solved! You were right, it is just something to do with how phpMyAdmin is presenting the table. When I run the select from cmd, it shows it in the unreadable format of characters. Thanks Larry, much appreciated. Very good book. Regards Jon
  6. Yes I am seeing it in phpMyAdmin, this is how it is stored in the table. Because this is just a result of the queries listed above (and I have re-run and double checked them many times), I am not sure how else to debug this. I am continuing on through the book and haven't had any other issues yet (up to Chapter 10). Any help would be much appreciated, the book has been very useful so far! Regards Jon
  7. Just to add what verions I am on; Database server Server: 127.0.0.1 via TCP/IP Software: MySQL Software version: 5.5.27 - MySQL Community Server (GPL) Protocol version: 10 User: root@localhost Server charset: UTF-8 Unicode (utf8) Web server Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7 Database client version: libmysql - mysqlnd 5.0.10 - 20111026 phpMyAdmin Version information: 3.5.2.2, latest stable version: 4.0.3
  8. Hi, I have been following through the exercises in your book, and until now have been getting on fine. However I don't seem to be able to salt the password in the way described in the book in Chapter 7, page 238-239. I run the column creation queries; ALTER TABLE customers ADD COLUMN pin VARBINARY(16) NOT NULL; ALTER TABLE customers ADD COLUMN nacl CHAR(20) NOT NULL; Then I run the salt and password setting on one of the columns; UPDATE customers SET nacl = SUBSTRING(MD5(RAND()), -20) WHERE customer_id=1; UPDATE customers SET pin=AES_ENCRYPT(1234, nacl) WHERE customer_id=1; But for some reason, when I run the select query to view it, I get the following; customer_id = 1 first_name = Sarah last_name = Vowell nacl = 3df7829e4678b0d3e34c pin = f1c0318bbf8fe261e32c3a6f821561b7 The pin has been set as alphanumeric rather than in the unreadable format. It is also 32 characters rather than the 16 I set the column to. Do you know why this is happening? Regards Jon
×
×
  • Create New...