/    Sign up×
Community /Pin to ProfileBookmark

George, this doesn’t add up? I don’t get it, it will not add.

Alright… I’m like smashing my head into a brick wall over and over again every time I hit refresh and I don’t see 123098

So I created an arbitrary 6 digit number to start with, this is a “repair code” for customers and I figured it’s better to have a large number rather than 1 eg. “Hey, you’re my first customer, good luck.”

Anyway, first, I don’t know when to use quotes. If said

[code=php]$sql = “SQL COUNT Column From Table”[/code]

; what would that give me? A string or the value? I would think a string.

I also had a problem of converting an integer to a string, I’m not trying to, but my method of displaying the number which is stored as an Int seems to want to convert to a string.

This is my “code” so far, (garbage)
Login info ommitted
There is currently one row that exists, which has the Rc (repair code) 123097
It is actually auto incremented per entry but my attempts of using LAST was not getting anywhere so I decided to just add 1 to the last value which I’m going to do by taking the base number 123097 and adding the count / number of rows that exist. Seems dumb I know…

[code=php]<?php
error_reporting(E_ALL);
error_reporting(-1);

$servername = “localhost”;
$username = ” “;
$password = ” “;
$dbname = ” “;

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
$count = “SQL COUNT(*) FROM computers”;
$result = $conn->query($count);
$base = 123097;
$number = $count + $base;
$sql = $number;
echo (int) $number;
?>[/code]

Any help would be greatly appreciated…

What I’m trying to accomplish isn’t hard, it’s the syntax… the syntax which taxes my parallax of my desire and inability

I want a repair code that people enter into my website and this gives them a status update, the status page spits out their info and a status update / color (eg. yellow = in progress). My websit is very simple… but my mind is also simple.

Thank you for your time in reading this collection of text.

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@GreenAce92authorDec 14.2014 — Yeah it should echo $sql but it would have been the same ( I did miss that )
Copy linkTweet thisAlerts:
@Stephen_PhilbinDec 14.2014 — What I think you're asking for seems to fit the description of an "auto increment column" in a database. Basically it's a column in a database that automatically has a value that is one higher than its previous row in the table. So say you had a table called "repair jobs" wich had 16 entries (or "rows" as they're more commonly known) and they are each numbered from 1 to 16. Then if you made a new row in the database that did [b]not[/b] specify the repair number, the auto increment feature would kick in and automatically assign repair number 17 to the new row.

I would very strongly suggest you stop and take a little whilse to learn the very basics of database design. Your previous posts about having problems with appostrophes and not having much time to learn any of this stuff worries me that you may be about to put into production something that could go seriously wrong. Like most things you could sell, if someone buys your services to build a site and it goes well... there's a small schance they might recommend you to some other potential clients. If they hire you to make something and it goes horribly wrong, you can guarantee they'll be telling everyone about your failure any time they hear the words "web developer", whether they were being asked to recommend someone or not.

You can improve your knowledge later on, but you can't improve a client's opinion of you without them hiring you again. If you're really squeezed for time, then just try learning the basics of database table design and try to keep your tables and queries on them as simple as you can. That way yo're unlikely to introduce inefficiencies that will negatively impact the database (and therefore the website that's built on it). Aso try to learn the basics of preventing "SQL injection" attacks. The sooner you can find the time to learn about these, the better.
Copy linkTweet thisAlerts:
@GreenAce92authorDec 14.2014 — I have used auto increment before, I think I didn't need to increment... the thing that threw me off was that I didn't start from 0, I should have figured that it would have kept incrementing from the current value.

I appreciate your concern on my behalf, truth to be told this is not my primary interest, more like a means to make money to reach my other goal / passion.

It's not get rich quick as I'm finding out but the advertising business seems like a gold mine. I mean you get a site like this, pre-built, you just hope you get some users and then there you go, money while you sleep.

I don't know I would love to just hire people that have the passion for a certain language / web developing but I cannot for I lack the funds...

I like being able to make things, specifically the front end aspect, designing... but yeah there are a lot of details and as I'm finding it isn't easy to just clump things together and get it to work... but I haven't tried my best yet... I'm just I don't know... tired? Floating in limbo... I've been working on writing stuff for weeks... I had many projects and this one came to mind as something that is more tangible eg. I was trained to fix computers / hardware so I could profit from this business provide I can have a "image"...

The website is very basic. I'm more concerned about the actual fixing and generating some income.

I'm done washing plates and I'm not in school / don't want to return.

Entrepreneur / freelance and commence the judgment.
Copy linkTweet thisAlerts:
@GreenAce92authorDec 14.2014 — Also my problem or interest in this particular post isn't incrementing. It's retrieving the last piece of data from a certain column.

I wasn't getting that to work and since I knew what I was starting from and I have used count before... I thought of approaching it by that method.
Copy linkTweet thisAlerts:
@GreenAce92authorDec 14.2014 — Not to place blame but I've used databases from inmotionhosting before and now I'm using database hosting from GoDaddy and I've never had so much trouble with using their database as I've had with inmotion...
Copy linkTweet thisAlerts:
@Stephen_PhilbinDec 15.2014 — Not to place blame but I've used databases from inmotionhosting before and now I'm using database hosting from GoDaddy and I've never had so much trouble with using their database as I've had with inmotion...[/QUOTE]

I can imagine... and sympathise. The only business I've had with GoDaddy is with using them as my domain name resistrar. It seemed like [b]everything[/b] was considered an extra and was deliberately mis-labeled so you had to use support (or "sales dept. 2" as I thought of them) to get anything done. Some some people don't have a problem with them, but I'm not one of them. As for the process of building things, it I don't think there's anyone that doesn't just wish it'd build its self sometimes. Mostly because you have your idea and you know how you want everything to work, but you have to keep thinking "how could this be broken" and spend about 2/3 of the time hardening it against script-kiddies and other nefarious sorts.

Anyway on to your problem. I've just had another look at your code and I reckon I've spotted the problem. You're probably suffering from what I call code-blindness (like snowblind but with ode instead). Usually caused by what you're typing not keeping pace with what you're thinking. You know what you're thinking of [u]should]/u] work, but it doesn't. When you read the code you're really just reading what's in your head, rather than what's on the screen, so usually it takes someone else to have a look at it because they'll read it from the same point of view of the PHP parser, rather than a short-circuited "why isn't it doing what I want?! >_<" point of view. [b]Everyone[/b] suffers from it every once in a while. ?



