Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variables & recordsets

Status
Not open for further replies.

h1cksuk

Programmer
Feb 22, 2005
2
GB
I'm pretty new to php but have used ASP for quite a while. I'm trying to do the following:

$strSQL="SELECT * FROM table";

$RS = mysql_query($strSQL);

while ($value = mysql_fetch_array($RS))

$intId = $value[id];
$strName = $value["name"];

I am trying to populate the variables $intId, $strName etc so I can use these further down the page but the values are not populated into the variables.. can you do this with php?

thanks
 
You look pretty close to the example code on the PHP online manual page for mysql_fetch_array().

If your script does:

print_r ($value);
die();

right at the beginning of the while loop, what is output?

I know $intID will likely not have a value, as it should get its value from $value[[red]'[/red]id[red]'[/red]], not $value[id]. But you could also be having problems with case-specificity in the array element names.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
nearly there. you need curly braces within the while clause:
Code:
while ($value = mysql_fetch_array($RS))
{  // curly brace
   $intId = $value["id"]; //quotes around the array element
   $strName = $value["name"];
} //close curly brace
 
thanks a lot for the quick response, the brackets were causing the problem although the code doesn't seem too bothered about the quotes "

thanks again...
 
It may or may not effect your script, depending on your php.ini settings. However, it's a good idea to always use the quotes, as you may one day program on a server that is configured to expect the quotes.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top