djdellux Posted December 4, 2008 Share Posted December 4, 2008 how do i combine these to start a viewer for VoIP phone call data <?php $dbvoip = sqlite_open('voip.sqlite'); if ($dbvoip == false) { die ('Unable to open database'); } else { echo 'Database created.'; } $dbquery = 'INSERT INTO voip () VALUES ()'; $dbresult = sqlite_query($dbvoip, $dbquery); sqlite_close($dbvoip) ?> <?PHP $dbinfo=file("master.csv"); foreach ($dbinfo as $value) { echo $value . "<br />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/135501-get-it-going-mates/ Share on other sites More sharing options...
.josh Posted December 4, 2008 Share Posted December 4, 2008 what are your column names for your 'voip' table, give some example lines in your csv file, and what parts of each line belong to what column in your table. Quote Link to comment https://forums.phpfreaks.com/topic/135501-get-it-going-mates/#findComment-705904 Share on other sites More sharing options...
Mchl Posted December 4, 2008 Share Posted December 4, 2008 Too little data. Question unclear. Answer impossible. What do you actually want? Quote Link to comment https://forums.phpfreaks.com/topic/135501-get-it-going-mates/#findComment-705906 Share on other sites More sharing options...
djdellux Posted December 4, 2008 Author Share Posted December 4, 2008 here is an example of the excel/csv tbl C0 number1 number2 type number3 linetype c1 dial c2 date1 date2 date3 c3 c4 anw DOCUMENTATION unix C17 18005673786 15867569100 internal 18005673786 SIP/PTIline1-08f109b8 IAX2/rapidvox-5145 Dial IAX2/rapidvox/15867569100,,T 11/13/2008 14:20 11/13/2008 14:20 11/13/2008 14:20 18 5 ANSWERED DOCUMENTATION 1226586019 PTIline1 s default PTIline1 IAX2/atl-its02-14375 11/13/2008 14:22 11/13/2008 14:22 11/13/2008 14:22 1 0 ANSWERED DOCUMENTATION 1226586152 PTIline1 1517 internal "PTIline1" <PTIline1> SIP/PTIline1-08f109b8 IAX2/atl-its02-14375 Dial SIP/CSEline4,,D(1517) 11/13/2008 14:22 11/13/2008 14:22 11/13/2008 14:22 3 2 ANSWERED DOCUMENTATION 1226586152 PTIline1 1517 internal "PTIline1" <PTIline1> SIP/PTIline1-08f109b8 IAX2/atl-its02-3090 Dial SIP/CSEline4,,D(1517) 11/13/2008 14:25 11/13/2008 14:25 11/13/2008 14:25 3 2 ANSWERED DOCUMENTATION 1226586343 PTIline1 1517 internal "PTIline1" <PTIline1> SIP/PTIline1-08f109b8 IAX2/atl-its02-10920 Dial SIP/CSEline4,,D(1517) 11/13/2008 14:27 11/13/2008 14:27 11/13/2008 14:27 3 2 ANSWERED DOCUMENTATION 1226586431 PTIline1 s default PTIline1 IAX2/atl-its02-7470 11/13/2008 14:27 11/13/2008 14:27 11/13/2008 14:27 1 0 ANSWERED DOCUMENTATION 1226586464 PTIline1 1517 internal "PTIline1" <PTIline1> SIP/PTIline1-08f23418 IAX2/cse-its04-11584 Dial SIP/CSEline4,,D(1517) 11/13/2008 14:27 11/13/2008 14:27 11/13/2008 14:27 3 2 ANSWERED DOCUMENTATION 1226586464 PTIline1 s default PTIline1 IAX2/atl-its02-12742 11/13/2008 14:29 11/13/2008 14:29 11/13/2008 14:29 1 0 ANSWERED DOCUMENTATION 1226586570 PTIline1 1517 internal "PTIline1" <PTIline1> SIP/PTIline1-08f23418 IAX2/cse-its04-12179 Dial IAX2/cse-its04/1517,20,tTg 11/13/2008 14:29 11/13/2008 14:29 11/13/2008 14:29 10 9 ANSWERED DOCUMENTATION 1226586570 excuse th crudeness im really busy and multitaskin like a mad man sorry guys Quote Link to comment https://forums.phpfreaks.com/topic/135501-get-it-going-mates/#findComment-705925 Share on other sites More sharing options...
Mchl Posted December 4, 2008 Share Posted December 4, 2008 What do you actually want? Quote Link to comment https://forums.phpfreaks.com/topic/135501-get-it-going-mates/#findComment-705929 Share on other sites More sharing options...
.josh Posted December 4, 2008 Share Posted December 4, 2008 You need to put your $dbquery and $dbresult inside your foreach loop. You need to put your column names in the first () in your $dbquery. You also need to take the $value in your foreach loop and explode it and then implode it into a comma separated list of values (don't forget to put quotes around them). Then you will put that in the second () of your $dbquery. Make sure your list of values are in the same order as your columns like so: insert into voip (column1, column2, column3, etc.. values (value1, value2, value3, etc...) Quote Link to comment https://forums.phpfreaks.com/topic/135501-get-it-going-mates/#findComment-705944 Share on other sites More sharing options...
djdellux Posted December 4, 2008 Author Share Posted December 4, 2008 ok well im a little off with the explode\implode stuff heres what i have so far <?php $dbvoip = sqlite_open('voip.sqlite'); if ($dbvoip == false) { die ('Unable to open database'); } else { echo 'Database created.'; } $dbinfo=file("master.csv"); foreach ($dbinfo as $line) { echo $line; } $dbquery = 'INSERT INTO voip (C0, number1, number2, type, number3, linetype, c1, dial, c2, date1, date2, date3, c3, c4, anw, DOCUMENTATION, unix, C17) VALUES (' . $var1 . ',' . $var2 . ',' . $var3 . ',' . $var4 . ',' . $var5 . ',' . $var6 . ', ' . $var7 . ',' . $var8 . ' ,' . $var9 . ' ,' . $var10 . ',' . $var11 . ',' . $var12 . ',' . $var13 . ',' . $var14 . ',' . $var15 . ',' . $var16 . ',' . $var17 . ',' . $var18 . ')'; $dbresult = sqlite_query($dbvoip, $dbquery); sqlite_close($dbvoip) ?> i know thats what i should use but im not sure how Quote Link to comment https://forums.phpfreaks.com/topic/135501-get-it-going-mates/#findComment-706148 Share on other sites More sharing options...
djdellux Posted December 4, 2008 Author Share Posted December 4, 2008 outa here for the day have a good one gents and ill check back in the A.M.<><><>><><><> till then..... Quote Link to comment https://forums.phpfreaks.com/topic/135501-get-it-going-mates/#findComment-706184 Share on other sites More sharing options...
djdellux Posted December 5, 2008 Author Share Posted December 5, 2008 any input on this code criticism is always welcome <?php $dbvoip = sqlite_open('voip.sqlite'); if ($dbvoip == false) { die ('Unable to open database'); } else { echo 'Database created.'; } $dbinfo=file("master.csv"); foreach ($dbinfo as $line) { echo $line; } $dbquery = explode(" ", $var); for($i = 0; $i < count($var); $i++){ echo "$i = $var[$i] <br />"; $dbquery = 'INSERT INTO voip (C0, number1, number2, type, number3, linetype, c1, dial, c2, date1, date2, date3, c3, c4, anw, DOCUMENTATION, unix, C17) VALUES (' . $var1 . ',' . $var2 . ',' . $var3 . ',' . $var4 . ',' . $var5 . ',' . $var6 . ', ' . $var7 . ',' . $var8 . ' ,' . $var9 . ' ,' . $var10 . ',' . $var11 . ',' . $var12 . ',' . $var13 . ',' . $var14 . ',' . $var15 . ',' . $var16 . ',' . $var17 . ',' . $var18 . ')'; } sqlite_close($dbvoip) ?> Quote Link to comment https://forums.phpfreaks.com/topic/135501-get-it-going-mates/#findComment-706690 Share on other sites More sharing options...
.josh Posted December 5, 2008 Share Posted December 5, 2008 foreach ($dbinfo as $line) { echo $line; $dbquery = explode(" ", $line); $data = "'" . implode("','",$dbquery) . "'"; $dbquery = "INSERT INTO voip (C0, number1, number2, type, number3, linetype, c1, dial, c2, date1, date2, date3, c3, c4, anw, DOCUMENTATION, unix, C17) VALUES ($data)"; // ^ just creates the query string. You need to actually insert it into db with mysql_query or whatever function for the db you're using } Quote Link to comment https://forums.phpfreaks.com/topic/135501-get-it-going-mates/#findComment-706735 Share on other sites More sharing options...
djdellux Posted December 5, 2008 Author Share Posted December 5, 2008 thx I'm actually using sqlite and like i said early in the post i am just not familiar with it how would i go bout that?? Quote Link to comment https://forums.phpfreaks.com/topic/135501-get-it-going-mates/#findComment-706746 Share on other sites More sharing options...
.josh Posted December 5, 2008 Share Posted December 5, 2008 thanks I'm actually using sqlite and like i said early in the post i am just not familiar with it how would i go bout that?? The documentation in the manual explains it a lot better than I ever could. Quote Link to comment https://forums.phpfreaks.com/topic/135501-get-it-going-mates/#findComment-706785 Share on other sites More sharing options...
djdellux Posted December 5, 2008 Author Share Posted December 5, 2008 wow wtf is goin on.... im getting this error Database created. Notice: Undefined variable: data in c:\program files\Apache\htdocs\csv2.php on line 15 Warning: implode() [function.implode]: Bad arguments. in c:\program files\Apache\htdocs\csv2.php on line 19 Warning: implode() [function.implode]: Bad arguments. in c:\program files\Apache\htdocs\csv2.php on line 19 Warning: implode() [function.implode]: Bad arguments. in c:\program files\Apache\htdocs\csv2.php on line 19 Warning: implode() [function.implode]: Bad arguments. in c:\program files\Apache\htdocs\csv2.php on line 19 heres the code <?php $dbvoip = sqlite_open('voip.sqlite'); if ($dbvoip == false) { die ('Unable to open database'); } else { echo 'Database created.'; } $dbinfo=file("master.csv"); foreach ($dbinfo as $line) { $data = "'" . implode("','",$dbquery) . "'"; //print_r($dbquery); $dbquery = "INSERT INTO voip (C0, number1, number2, type, number3, linetype, c1, dial, c2, date1, date2, date3, c3, c4, anw, DOCUMENTATION, unix, C17) VALUES ($data)"; } sqlite_close($dbvoip) ?> its driving my nuts help a newbie out man Quote Link to comment https://forums.phpfreaks.com/topic/135501-get-it-going-mates/#findComment-706932 Share on other sites More sharing options...
.josh Posted December 5, 2008 Share Posted December 5, 2008 Dude come on, I understand you may be a "newbie" to php, but you need to try harder, use some logic. Use some common sense. Look at the error message. It says your implode has a bad argument. So look at the arguments in your implode(). "','" and $dbquery If you look at implode in the manual, you will see that the first argument is a string that will act like glue, and the 2nd argument is an array to glue together. Since a string can be anything, chances are the bad argument is your $dbquery. So look at $dbquery. Where is it coming from? Look at your code. You don't assign anything to $dbquery before that implode. Therefore, you are passing a bad argument. Why did you take this line... $dbquery = explode(" ", $line); ... out from the code? That takes the current line in your foreach loop and explodes it into an array: the array you need for the implode. And even after all that is done, your code still will only generate a query string. It's not actually inserting it into your database. Read the documentation. I promise you, I don't mean to sound harsh. But if you're wanting to do this in an effort to learn php in general, I suggest you put this project on hold and back up a few steps and start with the basics. Syntax, etc... If you're just trying to do this in an effort to get a project done for your boss or something, and don't really have a desire to learn php in general, I suggest you consider just forking over a few bucks and having someone else do it for you, because (again, nothing personal) you're trying to work at level B when you haven't really learned level A. Even if you do manage to bluff your way through it, you're not going to understand what's going on and that can potentially be a very, very bad thing. I mean, you're struggling with just getting it to work. You probably haven't even considered how to make it secure, so someone doesn't come along and wtfpwn your database. Quote Link to comment https://forums.phpfreaks.com/topic/135501-get-it-going-mates/#findComment-706970 Share on other sites More sharing options...
djdellux Posted December 5, 2008 Author Share Posted December 5, 2008 Crayon Violent<><><> chk ur msgs and the line of code $dbquery =explode("','", $line); its till in there i was messin wit the stuf and when i posted it to the forum i must have left it out... Quote Link to comment https://forums.phpfreaks.com/topic/135501-get-it-going-mates/#findComment-707063 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.