Checking an array for duplicates on a SQL Table [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I would love a starting point for this problem.
I have a list of IP's retrieved from a source, the IP's along with ID's get stored in a table.
I want to check the table against my array each time it grabs new data, to make sure the array is not putting a duplicate IP in the said table.

Wrong way to think about the problem. Let the database control the data. You can ensure no duplicates by defining a constraint or unique index on the IP column (they are pretty much equivalent):
create unique index unq_iptable_ip on iptable(ip);
Then, if you attempt to insert a duplicate ip, the database won't let you. This ensures data integrity, and the database can do this better than you can (consider what happens if multiple users try to modify the table at the same time).

Related

Update integer and date column to null in Laravel [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I have a table where I want to delete a member from the club but I don't want to delete the member from the database, just leave the member without the club, reason why I'm trying to use patch instead of delete in this case. I tried to set the value to null but it is returning me this error Trying to get property 'NULL' of non-object, is there a way I could do this?
I am not using migrations for the table, it's a table I already had created in postgreSQL, the column I'm trying to edit is nullable.
This is what I'm trying to do:
$trash = null;
Member::where('doc_iden',$id)->update(array(
'id_club'=> $trash,
));
Membresia::where(['id_lec'=>$id,'id_club'=>$idclub,'fec_f'->$trash])->update(array(
'fec_f'=>date('Y-m-d'),
));
I tried to do it with NULL instead of null and setting the value directly without using a variable but I have the same error and I don't know what to do here.
Update: The first bit works, the second doesn't
You have a typo.
'fec_f'->$trash]
should be
'fec_f'=>$trash]

Name for string that holds array? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 3 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Improve this question
I am wondering what the proper name is for an array held in a string (string that holds an array).
Commonly used for storing tags or multiple variables in a database
EXAMPLE 1 (Image URLs for item):
url1,url2,url3
Example 2 (Video Tags): tag1,tag2,tag3
Example 3 (quests complete): 2,3,1,6,7,4
These strings would get converted into an array with an explode in PHP usually.
To clarify: What is the proper name for these types of strings?
These values are stored as comma separated values or CSV. This is a relatively common practice as a way to store multiple data points uder a single entry.
From wikipedia
A comma-separated values (CSV) file is a delimited text file that uses a comma to separate values. A CSV file stores tabular data (numbers and text) in plain text. Each line of the file is a data record. Each record consists of one or more fields, separated by commas. The use of the comma as a field separator is the source of the name for this file format.
Hope this helps,

mysql: how to select with string containing "-" [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
Could someone please point me where did I go wrong?
I've an apps using PHP and mysql. The thing is, we are using some file uploader plugins that require us to save the unique id that has format something like this a41ddc78-3fee-4bf3-88c1-83028ae22f1. At some point, I need to select data from the database using this fields and as you can see, I can't get the field when I do manual query on it. any help is appreciate on how to solve this problem. Thank you
SELECT * FROM product_image WHERE unique_id = 'a41ddc78-3fee-4bf3-88c1-83028ae22f1'
the query works fine...

Best way to save random questions and answers in a MySQL Database [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I have to create a sort of poll with random questions and I wanted to ask you whether the best way to store these random questions in my MySQL db would be
storing the questions as string, which means I would extract via PHP the random questions from the bunch I've got and save them in the database like this
storing the questions' IDs as a string (e.g. "1_2_3_4_5") and then using PHP I get an array out of it using explode() and take out of the array with the questions' texts using the IDs:
Table.
or please suggest me a better method.
Thank you really much, appreciate your support, I hope I explained it clearly and sorry for mistakes.
I'd create a table for Questions and a table for QuestionResponses, at a minimum. QuestionResponses can have a foreign key reference to Questions, along with a VARCHAR(SOMELENGTH) field for storing the response.
I would go with your first option. You can just store the questions as strings in the database, and use php/pdo to randomly select the amount of questions you want per time in an array, then print out the array content randomly. (English is hard sometimes, so i'll explain again)...
Say you want to produce 5 random questions per user that tries to use the application, you can have at least 50 questions in the database stored as string, then "randomly" select 10 questions from the database (this is to avoid selecting all the questions every time or selecting the same set of questions), from the 10 randomly selected questions (which is now in an array), you can randomly print out 5 for the user.
So you have two sets of randomization.
I hope this makes a little sense and helpful too.
I can explain myself better if you have any more questions.
Thank you.

Insert a single value into database table which has multiple columns [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I couldn't find an anwser on google, so here's my question.
Let's say, I have a table which has name,lastName,Age columns.
What I want to do, is insert only "name" into the table.
I have a function
function c_mysqlInsert($ptable,$pvaluename,$pvalue,$database=""){
global $con_dbaccounts;
$dbname = ($database=="")?$con_dbaccounts:$database;
$con = c_dbconnect($dbname);
mysql_query($con,"INSERT INTO $ptable ($pvaluename) VALUES('$pvalue')");
}
/**
which doesn't seem to insert any new things into the $pdbtable, even when $ptable, $pvaluename and $database are all correct. It does connect to the database $database.
I thought it would create a new row with $pvalue and the other columns empty (or NULL), but it doesn't.
So I guess I can't do it this way - call c_mysqlInsert function multiple times to insert into all three columns, so is there any other way I could make this function work?
Your insert statement has the $pdbtable variable but the variable passed into your function is $ptable. Change the variable in your insert and you should be golden.

Categories