Excizted 67 Posting Whiz

You are not even mentioning what database type you would like to access.

If you just need any, then have a look at LiteSQL - easy to use and first few results already talks about C++. However this one is typically locally stored.

Maybe you want a more typical network-accessed database like MSSQL or MySQL?

If you specify this in your own Google searches, I think you will have much more success in finding a good library for implementation. But if you are a beginner to C++, you will learn MySQL implementation can be a little challenging.

Good luck.

Excizted 67 Posting Whiz

Hi there,

When you are updating the text hint with Ajax, your Javascript code looks for the first element with ID="txtHint".

But you are creating multiple elements with ID="txtHint" and so your hint will always be shown in the first row.

To resolve this you need to correlate the Ajax call to a given row and make sure your ID's are unique.

For example when creating a new row (line 98 in your snippet) do something like

var numRows = 1; // keep track of how many rows you have
$('#addmore').on('click', function(){
numRows++; // when adding a row, increment the count
...
data += '<input type="text" name="conn_type[]" id="conn_type" onChange="showptype(this.value, \'txtHint' + numRows + '\');">...<div id="txtHint' + numRows + '"></div>...';
// use the number in the ID of your element ^ and when calling Ajax
...
}

Now you just need to use the second argument of showptype to find the right txtHint.

function showptype(str1, txtHintID) // second parameter added
{
if (str1=="")
  {
  // we use the variable txtHintID which should contain fx "txtHint2" or "txtHint7" depending on the row called from
  document.getElementById(txtHintID).innerHTML=""; 

  ... // and so on, update your other txtHint-references too

This should be more than enough to get you finished.

Remember - always keep unique IDs or things will break ;-)

Excizted 67 Posting Whiz

Hi there.

I assume you are using PHP as your programming language. You must use PHP to develop the logic of finding out whether or not something has been clicked on the HTML end.

When your PHP program knows this, fx by the POST-variable you mentioned

if(isset($_POST['like']))
{ // So the LIKE-button was pressed

}

You would add any logic to prevent liking multiple times in there too.

Then you can increment the database value independent of PHP-variables, with the query below. But first, you are saying your table columns "likes" and "dislikes" are varchar-type. Varchar is for characters, and I think you want "likes" and "dislikes" to be a count (number, integer). So please change their type to something like int(11), unsigned optionally.

Then you can do

UPDATE clicks SET likes = likes+1 WHERE user_associated = {$_SESSION['user_id']}

Where $_SESSION['user_id'] being an integer user id, you can change that to whatever variable you use.

I hope this helps.

Excizted 67 Posting Whiz

This is the most correct way to do it.
Alternate methods are C ways, and is shouldn't be used in C++ :)

Excizted 67 Posting Whiz

I have done as instructed, and the person is able to enter a value, but then it says that Fahrenheit is uninitialized, I don't know how to take the value that a person entered and put it in the cout as well. Take a look.

#include <iostream>
#include <iomanip>
#include <fstream>


using namespace std;
float FahrenheitToCelsius(float);
int main()
{
	float fahrenheit;
	char input[10];
	float celsius;
	int choice;
	do{

	cout << "This program converts fahrenheit to celsius" << endl << endl ;
	cout << "Please Enter Fahrenheit Degrees: ";
	cin >> input;
	for(unsigned int i = 0; i<10; i++){
		if (input[i] == '\0')
			break;
		if(!isdigit(input[i])){
			cout <<"Please Enter Digits ";
		}

	}
	cout << "Your Conversion Is: "<< fahrenheit << " Degree Fahrenheit to:" << endl;
	cout << FahrenheitToCelsius (fahrenheit) << fixed <<setprecision(2) <<" Degrees Celsius.";
	cout << "Want To Play Again?";
	cout << "1 == Yes";
	cout << "2 == No " << endl;
	cin >> choice;

	} while (choice == 1);

	cin.get();
	return 0;
}

float FahrenheitToCelsius(float fahrenheit)
{

	return fahrenheit = (5.0/9.0) * (fahrenheit - 32);
}

Sorry my bad.
This means that float fahrenheit has not been assigned a value.
You will have to convert the input string to a floating numeric value, after validating it.

You will have to #include <stringstream> also.
After line 26, you would have to do the conversion like this:

stringstream convert;
convert << input;
convert >> fahrenheit;
Excizted 67 Posting Whiz

isdigit checks a character if it is a digit character.
The user entered string is parsed into a float (float fahrenheit; on line 10) and is automatically (if possible) converted to a digit.

This means you will not be able to check if the entered string was letters or numbers.

You would have to read the cin to a character array instead, and then check each character for validity.

You could do something like this:

char input[10]; // max length is 9 (tenth place is needed for terminating null)
cin >> input;
for(unsigned int i = 0; i < 10; i++) // 10 again, as we wrote it in input size
{
    if(input[i] == '\0') // we have reached the end of the input
        break; 
    if(!isdigit(input[i]))
    {
        cout << input << " contains invalid characters." << endl;
        return -1; // exit program
    }
}
Excizted 67 Posting Whiz

Well you have some serious issues there.
On line 20 you try to cout a function. Uh-oh, that does not work at all.
You would write

cout << FahrenheitToCelsius(fahrenheit) << " Degrees Celsius";

Also, on line 32 your function definition mismatches the declaration up on line 6.

Make sure both lines read

float FahrenheitToCelcius(float fahrenheit)

Also, delete line 13.


I am surprised you say it crashes. I wouldn't think this would even compile.
Please make the corrections I suggested and post back with your results :)

Ps. You might want to call it function not subprogram, although it is probably not wrong ;-)

