88 Replies
what does "nothing" mean?
at first glance it looks like you're trying to use something like
%123.45%
as a number and that is not a number
the %
symbols are used as wildcards for text search, they aren't valid for numbersi copied a youtube video
its meant to get the user input e.g 400 and get the data from the database which matches 400 or less
you don't need %% for that
what shall i put where the error is
you wrote searchPriceCPU, but the parameter is searchTermCPU
omg i think it worked
i have been trying to figure this out for weeks
...weeks?
💀
thank you so much i owe you my life
i am new to this.
maybe you should go through some SQL tutorials so you understand what you're writing
perhaps chatgpt may have helped you xD
no
chatgpt is awful for beginners
believe me it did not
in order to use LLMs effectively you have to be able to tell good code from bad code
and beginners don't have that experience
it's just as likely to tell them some made up garbage that won't work as give them an actual answer
ur right, i was just saying that chatgpt may have pointed out that the variable names were incorrect
yes it did not help at all
i am trying to do a big project
and i have been given an extension because it is so bad
small steps lol
i don't want to let you down, but the way you're coding this does not follows today's standards
my teacher doesn't help at all, i have to teach myself and idk where to go or what to do
if it's a school project then raw dogging ADO.NET is expected tbh
ah, then okay
school courses are behind the times
i did connect it to my database and created a database on my own though
brownie points for me
i was shown this recently https://sqlbolt.com/
SQLBolt - Learn SQL - Introduction to SQL
SQLBolt provides a set of interactive lessons and exercises to help you learn SQL
it's not specific to mysql but it might help you understand the queries you're writing
ye it's okay, but if you want to do this as a professional after school, you should expand your knowledge to more modern approaches
i have actually never been so happy
i want to do this after school but i am shit at computer science
nobody is born knowing everything
you can only get better with practice :bless:
very true
do you guys want to help with other aspects of my project
fine if not
may as well ask
try to solve things on your own first. if you get stuck, just open a new post with the underlying problem
believe me i have i don't know where to start
what do you have to do?
it has to take the budget, purpose and age into consideration and depending on all of those things will depend on the output
for example
budget: 600 purpose: gaming age: 21
it should output where everything is under a certain amount, the CPU is AMD for gaming
age doesn't really matter
ye that's what i was about to say
why is there age in the first place xD
it matters in my analysis
i spoke about age a lot in the analysis
this is 20% of my a level
which is what determines what apprenticeship i get
do you have an idea on how to distribute the price evenly
e.g the cpu gets 45%
the gpu gets 30%
and the ram gets 25%
you mean of the budget?
yes
sounds like just math
take the budget and compute that % of it
probably you won't find a solution that matches your budget 100%
almost definitely wont
yes but if the budget is 600
you have to get the closest solution
it'll get all the CPU's which are 200 and less
is what i want it to do
yeah that's just math
im unsure how to code maths
if you consider a percentage as a number from 0 to 1 you can use it as a multiplier
like 50% of 100 -> 100 * 0.50 -> 50
so if i do CPUAmount = textBox1.text
how would i factor that into searching that
wait no
you can't just get the text
you'll need to convert the text into a number before you can do math on it
$tryparse
When you don't know if a string is actually a number when handling user input, use
int.TryParse
(or variants, e.g. double.TryParse
)
TryParse
returns a bool
, where true
indicates successful parsing.
Remarks:
- Avoid int.Parse
if you do not know if the value parsed is definitely a number.
- Avoid Convert.ToInt32
entirely, this is an older method and Parse
should be preferred where you know the string can be parsed.
Read more herei usually do newvariablename = Convert.ToInt32(variablename)
that's an old and wrong way
:/
tryparse is better
you can show an error if the text is not a number
the thing i pasted above says what to use and when
and you don't necessarily want an int, prices have a decimal point and ints can only represent whole numbers
did not think about that
will it be able to search through the database if the datatype for the price for the components is int32
if the type in your database is also int then you might as well use ints everywhere
or change the database
i can change the database
i did it before
i'd do that just because prices aren't always full dollar amounts
in some countries they are 🤓 ☝️
yeah i just rounded the prices
okay so
i need to create 3 variables making the % i want into decimals
timesing the amount
then searching for that number
you probably want the first item you get from the query
what does that mean
the query returns many records
you just get the first one
i still don't understand
so, if you want to find the best cpu what would you do?
what is the query you'd write?
SELECT * FROM ram WHERE price @search => x 0.4
that was a guess
that is not valid sql.. why is @search there
that is what gets the userinput
i think
SELECT * FROM ram WHERE price <= (@search * 0.4)
perhaps something like this
it is unclear what you wanna do here
oh
i was kind of close though
i think percentage wise
40% for CPU
40% for GPU
20% for RAM
in any case this query will not return just one output
it will return a list
okay how do we make it return the top one
or the priciest
SELECT * FROM ram WHERE price <= (@search * 0.4) order by price desc
and you will get the first item of the list
it didnt like that
sorry i missed a thing xD
order by price desc will order the elements in the output list from the pricest to the cheapest
oh i see
if you want from the cheapest to the pricest, you do
order by price asc
it came up with the same result
i did change it from 0.4 to 0.2
im not too bothered at least it works
thank you
🫡