|
|
|
||||
|
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. |
![]() |
|
|||||||
| Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
|
Thread Tools |
|
|
#1 |
|
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 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 |
|
|
|
|
|
#2 |
|
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 |
|
|
|
|
|
#3 |
|
Confirmed User
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 |
|
|
|
|
|
#4 |
|
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 />";
Code:
print_r (explode(",\"",$str));
print_r (explode("\"",$str));
echo "<br />";
$peanuts = $array[9];
echo $peanuts;
|
|
|
|
|
|
#5 | |
|
Confirmed User
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
|
Quote:
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. |
|
|
|
|
|
|
#6 |
|
Confirmed User
Join Date: Oct 2003
Posts: 440
|
loop through the array elements
|
|
|
|
|
|
#7 |
|
Confirmed User
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 |
|
|
|
|
|
#8 | |
|
Confirmed User
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
|
Quote:
|
|
|
|
|
|
|
#9 |
|
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 />";
}
}
?>
Code:
$sql = "INSERT INTO modem2 ('zero','one','two','three','four','five') VALUES (".$new[0].",".$new[1].",".$new[2].",".$new[3].",".$new[4].","$new[5].")";
|
|
|
|
|
|
#10 |
|
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
|
|
|
|
|
|
#11 |
|
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 />";
?>
|
|
|
|
|
|
#12 |
|
Confirmed User
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 |
|
|
|
|
|
#13 |
|
Guest
Posts: n/a
|
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. |
|
|
|
#14 | |
|
Confirmed User
Join Date: Jan 2005
Location: Stockton
Posts: 4,365
|
Quote:
__________________
ICQ:268731675 |
|
|
|
|
|
|
#15 | |
|
Confirmed User
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
|
Quote:
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 echo $array(2); echo $array[2]; $array[2] = $hello; echo $hello; etc, just cant seem to figure it out |
|
|
|
|
|
|
#16 |
|
Guest
Posts: n/a
|
echo $array[2];
|
|
|
|
#17 | |
|
Confirmed User
Join Date: Jan 2005
Location: Stockton
Posts: 4,365
|
Quote:
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 |
|
|
|
|
|
|
#18 |
|
Confirmed User
Join Date: Jan 2005
Location: Stockton
Posts: 4,365
|
In that little piece of code I wrote it says $array's' not $array, don;t forget the "S"
__________________
ICQ:268731675 |
|
|
|
|
|
#19 |
|
Guest
Posts: n/a
|
|
|
|
|
#20 | |
|
Confirmed User
Join Date: Jan 2005
Location: Stockton
Posts: 4,365
|
Quote:
__________________
ICQ:268731675 |
|
|
|
|
|
|
#21 |
|
Confirmed User
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 |
|
|
|
|
|
#22 |
|
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]);
?>
|
|
|
|
|
|
#23 | |
|
Confirmed User
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
|
Quote:
|
|
|
|
|
|
|
#24 |
|
Confirmed User
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
|
might have got it, trying it out now
|
|
|
|
|
|
#25 |
|
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 |
|
|
|
|
|
#26 |
|
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.
__________________
![]() |
|
|
|
|
|
#27 |
|
Confirmed User
Join Date: Jun 2005
Location: Montevideo, Uruguay.
Posts: 4,686
|
He got his answer though.
__________________
I'm not back. |
|
|
|
|
|
#28 |
|
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
|
|
|
|
|
|
#29 |
|
Confirmed User
Join Date: Jan 2005
Location: Stockton
Posts: 4,365
|
268731675 just added you
__________________
ICQ:268731675 |
|
|
|