Excizted 67 Posting Whiz

Initially store the descr of the selected one (get it from mysql).
Then in your while loop, you check if $r == $your_new_variable;

If it is, then you echo "selected" in your <option> tag.

pietpiraat commented: thanks for helping +1
Excizted 67 Posting Whiz

Omg use google, this is a broadly discussed topic.

if (mysql_query("SOURCE file.sql"))
{
  echo "success";
}
Excizted 67 Posting Whiz

Requires you to sign up with a phone service provider.
There are some easy ones where you pay just a few bucks and get code for integration.

Can't remember names.

Excizted 67 Posting Whiz

Super:)

Excizted 67 Posting Whiz

Guns are banned in Danmark.
We still hear, almost regularily I would say, about gunshooting in the news.

I don't really have an opinion on whether it is a good thing or not. I have neither been threatened by a gun or felt I would like to have a gun.

Excizted 67 Posting Whiz

I don't know the solutions to this.
(this is a friendly and discrete bump because I think it is an interesting issue)

Excizted 67 Posting Whiz

One thing is the choice, and I think you should only choose 64-bit if you need it for extra RAM, but that's my opinion - anyway, it does not really seem like he's choosing, he's more like switching FROM 64-bit, which I think is ridiculous :)

Excizted 67 Posting Whiz

You do not check for mysql errors, so that could be a reason you don't get errors :)

Get used to, after all mysql_query(), add as shown here:

mysql_query(...) or die(mysql_error());

If mysql_query returns false, which it will if something goes wrong, it will stop execution, clear page and print mysql_error() which contains information about the latest error.

I hope this helps you!

Excizted 67 Posting Whiz

Please specify your issue.
You mention a warning.. what warning!?

Please indent your code, it is unreadable in it's current state.

Excizted 67 Posting Whiz

I agree, that there should be no need to switch to 32 bits.

If you wanted to so anyway, you will have to obtain a 32 bits version of Windows and install it instead of your current installation.

I've seen it is possible to convert a 32 bit license to 64 bit, but I don't think it goes the other way around.

Beyond that you cannot change 64 to 32 as the motherboard is built with '64' wires around it instead of 32. (oversimplified version of the truth!)

You lost me here.
Any 64 bit computer I've come accross (including three of my own) are all fully capable of running both 32- and 64bit OS'es.

