It seems that you're using an outdated browser. Some things may not work as they should (or don't work at all).
We suggest you upgrade newer and better browser like: Chrome, Firefox, Internet Explorer or Opera

×
avatar
carlosjuero: Double quotes and single quotes are both acceptable, they main thing they affect is the type of data you can pass through to the function. PHP will attempt to parse variables passed in double quoted text [eg: printf("Hi my name is $name, how are you?");] where as a single quote will be parsed as literal text [eg the output of above would be "Hi my name is $name, how are you?"]. There are quite a few rules/exceptions to the whole thing of course - what would a programming language be without overly complex functionality ;)
avatar
Stuff: Good information, thanks. I need to dabble in PHP . . . =)

When building a SQL string, I have to do something like this -

"Hi my name is " & "'" & [name] & "'" & " , how are you?" or "[name] = 'John Doe'"
Some dabbling would help ;)

Your line could be simplified to:
"Hi My name is \"" . [name] . "\", How are you?"

With single quotes you can even leave out the escape character
'Hi my name is"' . [name] . '", how are you?'

the . is the "standard" for combining string objects in PHP OOP - though the & character does come in handy when adding numeric values to the display.

The \ is an escape character telling PHP to literally parse the next character in line [allowing you to shorten lines of code that print out specialty characters - to do an escape character print out you escape it [eg \\].

So an example normal MySQL PHP query string would be something like:

$connect = mysql_connect($host, $username, $password);
mysql_select_db($dbname);

$query = 'SELECT * FROM Names'; // Obviously you would want to make it more specific to what name to retrieve

$result = mysql_query($connect, $query);

$row = mysql_fetch_array($result);
// add your loop structures here for more complex result parsing
$name = $row['name];
mysql_close();
echo 'Hello my name is "' . $name . '", how are you?';


I tend to work with custom functions and classes in my PHP scripts - that makes my work more modular and much easier to modify if an error should pop up.

[For example my db connection on the "display" page would look like $conn = $db->connect();]
avatar
carlosjuero: Double quotes and single quotes are both acceptable, they main thing they affect is the type of data you can pass through to the function. PHP will attempt to parse variables passed in double quoted text [eg: printf("Hi my name is $name, how are you?");] where as a single quote will be parsed as literal text [eg the output of above would be "Hi my name is $name, how are you?"]. There are quite a few rules/exceptions to the whole thing of course - what would a programming language be without overly complex functionality ;)
And as such, using single quotes when you don't want anything parsed saves a couple processor cycles, though I don't actually know what's faster comparing the two following statements:

$var = "My name is \"$name\", what's yours?";
$var = 'My name is "'.$name.'", what\'s yours?';

I, by virtue of habit, always use the latter, except for very short strings where I want something parsed (say "<br/>\n").
avatar
carlosjuero: Some dabbling would help ;)
hehe, dabble was probably not the right word. "Learn" some PHP would be more appropriate. Thanks for an awesome explanation . . . I would pay for this kind of info . . . =D
avatar
Stuff: Not my code but . . .
Well I see no difference between your code and several of the dozens of variants I tried yesterday except that yours works so I'm going to declare victory, magic and your post as the solution, thank you!

Now all I have to do is figure out how my table that apparently has 59 rows of headings has somehow got 60 columns of data... Okay I just manually counted, there's definitely 59 headings and yet I get 60 columns of data. Double yew tee eff??
Post edited October 03, 2011 by Aliasalpha
avatar
Aliasalpha: ...
lol, glad it worked. If nothing else, over the years I have gotten really good at searching for code examples . . . =)

carlosjuero and Miaghstir are, by far, more knowledgeable about PHP than I am so I will +1 for them. I will hazard a guess on the record count as being the way the query was opened . . . as in read only or edit . . . which may return a new record. Maybe carlosjuero can enlighten us both?? . . . =)

Edit: First record starts at 0 thru 59 ?? Wish I knew the PHP environment better . . . =(
Post edited October 03, 2011 by Stuff
Well I've done a table describe and copied the entire thing into excel and there's 59 columns (the names in the describe output match exactly to what I wrote out on paper when starting the DB so I've not missed one) but the query returns 60 columns of data. My first thought was the guid/primary key was being skipped since a its not the kind of data you often query for (at least the user doesn't) but that was the first row I ordered the script to display and it seems to be correct.

The weirdest thing is that the data seems to be correct up until about the 23rd or 24th column and then its all out by one BUT there's no missing heading that could account for it and there has to be 60 columns in the table or mysql would have spat the dummy when I was inserting 60 columns worth of data in the first place.
avatar
Aliasalpha: ...
avatar
Stuff: lol, glad it worked. If nothing else, over the years I have gotten really good at searching for code examples . . . =)

