Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 12-15-2009, 08:49 PM   #1
mkx
Confirmed User
 
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
PHP and MYSQL insert question

I have the following modem response being inserted into a field on a mysql database:

This is the complete contents of the field:
Code:
AT+SSS="SHOW"

+CT: 0,"OK","+974941949",,"09/12/15,03:06:18+00"
Sup
+CT: 1,"OK","+974941949",,"09/12/15,14:26:36+00"
Yo
+CT: 2,"OK","+974941949",,"09/12/15,22:30:51+00"
Test
OK
I want to automatically reinsert certain parts of this field into a new table (called modem2 lets say) and divide them into 5 different fields

FIELD NAMES =
CT, STATUS, FROM, TIME, MESSAGE

EXAMPLE FIELD INSERTIONS
0, OK, +974941949, 09/12/15,03:06:18+00, Sup
1, OK, +974941949, 09/12/15,14:26:36+00, Yo


Anyone know how or where I can find out how to do this? Seems pretty simple if I only knew a bit more php
mkx is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-15-2009, 09:21 PM   #2
nicedreams
Confirmed User
 
Industry Role:
Join Date: Apr 2004
Location: Metro DC Area
Posts: 298
Well, assuming you know how to split the fields up and know your mysql insert statement?

You would use the mysql_query function with your mysql statement.


http://us3.php.net/manual/en/function.mysql-connect.php

http://us3.php.net/manual/en/function.mysql-query.php

http://us3.php.net/manual/en/function.mysql-close.php

Jimmy
__________________

Nice Dreams Cash
http://www.nicedreamscash.com
nicedreams is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-15-2009, 09:52 PM   #3
Bird
Confirmed User
 
Bird's Avatar
 
Join Date: Jan 2005
Location: Stockton
Posts: 4,365
What are you trying to do???


Do you need to parse the output first or do you just want to build the SLQ insert funtion into the page.
__________________
ICQ:268731675
Bird is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-15-2009, 09:58 PM   #4
mkx
Confirmed User
 
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
I just learned over the last hour how to split the fields. Now I have array [0] to array [19] outputted with the following script:

Code:
print_r (explode(",\"",$str));
print_r (explode("\"",$str));
echo "<br />";
I now need to know how to declare say array[9] as $peanuts and echo it. From there I can figure out how to put it in the database. Tried code below but didn't work

Code:
print_r (explode(",\"",$str));
print_r (explode("\"",$str));
echo "<br />";

$peanuts = $array[9];
echo $peanuts;
mkx is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-15-2009, 10:01 PM   #5
mkx
Confirmed User
 
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
Quote:
Originally Posted by Bird View Post
What are you trying to do???


Do you need to parse the output first or do you just want to build the SLQ insert funtion into the page.
Just basically trying to take something from a field in my database that says hello, my, namell is ##fred and insert it back into a new table

field1 field2 field3 field4 field5
hello my name is fred

Think i figured out the php explode / split thing, just need to get the correct results back in the database now.
mkx is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-15-2009, 10:23 PM   #6
phypon
Confirmed User
 
Join Date: Oct 2003
Posts: 440
loop through the array elements
phypon is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-15-2009, 10:25 PM   #7
Bird
Confirmed User
 
Bird's Avatar
 
Join Date: Jan 2005
Location: Stockton
Posts: 4,365
Oh, I see. You will get it...this is where we all start with php. You should look at W3schools or tiztag for tutorials.

I wrote something real quick for your AT commands but not sure how exactly it would work for you. But should give you some Idea

Code:
<?php 
$contents = file_get_contents("at.php");
$arrays = explode('+CT:', $contents);
print_r($arrays)."<hr />";
//mysql_query($connect);

	  
foreach($arrays as $value){
$i = 0;
print_r($value)."<hr />";


   for($i=0; $i < count($value); $i++) {
     $new = explode(',',$value);
         echo $new[1]. "|" .$new[2]."|".$new[3]."|".$new[4]."|".$new[5]."<br />";
        //$sql = "INSERT INTO modem2 (CT,STATUS,FROM,TIME,MESSAGE) VALUES (' ',".$new[1].",".$new[2].","$new[3].")";
      
	  }

}	  
?>
__________________
ICQ:268731675

Last edited by Bird; 12-15-2009 at 10:29 PM..
Bird is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-15-2009, 10:35 PM   #8
mkx
Confirmed User
 
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
Quote:
Originally Posted by Bird View Post
Oh, I see. You will get it...this is where we all start with php. You should look at W3schools or tiztag for tutorials.

I wrote something real quick for your AT commands but not sure how exactly it would work for you. But should give you some Idea

