Results 26 to 50 of 99
-
09-05-2006, 10:01 PM #26Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
I simply used the same name as you did. I even tested with mine as I have the same error result unfortunitely.
-
09-05-2006, 11:48 PM #27Web Hosting Master
- Join Date
- Aug 2002
- Location
- Canada
- Posts
- 667
-
09-06-2006, 06:24 AM #28Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
As you can see from this post:
http://www.webhostingtalk.com/showpo...74&postcount=9
I'm, first, checking if the variable is, indeed, an array. If not, it fails.
Any other idea ?
-
09-06-2006, 10:57 AM #29Web Hosting Master
- Join Date
- Aug 2002
- Location
- Canada
- Posts
- 667
That's a poorly scoped block of code.. Consider replacing it with these few lines:
Code:if( isset( $_POST['user_id'] ) && is_array( $_POST['user_id'] ) ){ $user_ids = implode( ",", $_POST['user_id'] ); $result = mysql_query( "SELECT user_id FROM table WHERE id = '{$_SESSION['user_id']}'", $connection ); if( $row = mysql_fetch_assoc( $res ) ){ if( $row['user_id'] && count( $user_ids ) ){ $idstr = ""; foreach( $user_ids as $id ) $idstr = "'{$id}',"; $idstr = substr( $idstr, 0, strlen( $idstr ) -1 ); mysql_query( "UPDATE table SET user_id = '{$row['user_id']}' WHERE user_id IN ($idstr) AND id = '{$_SESSION['user_id']}'" ) or die( mysql_error() ); header("Location: index.php"); } } } else{ die ('No permission'); }
There's some wierd stuff in your code that I assumed was a sematic mistake.
Code:$sql = " SELECT user_id FROM table WHERE id = ".$_SESSION['user_id']; $result = mysql_query($sql); while ($row = mysql_fetch_array($result)) { $user_id_field = $row['user_id']; }
Nonetheless, this has nothing to do with an array error...you're probably not catching your array, or screening it properly. Get an IDE like Zend Studio, it can help you when you are learning with its "Analyze Code" feature.Last edited by Saeven; 09-06-2006 at 11:02 AM.
-
09-06-2006, 12:52 PM #30Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
Ok thanks. I will try this up later today. As for the while loop statement, good question for the single field. I was so into it that I forgot to tell myself to simply set a single variable without a loop. It would, indeed, of been enough. As for the user_id field as a primary - no - it isn't. It's being placed under the 2nd row in the table.
More inputs to come later . . .
-
09-06-2006, 05:44 PM #31Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
This is, now, the error I got:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') AND ...
-
09-06-2006, 07:38 PM #32Web Hosting Master
- Join Date
- Aug 2002
- Location
- Canada
- Posts
- 667
-
09-06-2006, 07:45 PM #33Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
Hope this has jogged a solution for you.
Ah ! well, I guess I will have to wait for an experienced PHP coder to post but I thank you for your time and try-outs anyway.
-
09-06-2006, 08:14 PM #34Web Hosting Master
- Join Date
- Aug 2002
- Location
- Canada
- Posts
- 667
I think if you looked into my portfolio you wouldn't have resorted to such an insult. I could write quite a bit, but I'll desist here. What I posted were not 'try-outs' they were solutions. Your inability to apply them hardly constitutes a 'lack of experience' on my behalf.
Good luck, to anyone that adds to this thread!
-
09-06-2006, 08:17 PM #35Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
Your inability to apply them hardly constitutes a 'lack of experience' on my behalf.
-
09-06-2006, 09:25 PM #36Web Hosting Master
- Join Date
- Aug 2002
- Location
- Canada
- Posts
- 667
My snippets cannot generate the error you've noted. In candor horizon, I'd write that this isn't a popularity contest, I'm just here to lend a hand (it's my relaxation). You've been second guessing everything myself and anyone else has posted, down to an original finger pointing about parenthesization.
Post your entire .php file, and myself or someone else here will take a look I'm certain.
-
09-06-2006, 09:50 PM #37Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
I'd write that this isn't a popularity contest
I'm just here to lend a hand (it's my relaxation).
The entire PHP 'has' been posted entirely already. All I'm doing is renaming those variables into their appropriate names (to avoid copyrighting issues).
In addition to what has been technicly posted before, I have added an extra line with explode (to avoid further errors from the foreach statement - as posted above). Then, I used your foreach statement from the explode variable, rather than the implode variable, and the error doesn't show up anymore.
Althought, it still fails to update the info from the SQL statement. No errors are showing either. It simply returns to it's original page without any modifications over the fields. Everything simply remains as it is.
The good news is, when I uncomment the SQL UPDATE statement, and replace it with echo, (over the imploded variable), the selected IDs are showing up correctly.
-
09-06-2006, 09:53 PM #38the cloud is a lie
- Join Date
- May 2004
- Location
- NYC
- Posts
- 793
There might be a problem here:
Code:if( count( $arr ) ){ foreach( $arr as $id ) $idstr = "'{$id}',"; } $idstr = substr( $idstr, 0, strlen( $idstr ) -1 );
$idstr = "'{$id}';";
Needs a . concatenator character, and should be initialized:
Code:if( count( $arr ) ) { $idstr = ''; foreach( $arr as $id ) $idstr .= "'{$id}',"; } $idstr = substr( $idstr, 0, strlen( $idstr ) -1 );
Code:$idstr = implode(',',$arr);
-
09-06-2006, 09:57 PM #39Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
That said, we can shorten all the code in the above block to:
-
09-06-2006, 10:19 PM #40New Member
- Join Date
- Mar 2005
- Location
- Amboy WA
- Posts
- 2
Some thing you could try is put a line in like echo("My query is: $sql"); just before your query is sent to mysql or some where it will be printed on screen. Then copy that and log in to mysql on the command line and past it in direct query and see what returns. It helps to know if what you think you ar sending is what you think it is.
-
09-07-2006, 01:48 AM #41Web Hosting Master
- Join Date
- Aug 2002
- Location
- Canada
- Posts
- 667
Good eye seaotter, serves me for typing code on my pda. You are correct. The original code block:
Code:if( $row['user_id'] && count( $user_ids ) ){ $idstr = ""; foreach( $user_ids as $id ) $idstr = "'{$id}',"; $idstr = substr( $idstr, 0, strlen( $idstr ) -1 ); //...
Code:if( $row['user_id'] && count( $user_ids ) ){ $idstr = ""; foreach( $user_ids as $id ) $idstr .= "'{$id}',"; $idstr = substr( $idstr, 0, strlen( $idstr ) -1 );
Good eye again though - thanks for that correction.
Horizon:
However, it has almost been three pages - instructed from the first post on what I was trying to accomplish but, unfortunitely, without success so far.
-
09-07-2006, 06:25 AM #42Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
PHP Code:if( $row['user_id'] && count( $user_ids ) ){
$idstr = "";
foreach( $user_ids as $id )
$idstr .= "'{$id}',";
$idstr = substr( $idstr, 0, strlen( $idstr ) -1 );
However, wouldn't this line need to be changed into:
PHP Code:$idstr .= substr( $idstr, 0, strlen( $idstr ) -1 );
-
09-07-2006, 06:32 AM #43Junior Guru Wannabe
- Join Date
- Apr 2004
- Location
- Fullerton, CA
- Posts
- 97
I'll hop back in here really quick. From the knowledge I have gained, it appears that you are storing multiple id's in a string, that is pulled from a mysql database, correct me if I am wrong? This is not a coding issue, it is a design issue, as far as the database goes, I would restructure the database, so each row has it's own controller id.
-
09-07-2006, 08:58 AM #44Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
- it appears that you are storing multiple id's in a string, that is pulled from a mysql database, correct me if I am wrong?
Yes. Correct. This is what has been demonstrated since the first post.
- This is not a coding issue, it is a design issue, as far as the database goes, I would restructure the database, so each row has it's own controller id.
This is what I'm trying to avoid actually. I'd like to create multiple IDs through each ID rows and gain them once required.
P.S: Sorry for the quotes, I'm not actually at my computer and this keyboard is french so it looks kind of bad I know.
-
09-07-2006, 09:03 AM #45Junior Guru Wannabe
- Join Date
- Apr 2004
- Location
- Fullerton, CA
- Posts
- 97
What reasoning do you have to do it like this? This is bad design, for various reasons.
-
09-07-2006, 09:55 AM #46Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
I'm still wondering some topics contains some 'whys' on it. The reason that needs to be done is because of what I'm looking for to accomplish. Simple as that.
-
09-07-2006, 06:55 PM #47Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
I have just tried the latest corrections. The good news is, the foreach error is no longer showing up. The bad bews is, it's not updating the fields at all (or may be it does), the array remains the same in the targeted row and the HTML form is redirecting without affecting the rows.
-
09-07-2006, 08:10 PM #48Web Hosting Evangelist
- Join Date
- Apr 2005
- Posts
- 522
You are trying to accomplish your task by using the wrong logic and wrong design. Since you don't like to be criticised, what's the point in asking for help?
You could have posted your database schema which would help others to help you. And your topic wouldn't expand to 3 pages because you are unable to form a string from an array.
Just a friendly criticism, no hard feelings.
-
09-08-2006, 08:27 AM #49Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
You could have posted your database schema which would help others to help you. And your topic wouldn't expand to 3 pages because you are unable to form a string from an array.
I guess it just didn't came to mind. Sorry about that. Next time, I will post my database schema. It is, indeed, more easier to understand.
-
09-08-2006, 09:06 AM #50Hail Eris !
- Join Date
- Oct 2002
- Location
- Canada
- Posts
- 3,103
Heh, I went through 4 pages and I am still not sure what are you trying to accomplish. It would be good idea to post:
1. HTML form where checkboxes are being checked
2. php code handling that
3. table structure
4. sample data for couple rows you are trying to update
5. echo $query to see what the actual query is
I will not go into design issue.
You are approaching this problem in a wrong way. First thing you should do is manually construct actual mysql query that will update sample row and see if that will work on it's own. Once you have the query working it should be simple thing to have your PHP construct it dynamically.