-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
Please stop posting your code on a single line. It's ****ing annoying.
-
a href="cocoa_type_chocolate.php?type_chocolate='dark'">Dark</a>
Barand replied to bertrc's topic in PHP Coding Help
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 -
How to Add Element to end of currently Iterating array
Barand replied to sen5241b's topic in PHP Coding Help
Yes you can - I just showed you how to do it. -
How to Add Element to end of currently Iterating array
Barand replied to sen5241b's topic in PHP Coding Help
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 -
a href="cocoa_type_chocolate.php?type_chocolate='dark'">Dark</a>
Barand replied to bertrc's topic in PHP Coding Help
You have a syntax error on line 8 and you only show one line!? Sorry, can't help. -
a href="cocoa_type_chocolate.php?type_chocolate='dark'">Dark</a>
Barand replied to bertrc's topic in PHP Coding Help
I get no syntax errors when I run it. What's your code now? (Preferably in a readable format) -
a href="cocoa_type_chocolate.php?type_chocolate='dark'">Dark</a>
Barand replied to bertrc's topic in PHP Coding Help
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) -
a href="cocoa_type_chocolate.php?type_chocolate='dark'">Dark</a>
Barand replied to bertrc's topic in PHP Coding Help
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. -
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.
- 1 reply
-
- 1
-
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.
-
The whole point of prepared statements is not to put variables in the query. Look at my code again.
-
Would you like me to move this thread to the "Politics & Economics" forum?
-
Need help in Checking divisibility of Numbers in Php
Barand replied to Marie's topic in PHP Coding Help
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. -
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 {
-
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
-
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.
-
I don't see your problem. I have given you a solution using @mac_gyver's example.
-
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");