Code:
<?php 
$contents = file_get_contents("at.php");
$arrays = explode('+CT:', $contents);
print_r($arrays)."<hr />";
//mysql_query($connect);

	  
foreach($arrays as $value){
$i = 0;
print_r($value)."<hr />";


   for($i=0; $i < count($value); $i++) {
     $new = explode(',',$value);
         echo $new[1]. "|" .$new[2]."|".$new[3]."|".$new[4]."|".$new[5]."<br />";
        //$sql = "INSERT INTO modem2 (CT,STATUS,FROM,TIME,MESSAGE) VALUES (' ',".$new[1].",".$new[2].","$new[3].")";
      
	  }

}	  
?>
Thanks dude, working with that code now, will update in 10
mkx is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-15-2009, 10:46 PM   #9
mkx
Confirmed User
 
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
hmm i got this to separate the thing into 15 arrays, 5 per message,

Code:
<?php
include 'dbconnect.php';

$query  = "SELECT * FROM messages WHERE id=43";
$result = mysql_query($query);


while($row = mysql_fetch_array($result))
  {
  $str = $row['message'];
}

$arrays = explode(',', $str);
print_r($arrays)."<hr />";

//mysql_query($connect);

	  
foreach($arrays as $value){
$i = 0;
print_r($value)."<hr />";


   for($i=0; $i < count($value); $i++) {
     $new = explode(',',$value);
         echo $new[0]. "|" .$new[1]."|".$new[2]."|".$new[3]."|".$new[4]."|".$new[5]."<br />";


	  }

}	  
?>
doesn't seem to work with the insert command

Code:
  $sql = "INSERT INTO modem2   ('zero','one','two','three','four','five') VALUES (".$new[0].",".$new[1].",".$new[2].",".$new[3].",".$new[4].","$new[5].")";
had to modify it a bit to get it working.
mkx is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-15-2009, 10:50 PM   #10
mkx
Confirmed User
 
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
I think I got all the arrays declared properly, just need to know the insert command
mkx is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-15-2009, 10:55 PM   #11
mkx
Confirmed User
 
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
Code:
<?php
include 'dbconnect.php';



$query  = "SELECT * FROM messages WHERE id=43";
$result = mysql_query($query);


while($row = mysql_fetch_array($result))
  {
  $str = $row['message'];
  }


print_r (explode(",\"",$str));
print_r (explode("\"",$str));
echo "<br />";

?>
This code does the splits just fine, splits it into 20 arrays as it does it twice. I just need to say now that array[11] = $peanuts and i will be good to go
mkx is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-15-2009, 11:07 PM   #12
Bird
Confirmed User
 
Bird's Avatar
 
Join Date: Jan 2005
Location: Stockton
Posts: 4,365
Don't forget the ID key value for the tables next increment...if tour db reads

1 ok name number from to message
2 ok name number from to message
3 ok name number from to message
...

88 ok name number from to message
89 ok name number from to message

then the next input would fill automatically.

INSERT INTO modem2 ('id','zero','one') VALUES ('DELETETHIS', ".$new[0].",".$new[1].")";

see how the first value is blank, it would automatically populate id's next entry

90 ok name number from to message
91 ok name number from to message
__________________
ICQ:268731675

Last edited by Bird; 12-15-2009 at 11:08 PM..
Bird is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-15-2009, 11:34 PM   #13
Killswitch - BANNED FOR LIFE
Guest
 
Posts: n/a
Quote:
Originally Posted by mkx View Post
...Seems pretty simple if I only knew a bit more php
I love when newbies or people who don't know shit about PHP think, oh it's simple and should be easy for anyone!

"I need Google recreated, you're pretty good, should be simple and easy for you, how long you think it will take? 10 mins?"

Makes me

* PS: this wasn't directed at you, I just hear that sentence all the time.
  Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-15-2009, 11:47 PM   #14
Bird
Confirmed User
 
Bird's Avatar
 
Join Date: Jan 2005
Location: Stockton
Posts: 4,365
Quote:
Originally Posted by Killswitch View Post
I love when newbies or people who don't know shit about PHP think, oh it's simple and should be easy for anyone!

"I need Google recreated, you're pretty good, should be simple and easy for you, how long you think it will take? 10 mins?"

Makes me

* PS: this wasn't directed at you, I just hear that sentence all the time.
I'm cool with people wanting to get started with php its those businesses that think "hey can you make me a myspace type site".
__________________
ICQ:268731675
Bird is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-15-2009, 11:52 PM   #15
mkx
Confirmed User
 
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
Quote:
Originally Posted by Bird View Post
Don't forget the ID key value for the tables next increment...if tour db reads

1 ok name number from to message
2 ok name number from to message
3 ok name number from to message
...

88 ok name number from to message
89 ok name number from to message

then the next input would fill automatically.

INSERT INTO modem2 ('id','zero','one') VALUES ('DELETETHIS', ".$new[0].",".$new[1].")";

see how the first value is blank, it would automatically populate id's next entry

90 ok name number from to message
91 ok name number from to message

