hackalive Posted April 1, 2010 Share Posted April 1, 2010 This code is meant to implode $qry_AL = "SELECT max(position) FROM `articles` WHERE `uri`='$uri'"; $result_AL= $mysqli->query($qry_AL, MYSQLI_STORE_RESULT); $AL = mysqli_fetch_array($result_AL); $AL = $AL['0']; for($i=0;$i<=$AL;$i++) { $AL.$i = implode("", $AL.$i); } Basically what should happen is that $i is the maximum position value and then will implode all $AL# into just $AL# so if max position is 9 it should loop through doing the implode for $AL0, $AL1 etc upto and including $AL9, the $i should reflect the moving up value till $i=9 any help would be so much appreciated, thanks in advance Quote Link to comment Share on other sites More sharing options...
MatthewJ Posted April 1, 2010 Share Posted April 1, 2010 $qry_AL = "SELECT max(position) FROM `articles` WHERE `uri`='$uri'"; $result_AL= $mysqli->query($qry_AL, MYSQLI_STORE_RESULT); $AL = mysqli_fetch_array($result_AL); for($i=0;$i<count($AL);$i++) { $AL[$i] = implode("", $AL[$i]); } Something like that maybe? Quote Link to comment Share on other sites More sharing options...
hackalive Posted April 1, 2010 Author Share Posted April 1, 2010 $AL.$i would return $AL1 etc which is required to be as such $AL[$i] is incorrect, thanks for the help though any one else? Quote Link to comment Share on other sites More sharing options...
andrewgauger Posted April 1, 2010 Share Posted April 1, 2010 Are you talking about different variables such as $AL1, $AL2, $AL3? The syntax for that is ${"AL".$i} Quote Link to comment Share on other sites More sharing options...
ChemicalBliss Posted April 1, 2010 Share Posted April 1, 2010 You need to use variable variables. lol, short ex: $variable = "test"; $name = "variable"; echo($$name); // results as "test" So: <?php $qry_AL = "SELECT max(position) FROM `articles` WHERE `uri`='$uri'"; $result_AL= $mysqli->query($qry_AL, MYSQLI_STORE_RESULT); $AL = mysqli_fetch_array($result_AL); $AL = $AL['0']; // Just to show you it works $name_array = array(); for($i=0;$i<=$AL;$i++) { $name = $AL.$i; $$name = implode("", $AL.$i); // Just to show you it works $name_array[] = $name; } // Just to show you it works print_r($name_array); ?> -CB- Quote Link to comment Share on other sites More sharing options...
hackalive Posted April 1, 2010 Author Share Posted April 1, 2010 okay this works $qry_AL = "SELECT max(position) FROM `articles` WHERE `uri`='$uri'"; $result_AL= $mysqli->query($qry_AL, MYSQLI_STORE_RESULT); $AL = mysqli_fetch_array($result_AL); $AL = $AL['0']; for($i=0;$i<=$AL;$i++) { ${'AL'.$i} = implode("", ${'AL'.$i}); } return $AL1; but I get this message Warning: implode() [function.implode]: Invalid arguments passed in "HIDDEN BY ME"\index.php on line 123 line 123 is $result_AL= $mysqli->query($qry_AL, MYSQLI_STORE_RESULT); help is much appreciated, and thanks to all those who have helped so far Quote Link to comment Share on other sites More sharing options...
hackalive Posted April 2, 2010 Author Share Posted April 2, 2010 someone? Quote Link to comment Share on other sites More sharing options...
hackalive Posted April 2, 2010 Author Share Posted April 2, 2010 This error is causing some serious problems for me so if anyone can help it would be much appreciated Quote Link to comment Share on other sites More sharing options...
trq Posted April 2, 2010 Share Posted April 2, 2010 Your code makes little sense. You are trying to define a string using implode, but the second argument your passing to implode is this same variable you haven't defined yet. ps: Variable variables are slow, use an arrays instead. Quote Link to comment Share on other sites More sharing options...
hackalive Posted April 2, 2010 Author Share Posted April 2, 2010 thorpe could you provide an example using my code above please Quote Link to comment Share on other sites More sharing options...
trq Posted April 2, 2010 Share Posted April 2, 2010 Your question & code makes little sense. Quote Link to comment Share on other sites More sharing options...
hackalive Posted April 2, 2010 Author Share Posted April 2, 2010 can you elaborate on exactly why Quote Link to comment Share on other sites More sharing options...
trq Posted April 2, 2010 Share Posted April 2, 2010 Because your not providing enough information and the code examples are so far from working code that they make no sense (not to mention the fact that your variable names do NOTHING to help us know what data they store). Quote Link to comment Share on other sites More sharing options...
hackalive Posted April 2, 2010 Author Share Posted April 2, 2010 the code get the max position (eg 1) from a table then as a loop (for) it implodes all $AL1 arraqy data into a sting variable $AL1 then does a return Quote Link to comment Share on other sites More sharing options...
trq Posted April 2, 2010 Share Posted April 2, 2010 $AL1 is not defined anywhere in your code. Quote Link to comment Share on other sites More sharing options...
hackalive Posted April 2, 2010 Author Share Posted April 2, 2010 $AL1[0] = "hi"; $AL[1] = "and"; as an example (is predefined) pulled from another table Quote Link to comment Share on other sites More sharing options...
trq Posted April 2, 2010 Share Posted April 2, 2010 $tmp = ''; for ($i=0;$i<=$AL;$i++) { $tmp += implode("", $AL1); } $AL1 = $tmp; Quote Link to comment Share on other sites More sharing options...
hackalive Posted April 2, 2010 Author Share Posted April 2, 2010 your code cannot be used as sometimes it may get to $AL1000 it has to be completely self running (as such) Quote Link to comment Share on other sites More sharing options...
trq Posted April 2, 2010 Share Posted April 2, 2010 So, where are all these $A1 - $A1000 variables defined? Quote Link to comment Share on other sites More sharing options...
hackalive Posted April 2, 2010 Author Share Posted April 2, 2010 okay, in a tbl field I have (as an example) AAA: <AL1><AL2><b><AL3> furthermore in another table field I have BBB: <AL1>How is it going?<AL2>Well<AL3>Thats great I have code which works that replaces <AL1> etc from "AAA" with the relevant content from "BBB" finally what happens is this $qry_AL = "SELECT max(position) FROM `articles` WHERE `uri`='$uri'"; $result_AL= $mysqli->query($qry_AL, MYSQLI_STORE_RESULT); $AL = mysqli_fetch_array($result_AL); $AL = $AL['0']; for($i=0;$i<=$AL;$i++) { ${'AL'.$i} = implode("", ${'AL'.$i}); } return $PL1 this code finds the max(position) in a table (eg 5), what happens is it implodes $AL1 array into $AL1 or $AL2 array into $AL2 etc but it is resulting in the already mentioned error Quote Link to comment Share on other sites More sharing options...
hackalive Posted April 2, 2010 Author Share Posted April 2, 2010 the main point is why does this error occur and why for the line previously indicated? Quote Link to comment Share on other sites More sharing options...
trq Posted April 2, 2010 Share Posted April 2, 2010 And I have already explained the reason for the error. Your second argument to implode is the same variable you are trying to create. Hence, it does not exist when you pass it to implode. Your code and your approach to this problem both have some serious floors in logic. Quote Link to comment Share on other sites More sharing options...
hackalive Posted April 2, 2010 Author Share Posted April 2, 2010 thorpe can you give me code suggestion Quote Link to comment Share on other sites More sharing options...
trq Posted April 2, 2010 Share Posted April 2, 2010 Not without an explination of exactly what your trying to do. We need the big picture. 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.