last day (15 days later) » 

2:13 PM
0
A: How to avoid adding redundant data in SQLite table using php?

devproYour selection is fine, but you need to store result into an variable like: $result = $db->exec("SELECT * FROM Podcast_Export WHERE House_number = '".$value."'"); $rows = $result->fetchArray(); // check no of rows if(count($rows) <= 0){ // if data not exist $db->exec("INSERT INTO Podcast_Exp...

 
The code is not going after the 1st line. I am wondering what is numRows(); in the code above ?
 
@flash using numrows to get no of rows maybe syntax is diff for sqlite isn't it?
 
As soon, I comment this line the page starts loading but when I uncomment it the page doesn't load.
 
@flash u just need to check either query return result or not maybe u need to use diff. Syntax but logic sams
@flash code updated plz check
 
It should be inside the for loop right ?
 
2:13 PM
@flash yes ... ... Right
 
I am using the following code and it didn't work still foreach ($mp4_files as $value) { $result = $db->exec("SELECT * FROM Podcast_Export WHERE House_number = '".$value."'"); $rows = $result->fetchArray(); if(count($rows) <= 0){ // if data not exist $db->exec("INSERT INTO Podcast_Export ('House_number', 'Status') VALUES ('".$value."', 'Go')"); } }
The sqlite_version() I am using is 3.27.2
 
@flash I give u two tricks u just need to fetch count ... What is the result of print_r($rows);exit; use this before count check and share
 
I am getting error at this line $rows = $result->fetchArray(); so I don't think so I would be able to add print_r($rows);exit; to check what is the error.
I did put this ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); in my php script but unfortunately for that page need to load/open.
 
@flash it means u can find the method to get the query result isn't
Search how can I fetch the query result in sqlite ... @flash .. Now I am at home will help in morning
@flash: did u resolved?
 
No, I wasn't able to resolve. I tried many solutions on internet but it didn't work.
 
2:13 PM
@flash: in code, we did a minor mistake here... we forgot to add quotes around SELECT query $result = $db->exec("SELECT * FROM Podcast_Export WHERE House_number = '".$value."'");
@flash: use this line
 
I added that in my codebase.
And if you check my for loop above in the comment section, I already did that.
 
hello
let me chk
listening me???
 
hi
 
thank u, i am checking..
 
Yes, I can see your messages.
 
2:18 PM
foreach ($mp4_files as $value)
{
$result = $db->exec("SELECT * FROM Podcast_Export WHERE House_number = '".$value."'");
$rows = $result->fetchArray();
if(count($rows) <= 0){
$db->exec("INSERT INTO Podcast_Export (House_number, Status) VALUES ('".$value."', 'Go')");
}
}
try now
 
I am getting error at this line. $rows = $result->fetchArray(). As soon as I remove everything from this line $rows = $result->fetchArray() it started working.
 
what is the error
share error
 
That is the issue. I did put this ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); in my php script but unfortunately for that, page need to load/open
 
foreach ($mp4_files as $value)
{
$result = $db->exec("SELECT * FROM Podcast_Export WHERE House_number = '".$value."'");
$rows = $result->fetchArray();exit;
if(count($rows) <= 0){
$db->exec("INSERT INTO Podcast_Export (House_number, Status) VALUES ('".$value."', 'Go')");
}
}
try this, adding exit; this will not load the page
 
The page is blank. Not loading anything.
 
2:27 PM
ok
foreach ($mp4_files as $value)
{
echo "SELECT * FROM Podcast_Export WHERE House_number = '".$value."' <br/>";
}
ignore
foreach ($mp4_files as $value)
{
echo "SELECT * FROM Podcast_Export WHERE House_number = '".$value."' <br/>";
}
exit;
use this and share the result
// start
foreach ($mp4_files as $value)
{
echo "SELECT * FROM Podcast_Export WHERE House_number = '".$value."' <br/>";
}
exit;
// end
 
SELECT * FROM Podcast_Export WHERE House_number = '36031P.mp4'
SELECT * FROM Podcast_Export WHERE House_number = 'hello.mp4'
 
it means, your foreach is fine
now move forward
 
ok
what should I do now?
 
2:43 PM
hi
try this now
// start
foreach ($mp4_files as $value)
{
$result = $db->exec("SELECT * FROM Podcast_Export WHERE House_number = '".$value."'");
var_dump($result);
}
exit;
// end
and share the result
 