carlosjuero and Miaghstir are, by far, more knowledgeable about PHP than I am so I will +1 for them. I will hazard a guess on the record count as being the way the query was opened . . . as in read only or edit . . . which may return a new record. Maybe carlosjuero can enlighten us both?? . . . =)

Edit: First record starts at 0 thru 59 ?? Wish I knew the PHP environment better . . . =(
for 59 columns the numbering would be 0 thru 58 [0 is always the initial array number unless instantiated as 1 manually].

@Aliasalpha - Are you seeing 60 returned data results or just the array incrementing to 59? Sometimes if you are not explicit enough in your array reading/declarations PHP/MySQL will return an empty [but not NULL] result throwing off your array calculation.

Could you post a debug print of what is returned? or maybe a mysql dump? [if the data is in any nature confidential then forget about the data dump ;)]

do a debug with

echo 'MySQL query row return count: " . mysql_num_rows();


and see what it says. Insert that text before your array parsing code. If the return is the expected amount of data [eg: 59] then the error is in your code parsing the results.

For a full look at what is going on do a full array print out - either by cycling through the results and printing out the data, or by just throwing the entire array onto the screen [the first is easier to read, the second provides the exact array structure].

For the first you have to do a for/next loop parsing the $return variable:


$row_count = mysql_num_rows($result);
for ($x = 0; $x < $row_count; $x++)
{
$row = mysql_fetch_array($result);
echo "GUID: " . $row['GUID'] . "<p>";
echo "Data: " . $row['data'] . "<p>";
}


To just dump the array you would use:

print_r($result);

Ok, you seem to have figured it out - odd that it is hiccuping at that point though.
Post edited October 03, 2011 by carlosjuero
avatar
carlosjuero: Could you post a debug print of what is returned? or maybe a mysql dump? [if the data is in any nature confidential then forget about the data dump ;)]

do a debug with

echo 'MySQL query row return count: " . mysql_num_rows();


and see what it says. Insert that text before your array parsing code. If the return is the expected amount of data [eg: 59] then the error is in your code parsing the results.
Damn I knew I forgot to look at a thread somewhere on the internet...

The problem I'm having isn't rows, everything's shiny there, its the number of columns. I did a count on the number of fields in the table and it says 59 like it should be there's still 60 cells of data per row
DRINK! FECK! ARSE! It was a fucking PEBKAC error, I was repeating a line in my output code...

Anyone good with windows phone 7 or xna programming?
avatar
Stuff: Not my code but . . .
avatar
Aliasalpha: Well I see no difference between your code and several of the dozens of variants I tried yesterday except that yours works so I'm going to declare victory, magic and your post as the solution, thank you!

Now all I have to do is figure out how my table that apparently has 59 rows of headings has somehow got 60 columns of data... Okay I just manually counted, there's definitely 59 headings and yet I get 60 columns of data. Double yew tee eff??
This is called Voodoo Chicken Coding
avatar
Aliasalpha: DRINK! FECK! ARSE! It was a fucking PEBKAC error, I was repeating a line in my output code...

Anyone good with windows phone 7 or xna programming?
No, but I need to figure out a cheap way to snag a phone so I can try it out.
Post edited October 06, 2011 by orcishgamer
avatar
orcishgamer: This is called Voodoo Chicken Coding
Hehe thats one I'd not heard before, most of the time I've heard it described as a reason to chuck the code & start again. Thankfully it was a moronic typo that I continually missed so I don't have to go looking for a chicken, the closest I have is a rosella and he'd be a bit annoyed and probably bite me if I tried swinging him around my head

avatar
orcishgamer: I need to figure out a cheap way to snag a phone so I can try it out.
I believe the traditional method involves seeing someone who owns one, kicking them in the bollocks and running away with their phone. Someone other than me that is. There might be a bargain to be had on ebay if a bunch of people want to swap to the new 3% shinier iphone though