Furthermore I have never seen a motherboard specific for either x86 or x64.
It is the CPU that is either 32 bits or 64 bits, and a 64 bits OS won't install on a 32 bits CPU but the other way around shouldn't be an issue.

Excizted 67 Posting Whiz

Are you sure the server (apache) starts up, or fail in the progress?

Applications like Skype and Teamviewer like to use the same port as Apache.

Note: This would more fit in Hardware & Software category imo.

Excizted 67 Posting Whiz

I really can't figure out these coordinates or whatever.
You need to find out how to separate each row into columns.

First, by reading in 3 and 3, you would know to create an array with this size.

size1 = 3;
size2 = 3;
std::string str[size1][size2];

Then just fill them in`?

Excizted 67 Posting Whiz

Hi and welcome to Daniweb.

I get lost from your first line of data file.
You say it should contain the size of the array?
But there is two numbers? Is it a two-dimensional array?

And I'm a bit confused - you need to put data into structs, but also put them into arrays?

I don't see how your values would fit into a two-dimensional array, though.

If you clarify what you need better, I sure can and will help you :)

Excizted 67 Posting Whiz

Yes, it is common to have that kind of files looking like this

Peter;26;This guy is awesome!

or

Peter,26,This guy is awesome!

or you could specify multilined sections like this, but your need doesn't seem like this is any better unless you of course like the syntax.

{
Peter
26
This guy is awesome!
}
Excizted 67 Posting Whiz

Use code tags!!!!!!
And btw, what are you trying to achieve?

Excizted 67 Posting Whiz

Hi,

I find CodeBlocks a bit too unstable and generally lacking a lot.

Have you tried NetBeans? It is an IDE that supports several programming languages - All I do is basically programming, and I've tried many IDE's - I really like NetBeans as the best IDE. It both available for Windows and my Linux<3. I use it for Java, C++, C, Ruby (on Rails), PHP, HTML, CSS and more.

I'd say give it a try, you might just be wasting time in CodeBlocks :)

And hey people, no flame war here, I'm not ragging down on CodeBlocks, just suggestion him to try NetBeans as it is in my opinion and personal preference better.

Excizted 67 Posting Whiz

What that dude said!

Excizted 67 Posting Whiz

Oh well sorry then but I have no clue how to create that slide-down thingy.
It's probably not a good place to look for that in the PHP forums, maybe try some HTML/CSS forums?

Excizted 67 Posting Whiz

You want to print some text, without that having to be to an <input> box? Well make a <div> object with an id and set its innerHTML, look:

<script type="text/javascript">
function postResult(myResult)
{
    document.getElementById('output').innerHTML = myResult;
}
</script>
<div id="output">Please search</div>

innerHTML is at the start "Please search" but then with the sample function "Please search" will be replaced with the content of 'myResult'.

Excizted 67 Posting Whiz

I wanted to wrap your code in code tags so it's many times easier for me to read and understand.

Excizted 67 Posting Whiz

Wanted to help you there, but your code is not very nice to read. Edit your post and put the code in code tags, you have to remember that! :)

Excizted 67 Posting Whiz

Hello and welcome to Daniweb.
Usually all the friendly people here would give a prompte response.
You haven't had any yet. I'm not gonna go into your code right now, but instead take a look at your posting problem.

First of all, you want to get rid of your last error. What is the error? What part is working and which doesn't?

Secondly, where's your code tags? Wrap your code in [code] tags, to make it easily readable and to give some syntax highlighting.

Lastly, your copying of the code seemed to miss out your code formatting. Or maybe you haven't even done your formatting at all? This is important, otherwise your code is junk to read and hard to manage and maintain.

Fix those problems by editing your original post, and I'm sure you'll get your help! :)
Good luck!

Excizted 67 Posting Whiz

Something like this?

int** mainArray = new int*[5]; // example number
for(int i = 0; i < 5; i++)
     mainArray[i] = new int[3]; // two numbers and a sum

void sumThem(int** mArray, int which)
{
     mArray[which][0] = mArray[which][1]+mArray[which][2];
}