bool(true) bool(true)
 
thats good it means, our query is working
now we need to fetch the result
you are using sqlite right?
can u plz share the database file ?
 
sure
 
u can remove password from it or replace with dummy
 
This is my db file. There is only one table in it. Nothing to worry.
 
2:47 PM
ok
// start
foreach ($mp4_files as $value)
{
$result = $db->exec("SELECT * FROM Podcast_Export WHERE House_number = '".$value."'");
while ($row = $result->fetchArray()) {
var_dump($row);
}
}
exit;
// end
try this now
and share the result
 
The page is blank.
 
ok
// start
$result = $db->exec("SELECT * FROM Podcast_Export WHERE House_number = '36031P.mp4'");
while ($row = $result->fetchArray()) {
var_dump($row);
}
exit;
foreach ($mp4_files as $value)
{
$result = $db->exec("SELECT * FROM Podcast_Export WHERE House_number = '".$value."'");
while ($row = $result->fetchArray()) {
var_dump($row);
}
}
exit;
// end
share the result
if still page blank it means, something wrong with fetchArray method with your version.
 
still blank
I am using DB Browser for SQLite to open the SQLite db.
 
// start
foreach ($mp4_files as $value)
{
$result = $db->exec("SELECT * FROM Podcast_Export WHERE House_number = '".$value."'");
echo count($result);
}
exit;
// end
try this, and i hope this willl work
 
this is working
displaying 11
did you check the image above ?
 
3:01 PM
yes i have checked
its working great
// start
foreach ($mp4_files as $value)
{
$result = $db->exec("SELECT * FROM Podcast_Export WHERE House_number = '".$value."'");
if(count($result) <= 0){
$db->exec("INSERT INTO Podcast_Export (House_number, Status) VALUES ('".$value."', 'Go')");
}
}
// end
final code
?
 
The page is loading but it doesn't seem to insert. Let me try
 
because
u have already isnerted this data
remove all data from your database
and run
 
already removed, it is still not getting inserted.
 
// start
foreach ($mp4_files as $value)
{
$result = $db->exec("SELECT * FROM Podcast_Export WHERE House_number = '".$value."'");
if(count($result) <= 0){
echo "enter";
}
}
exit;
// end
run this
sorry,
use this one..
// start
foreach ($mp4_files as $value)
{
$result = $db->exec("SELECT * FROM Podcast_Export WHERE House_number = '".$value."'");
if(count($result) <= 0){
echo "enter";
}
else{
echo "outer";
}
}
exit;
// end
 
3:17 PM
outerouter
But nothing is inside the Podcast_Export
 
and your table is empty?
is Podcast_Export empty?
 
yes its empty
nothing is inside it.
I hope I am seeing it right.
 
yes
// start
foreach ($mp4_files as $value)
{
$result = $db->querySingle("SELECT COUNT(*) as count FROM Podcast_Export WHERE House_number = '".$value."'");
if(count($result) <= 0){
echo "enter";
}
else{
echo "outer";
}
}
exit;
// end
try this
 
Outer Outer
 
my bad
last try
// start
foreach ($mp4_files as $value)
{
$count = $db->querySingle("SELECT COUNT(*) as count FROM Podcast_Export WHERE House_number = '".$value."'");
if($count <= 0){
echo "enter";
}
else{
echo "outer";
}
}
exit;
// end
 
3:28 PM
enterenter
 
perfect
// start
foreach ($mp4_files as $value)
{
$count = $db->querySingle("SELECT COUNT(*) as count FROM Podcast_Export WHERE House_number = '".$value."'");
if($count <= 0){
$db->exec("INSERT INTO Podcast_Export (House_number,Status)
VALUES ('".$value."', 'Go')");
}
}
exit;
// end
 
exit; ?
On removing the exit; page loaded properly.
 
sorry
remove it
great
 
Its working now, thanks for the help.
 
glad to help u , this is also new for me..
dont forgot to acccept and answer and upvote..
 
3:33 PM
thanks for your time. I will do it now.
 
glad to help u tc... if u need more help just comment on my answer.
tc
 
3:56 PM
Sure, I will have a similar question soon. I will let you know once I will post it.
 
 
2 hours later…
5:51 PM
are you around ?
I have a question stackoverflow.com/questions/56690625/… related to sorting. I am wondering if you can have a look.
 

last day (15 days later) »