GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   PHP and MYSQL insert question (https://gfy.com/showthread.php?t=943688)

mkx 12-15-2009 08:49 PM

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 :(

nicedreams 12-15-2009 09:21 PM

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

Bird 12-15-2009 09:52 PM

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.

mkx 12-15-2009 09:58 PM

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 12-15-2009 10:01 PM

Quote:

Originally Posted by Bird (Post 16650887)
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.

phypon 12-15-2009 10:23 PM

loop through the array elements

Bird 12-15-2009 10:25 PM

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].")";
     
          }

}         
?>


mkx 12-15-2009 10:35 PM

Quote:

Originally Posted by Bird (Post 16650948)
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 12-15-2009 10:46 PM

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 12-15-2009 10:50 PM

I think I got all the arrays declared properly, just need to know the insert command

mkx 12-15-2009 10:55 PM

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

Bird 12-15-2009 11:07 PM

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

Killswitch - BANNED FOR LIFE 12-15-2009 11:34 PM

Quote:

Originally Posted by mkx (Post 16650723)
...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 :1orglaugh:1orglaugh:1orglaugh

* PS: this wasn't directed at you, I just hear that sentence all the time.

Bird 12-15-2009 11:47 PM

Quote:

Originally Posted by Killswitch (Post 16651092)
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 :1orglaugh:1orglaugh:1orglaugh

* 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".

mkx 12-15-2009 11:52 PM

Quote:

Originally Posted by Bird (Post 16651066)
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

Killswitch - BANNED FOR LIFE 12-16-2009 12:10 AM

echo $array[2];

Bird 12-16-2009 12:16 AM

Quote:

Originally Posted by mkx (Post 16651125)
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]);


Bird 12-16-2009 12:19 AM

Quote:

Originally Posted by Killswitch (Post 16651146)
echo $array[2];

In that little piece of code I wrote it says $array's' not $array, don;t forget the "S"

Killswitch - BANNED FOR LIFE 12-16-2009 12:37 AM

Quote:

Originally Posted by Bird (Post 16651155)
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.

Bird 12-16-2009 12:38 AM

Quote:

Originally Posted by Killswitch (Post 16651181)
Didn't look at the code, just went by what he asked. How to echo an array.

I know, It was just a note:thumbsup:thumbsup

Bird 12-16-2009 12:40 AM

Dude if you want a free text messaging solution, I have one for you...

http://mobiquio.com/playsms

login:demo and pass:password

mkx 12-16-2009 09:43 AM

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 12-16-2009 09:45 AM

Quote:

Originally Posted by Bird (Post 16651185)
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 12-16-2009 09:49 AM

might have got it, trying it out now :)

mkx 12-16-2009 09:52 AM

Yup got it! Just changed to:

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

Thanks a bunch everyone

potter 12-16-2009 10:12 AM

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. :(

gandalfuy 12-16-2009 11:05 AM

Quote:

Originally Posted by potter (Post 16652300)
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.

mkx 12-16-2009 12:34 PM

hey bird, do you have icq? might have some paid work for you :)

Bird 12-16-2009 01:11 PM

Quote:

Originally Posted by mkx (Post 16652839)
hey bird, do you have icq? might have some paid work for you :)

268731675 just added you


All times are GMT -7. The time now is 05:04 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2026, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123