[code=php]$count = "SQL COUNT(*) FROM computers";// The count variable is a qery string.
$result = $conn->query($count);// The result of the query is stored in $result.
$base = 123097;
$number = $count + $base;// But here you're using the query string as if it is the result
$sql = $number;
echo (int) $number; [/code]


So what you're really telling PHP to do there is [code=php]$number = "SQL COUNT(*) FROM computers" + 123097[/code]

What you actually need is to use the $result and fetch the row from result and add that to $base. Remember that[code=php]$number = $result + $base;[/code] would be equally useless because $result is a database query result object so you'd need to do something like [code=php]$AtLastTheNumberIWant = $result->fetch_row()[0]
//And then...
$number = $base + $AtLastTheNumberIWant;[/code]


This still may not [i]quite[/i] work, but it should get you very close. It's possible GoDaddy will have made fetching rows from results an "optional extra", but I can't imagine it'll be far off.
Copy linkTweet thisAlerts:
@GreenAce92authorDec 17.2014 — Yeah it's like they deliberately sabotage things to get people to pay more

Then they have the audacity to say things like "Oh well... for just $80.00 more, we'll fix the problems we've caused."

Anyway I'm going to thoroughly follow through your response now, sorry it's been a few days. 7:09

7:11 "Optional extra" haha

I see now what I missed, thank you for the comments and following through, really much obliged

That fetch row command will be interesting, although what is the 0? I'll probably figure that out before you have a chance to respond but thanks for getting me this far.
Copy linkTweet thisAlerts:
@GreenAce92authorDec 17.2014 — oh my goodness ahhhhhhh

I don't understand how quotes work

If I quote something like "SELECT * FROM computers WHERE something" that becomes a string.

But I can't seem to get it to work without putting it in quotes

Anyway, I don't know I can't think right now I feel awful

I just helped my friend paint a house, he's a contractor, god I hate that kind of work

I wasted my day today doing that and not even getting paid... that's another problem but ahhh

I'm just not in the state of mind, probably ate too much, sleeping too much, not enough sunlight, not exercising, bad food whatever...

Tea and rice seems to be a good combo, eat less is better too

This is what I'm trying to do, I'm trying to take in a repair code ( Rc ) and compare it to the database, then asking the person what his/her name is as an added security feature so they only see their own computer not other people's... then it's a matter of displaying their information

I don't know why this is so hard (because I don't know basic php syntax) anyway this is what I've tried

the {$_POST['repair-code']} works

[code=php]$conn = new mysqli($servername, $username, $password, $dbname);
echo $_POST['repair-code'];
$base = 123098;
$name = SELECT * FROM computers WHERE Rc=={$_POST['repair-code']};
$here = ($_POST['repair-code']-$base);
$d = $name->fetch_row(Name)[$here];
echo $d;
//echo $name;
//$result = $conn->query($name);
//echo $result;
/* if (($result = null)) {
echo "Account not found";
}
else {
$row = $result;
echo $row;
} */[/code]
Copy linkTweet thisAlerts:
@GreenAce92authorDec 17.2014 — I also don't understand "T_String" errors or "undefined..." etc... ahh so much and it's so simple too I don't know
Copy linkTweet thisAlerts:
@GreenAce92authorDec 17.2014 — For Code sake

Here it is

What is this BS about "Object of mysqli_name could not be converted to string" then you have to loop it.. ?

Anyway this works

Brenda Jones lives

[code=php]$conn = new mysqli($servername, $username, $password, $dbname);
$rc = $_POST['repair-code'];
echo $_POST['repair-code'];
$column = "SELECT Name FROM computers WHERE Rc=$rc";
$name = $conn->query($column);
while ($row = $name->fetch_assoc()) {
echo $row['Name']."<br>";
}[/code]
×

Success!

Help @GreenAce92 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...