hmm still having problems. how do I just echo a certain array. I got it to output:
Code:
Array ( [0] => 0 [1] => OK" [2] => +974941949", [3] => 09/12/15,03:06:18+00
So say I wanted to echo array 2 (+974941949), how would I echo it? I tried several variations such as
echo $array(2);
echo $array[2];
$array[2] = $hello; echo $hello;

etc, just cant seem to figure it out
mkx is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-16-2009, 12:10 AM   #16
Killswitch - BANNED FOR LIFE
Guest
 
Posts: n/a
echo $array[2];
  Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-16-2009, 12:16 AM   #17
Bird
Confirmed User
 
Bird's Avatar
 
Join Date: Jan 2005
Location: Stockton
Posts: 4,365
Quote:
Originally Posted by mkx View Post
hmm still having problems. how do I just echo a certain array. I got it to output:
Code:
Array ( [0] => 0 [1] => OK" [2] => +974941949", [3] => 09/12/15,03:06:18+00
So say I wanted to echo array 2 (+974941949), how would I echo it? I tried several variations such as
echo $array(2);
echo $array[2];
$array[2] = $hello; echo $hello;

etc, just cant seem to figure it out


Replace

$arrays with $arrays[3]

Code:
$contents = file_get_contents("at.php");
$arrays = explode('+CT:', $contents);
//print_r($arrays);
print_r($arrays[3]);
__________________
ICQ:268731675
Bird is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-16-2009, 12:19 AM   #18
Bird
Confirmed User
 
Bird's Avatar
 
Join Date: Jan 2005
Location: Stockton
Posts: 4,365
Quote:
Originally Posted by Killswitch View Post
echo $array[2];
In that little piece of code I wrote it says $array's' not $array, don;t forget the "S"
__________________
ICQ:268731675
Bird is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-16-2009, 12:37 AM   #19
Killswitch - BANNED FOR LIFE
Guest
 
Posts: n/a
Quote:
Originally Posted by Bird View Post
In that little piece of code I wrote it says $array's' not $array, don;t forget the "S"
Didn't look at the code, just went by what he asked. How to echo an array.
  Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-16-2009, 12:38 AM   #20
Bird
Confirmed User
 
Bird's Avatar
 
Join Date: Jan 2005
Location: Stockton
Posts: 4,365
Quote:
Originally Posted by Killswitch View Post
Didn't look at the code, just went by what he asked. How to echo an array.
I know, It was just a note
__________________
ICQ:268731675
Bird is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-16-2009, 12:40 AM   #21
Bird
Confirmed User
 
Bird's Avatar
 
Join Date: Jan 2005
Location: Stockton
Posts: 4,365
Dude if you want a free text messaging solution, I have one for you...

http://mobiquio.com/playsms

login:demo and pass:password
__________________
ICQ:268731675
Bird is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-16-2009, 09:43 AM   #22
mkx
Confirmed User
 
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
I tried with the 'S" and it still won't print the result

Code:
<?php
include 'dbconnect.php';



$query  = "SELECT * FROM messages WHERE id=43";
$result = mysql_query($query);


while($row = mysql_fetch_array($result))
  {
  $str = $row['message'];
  }


print_r (explode(",\"",$str));
print_r (explode("\"",$str));



echo $arrays[3];
echo $arrays[4];
print_r($arrays[5]);


?>
mkx is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-16-2009, 09:45 AM   #23
mkx
Confirmed User
 
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
Quote:
Originally Posted by Bird View Post
Dude if you want a free text messaging solution, I have one for you...

http://mobiquio.com/playsms

login:demo and pass:password
It's a bit more complicated
mkx is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-16-2009, 09:49 AM   #24
mkx
Confirmed User
 
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
might have got it, trying it out now
mkx is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-16-2009, 09:52 AM   #25
mkx
Confirmed User
 
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
Yup got it! Just changed to:

$arrays = (explode(",\"",$str));
$arrays = (explode("\"",$str));

Thanks a bunch everyone
mkx is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-16-2009, 10:12 AM   #26
potter
Confirmed User
 
Industry Role:
Join Date: Dec 2004
Location: Denver
Posts: 6,559
Man, this thread should have been over in like 1-2 replies. Talk about your basic basic programming function, It's so sad it took 25.

I guess that's what you get on a webmaster board.
__________________

potter is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-16-2009, 11:05 AM   #27
gandalfuy
Confirmed User
 
gandalfuy's Avatar
 
Join Date: Jun 2005
Location: Montevideo, Uruguay.
Posts: 4,686
Quote:
Originally Posted by potter View Post
Man, this thread should have been over in like 1-2 replies. Talk about your basic basic programming function, It's so sad it took 25.

I guess that's what you get on a webmaster board.
He got his answer though.
__________________
I'm not back.
gandalfuy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-16-2009, 12:34 PM   #28
mkx
Confirmed User
 
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
hey bird, do you have icq? might have some paid work for you
mkx is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-16-2009, 01:11 PM   #29
Bird
Confirmed User
 
Bird's Avatar
 
Join Date: Jan 2005
Location: Stockton
Posts: 4,365
Quote:
Originally Posted by mkx View Post
hey bird, do you have icq? might have some paid work for you
268731675 just added you
__________________
ICQ:268731675
Bird is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.