mysql_query("SELECT * FROM recaps WHERE CompanyCode = $CC)", $Connect);
//$query = "SELECT * FROM recaps WHERE CompanyCode = $CC"
//$result = mysql_query($query, $connect)
// or die("query was not successful);
while($row = mysql_fetch_array{
Didn't notice the second page and said that. Just felt in some ways it was slightly clearer so didn't remove my post. No offense intended and I didn't say that there was anything wrong with your code did I? The only thing I would say is that there should be an or die statement after the mysql_query() since it would make it easier to debug if something goes wrong with the query.
EDIT-
Oh and I thought that someone might get confused by kaizix's post as he had mysql_fetch_array with no ($result) which would have caused an error.
EDIT AGAIN -
Keep thinking of things - you should put SQL statements into double quotes so that you can use single quotes within them and keep the database happier.
$query = "SELECT CompanyName, PR_Contact FROM recaps WHERE CompanyCode = '$CC'";
$result = @mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
$Company = $rowї'CompanyName'];
$Payroll_Contact = $rowї'PR_Contact'];
echo 'Company Code '.$CC.' belongs to the Company '.$company.' run by '.$Payroll_Contact."<br>\n";
}
twigletmac wrote:
Keep thinking of things - you should put SQL statements into double quotes so that you can use single quotes within them and keep the database happier.
I think its better to get the variables outside the quotes even if they are double.
in such a query I would better use $_POST['CC'] or $HTTP_POST_VARS['CC'].
So since I will get the $_POST outside the quotes in the two cases, so using single quotes will allow me to use double quotes inside or using double to have single quotes inside are the same, but single is better.
$query = "SELECT CompanyName, PR_Contact FROM recaps WHERE CompanyCode = '".$_POSTї'CC']."'";
In this case using single or double quotes in your PHP code will make no difference whatsoever. Ok so it's personal preference, I think that SQL statements look much nicer enclosed in double quotes and since some databases choke on double quotes as delimeters I prefer to use single quotes.
Basically there's not a lot of difference between the your way and my way except some databases don't like double quotes as delimeters. (Oh and I like one and you like the other )
Oh.. I did not know that some databases choke on double quotes as delimeters, I will start using single quotes from now. I only started learning PHP and mySQL from few weeks.
my mistake on my last post....i saw the missing ) and that's all i saw so i didn't even think about the result pointer. perhaps i tried to reply too wuickly and i'll work on that.