Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. Please stop posting your code on a single line. It's ****ing annoying.
  2. I edited my code just after posting but you evidently were quick off the mark and missed the changes in your copy. $res->bind_param('s', $_GET['tipus_xocolata']); $res->bid_result($id_xocolata, $nom_xocolata, $id_tipus_xocolata, $tipus_xocolata) ; was changed to $res->bind_param('s', $_GET['tipus_xocolata']); $res->execute(); // added $res->bind_result($id_xocolata, $nom_xocolata, $id_tipus_xocolata, $tipus_xocolata) ; // changed bid_result to bind_result But I don't see where the "<" is coming from. Unexpected end-of-file is usually the result of a missing end "}" or unclosed quotes. * * * * * * As for the where... 'dark', that's done by the placeholder "?" in the query and the bind_param to replace the placeholder with the value when the query is executed
  3. Yes you can - I just showed you how to do it.
  4. When you use foreach() you iterate through a copy of the array elements but you are adding 'pink' to the original array. To iterate through the original array you need to pass the values "by reference". For example $colors = array("red", "green", "blue", "yellow"); foreach($colors as $x => &$value): // note the "&" echo "$value <br>"; if ($x == 1) $colors[] = "pink"; endforeach; giving red green blue yellow pink
  5. You have a syntax error on line 8 and you only show one line!? Sorry, can't help.
  6. I get no syntax errors when I run it. What's your code now? (Preferably in a readable format)
  7. try this for cocoa_type_chocolate.php <?php mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); $mysqli = mysqli_connect("localhost", "root", "*****", "cocoa"); if (isset($_GET['type_chocolate'])) { $res = $mysqli->prepare("SELECT c.id_chocolate , c.name_chocolate , t.id_type_chocolate , t.type_chocolate FROM chocolate c INNER JOIN type_chocolate t ON c.id_chocolate = t.id_type_chocolate WHERE type_chocolate = ? "); $res->bind_param('s', $_GET['type_chocolate']); $res->execute(); $res->bind_result($id_chocolate, $name_chocolate, $id_type_chocolate, $type_chocolate) ; echo '<pre>'; while ($res->fetch()) { printf("%s %s %s %s\n", $id_chocolate, $name_chocolate, $id_type_chocolate, $type_chocolate); } echo '</pre>'; } PS not sure if the join is right as I don't know your table structure edit - forgot the execute (I hate mysqli - too many things to do. Give me PDO any day)
  8. I removed the passwords from your posts. You can do the reformatting yourself if you want people to read them. You do seem to be connecting to the DB server 3 ties in same file though - once is sufficient.
  9. That query statement is an example of what I said about the code...
  10. I don't see how... 100000000000000000 9223372036854775807 He isn't running it again - he attempting to run a query on a statement object instead of a string of SQL.
  11. @ginerjm Please use PHP code type for your PHP code. This enables the format highlighting features (such as the comments above). I have edited this one for you.
  12. The column names in the query results wil be id_chocolate name_chocolate id_type_chocolate type_chocolate id_chocolate The tablename. prefixes are not part of them.
  13. Answer: The first line only. The rest is a hotch-potch of pasted code with no thought for what each line does or what the variables contain.
  14. If you ever get around to looking at the PHP manual and look up "shuffle()" yo will see its description is This function shuffles (randomizes the order of the elements in) an array. As it is randomising what you already have (ie a random number) what are you gaining? The second thing to note in the description is that it is for shuffling the elements of an array, not the characters in a string.
  15. The shorter answer would be to the question "What would work?"
  16. The whole point of prepared statements is not to put variables in the query. Look at my code again.
  17. Would you like me to move this thread to the "Politics & Economics" forum?
  18. Brilliant, Sherlock! If you had taken the trouble to read the (old and already fixed) post you would have seen that it already uses the modulo operator.
  19. You were right with the COUNT(*). You should be using a prepared statement and not trying to sanitize the input using htmlspecialchars (which is an output function) $sql = 'SELECT COUNT(*) FROM myTable WHERE myField = ?'; $stmt = $con->prepare($sql); $stmt->execute( [ $_GET["example"] ] ); if ($stmt->fetchColumn() == 0 {
  20. Yes, of course there is. If your array contains, say, 10 expression then you can write out 10 if() expressions - 1 for each array element). For example if (preg_match($regex[0], $mystr)) { // do something } elseif (preg_match($regex[1], $mystr)) { // do something else } elseif (preg_match($regex[2], $mystr)) { // do something else } ... //etc
  21. That code doesn't do that. That will be a problem as you don't store the data, you just fetch it and throw it away.
  22. I don't see your problem. I have given you a solution using @mac_gyver's example.
  23. You now create all your TreeLinks with id='tom' and all SimilarLinks with id='jerry'. Why are are you having difficulty with the concept of UNIQUE? I'll type this slowly for you ... No -- two -- elements -- on -- a -- page-- can -- have-- the -- same -- id -- value. Try some thing like this (As we only see snippets of your code, as though through keyholes, and not the whole picture, I am assuming that the following code is inside a loop and $index is incremented on each iteration). Prefix the TreeLink IDs with "T" and the SiimilarLink IDs with "S". echo "<br><a href='#' onclick='showDiv(\"T$index\")' style='float: right; margin-top: -6px; margin-right: 8px;'>Show domain linkage</a>"; echo getLinkTree($pdo, $row['url'], "T$index"); echo "<br><a href='#' onclick='showDiv(\"S$index\")' style='float: right; margin-top: -6px; margin-right: 8px;'>Show similar linkage</a>"; echo getLinkSimilar($pdo, $row['url'], "S$index");
  24. IDs need to be unique. You cannot have two (or more) elements with the same id. Give them different ids - simple!.
  25. I may be reading it wrong but it looks to me that you are allocating the same id (ie $index) to the linkTree div and the linkSimilar tree.
×
×
  • 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.